Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to finish registration #66

Open
jaydipdeveloper opened this issue May 7, 2024 · 6 comments
Open

How to finish registration #66

jaydipdeveloper opened this issue May 7, 2024 · 6 comments

Comments

@jaydipdeveloper
Copy link

jaydipdeveloper commented May 7, 2024

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 jaydipdeveloper changed the title The package product 'Crypto' requires minimum platform version 13.0 for the iOS platform, but this target supports 12.0 How to finish registration May 7, 2024
@dimitribouniol
Copy link
Contributor

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

@jaydipdeveloper
Copy link
Author

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
Copy link
Author

Can you give me sample code in iOS Swift please?

@dimitribouniol
Copy link
Contributor

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

@jaydipdeveloper
Copy link
Author

jaydipdeveloper commented May 7, 2024 via email

@jaydipdeveloper
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants