Skip to content

Instantly share code, notes, and snippets.

@Kaival-Patel
Created January 20, 2023 09:47
Show Gist options
  • Select an option

  • Save Kaival-Patel/1c4a4514fd0524461f72d07a894a9fb8 to your computer and use it in GitHub Desktop.

Select an option

Save Kaival-Patel/1c4a4514fd0524461f72d07a894a9fb8 to your computer and use it in GitHub Desktop.
Registration Implementation for Passkeys
func signUpWith(userName: String, anchor: ASPresentationAnchor) {
self.authenticationAnchor = anchor
let publicKeyCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
// Fetch the challenge from the server. The challenge needs to be unique for each request.
// The userID is the identifier for the user's account.
let challenge = Data()
let userID = Data(UUID().uuidString.utf8)
let registrationRequest = publicKeyCredentialProvider.createCredentialRegistrationRequest(challenge: challenge,
name: userName, userID: userID)
// Use only ASAuthorizationPlatformPublicKeyCredentialRegistrationRequests or
// ASAuthorizationSecurityKeyPublicKeyCredentialRegistrationRequests here.
let authController = ASAuthorizationController(authorizationRequests: [ registrationRequest ] )
authController.delegate = self
authController.presentationContextProvider = self
authController.performRequests()
isPerformingModalReqest = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment