webauthn-swift icon indicating copy to clipboard operation
webauthn-swift copied to clipboard

How to finish registration

Open jaydipdeveloper opened this issue 9 months ago • 6 comments

let webAuthnManager = WebAuthnManager( configuration: WebAuthnManager.Configuration( relyingPartyID: "oloid.ai", relyingPartyName: "My Fancy Web App", relyingPartyOrigin: "https://oloid.ai" ) )

    Task {
        let result = webAuthnManager.beginRegistration(user: PublicKeyCredentialUserEntity(id: self.generateRandomBytes(count: 10), name: "Jaydip", displayName: "Jaydip Finava"))
        print(result)
        let id = result.user.id.base64URLEncodedString()
        
        let request = RegistrationCredential

how to create request object of type RegistrationCredential?

        let confirmCredentialIDNotRegisteredYet: (String) async throws -> Bool = { credentialID in
            return true
        }
        do {
            let credential = try await webAuthnManager.finishRegistration(
                challenge: result.challenge,
                credentialCreationData: RegistrationCredential,
                confirmCredentialIDNotRegisteredYet: confirmCredentialIDNotRegisteredYet
            )
            print(credential)
        } catch {
            print(error.localizedDescription)
        }
    }

jaydipdeveloper avatar May 07 '24 07:05 jaydipdeveloper

how to create request object of type RegistrationCredential

You decode this from the web browser or your app — you'll need to pass the result from beginRegistration() to the client, have it sign that via a passkey, and supply it back to the server to be finalized and stored with finishRegistration(). Have you already gone through the documentation here? https://swiftpackageindex.com/swift-server/webauthn-swift/main/documentation/webauthn/example-implementation

dimitribouniol avatar May 07 '24 13:05 dimitribouniol

I'm using on native swift

let webAuthnManager = WebAuthnManager( configuration: WebAuthnManager.Configuration( relyingPartyID: "domain", relyingPartyName: "My Fancy Web App", relyingPartyOrigin: "https://domain.ai" ) )

    Task {
        let result = webAuthnManager.beginRegistration(user: PublicKeyCredentialUserEntity(id: self.generateRandomBytes(count: 10), name: "Jaydip", displayName: "Jaydip Finava"))
        print(result)
        let id = result.user.id.base64URLEncodedString()
        
        let request = RegistrationCredential(id: id, type: .publicKey, rawID: result.challenge, attestationResponse: AuthenticatorAttestationResponse(clientDataJSON: result.challenge, attestationObject: result.challenge))
        
        
        let confirmCredentialIDNotRegisteredYet: (String) async throws -> Bool = { credentialID in
            return true
        }
        do {
            let credential = try await webAuthnManager.finishRegistration(
                challenge: result.challenge,
                credentialCreationData: request,
                confirmCredentialIDNotRegisteredYet: confirmCredentialIDNotRegisteredYet
            )
            print(credential)
        } catch {
            print(error)
        }
    }
    

jaydipdeveloper avatar May 07 '24 13:05 jaydipdeveloper

Can you give me sample code in iOS Swift please?

jaydipdeveloper avatar May 07 '24 13:05 jaydipdeveloper

This library is for a server backend, not an iOS app. Apple has documentation here for the iOS half of the equation, assuming you are interacting with a supported server: https://developer.apple.com/documentation/authenticationservices/connecting_to_a_service_with_passkeys

dimitribouniol avatar May 07 '24 13:05 dimitribouniol

I need to do passkey like Dashlane iOS app

On Tue, 7 May 2024 at 6:36 PM, Dimitri Bouniol @.***> wrote:

This library is for a server backend, not an iOS app. Apple has documentation here for the iOS half of the equation, assuming you are interacting with a supported server: https://developer.apple.com/documentation/authenticationservices/connecting_to_a_service_with_passkeys

— Reply to this email directly, view it on GitHub https://github.com/swift-server/webauthn-swift/issues/66#issuecomment-2098364164, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOLYOFJ2OEB5DZTTITB4KPLZBDGW7AVCNFSM6AAAAABHKL5N3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJYGM3DIMJWGQ . You are receiving this because you authored the thread.Message ID: @.***>

jaydipdeveloper avatar May 07 '24 13:05 jaydipdeveloper

WebAuthnError(reason: PassDemo.WebAuthnError.Reason.invalidAttestationObject)

jaydipdeveloper avatar May 07 '24 15:05 jaydipdeveloper