Created
July 4, 2025 22:59
-
-
Save demesne/0bcccb6cdb0799b0f4d00dcd17147597 to your computer and use it in GitHub Desktop.
gist for mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if #available(iOS 15.0, *) { | |
| // --- Platform Authenticator (e.g., Face ID, Touch ID) --- | |
| if registrationOptions.authenticatorAttachment == .platform || registrationOptions.authenticatorAttachment == nil { | |
| let provider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: registrationOptions.rpId) | |
| let request = provider.createCredentialRegistrationRequest(challenge: registrationOptions.challenge, name: registrationOptions.name, userID: registrationOptions.userID) | |
| if !registrationOptions.excludeCredentials.isEmpty { | |
| request.excludedCredentials = registrationOptions.excludeCredentials.map { ASAuthorizationPlatformPublicKeyCredentialDescriptor(credentialID: $0) } | |
| } | |
| request.userVerificationPreference = registrationOptions.userVerificationPreference | |
| requests.append(request) | |
| print("[PasskeyDialogView][iOS] Created ASAuthorizationPlatformPublicKeyCredentialRegistrationRequest.") | |
| } | |
| // --- Security Key Authenticator (e.g., YubiKey) --- | |
| if registrationOptions.authenticatorAttachment == .crossPlatform || registrationOptions.authenticatorAttachment == nil { | |
| let provider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: registrationOptions.rpId) | |
| let request = provider.createCredentialRegistrationRequest(challenge: registrationOptions.challenge, displayName: registrationOptions.name, name: registrationOptions.name, userID: registrationOptions.userID) | |
| // Ensure publicKeyCredentialParameters are set for Security Key requests | |
| if !registrationOptions.publicKeyCredentialParameters.isEmpty { | |
| request.credentialParameters = registrationOptions.publicKeyCredentialParameters | |
| } else { | |
| print("[PasskeyDialogView][iOS][Warning] No publicKeyCredentialParameters provided for Security Key. Using default ES256 (-7).") | |
| request.credentialParameters = [ASAuthorizationPublicKeyCredentialParameters(algorithm: ASCOSEAlgorithmIdentifier(rawValue: -7))] | |
| } | |
| if !registrationOptions.excludeCredentials.isEmpty { | |
| request.excludedCredentials = registrationOptions.excludeCredentials.map { ASAuthorizationSecurityKeyPublicKeyCredentialDescriptor(credentialID: $0, transports: []) } | |
| } | |
| request.userVerificationPreference = registrationOptions.userVerificationPreference | |
| requests.append(request) | |
| print("[PasskeyDialogView][iOS] Created ASAuthorizationSecurityKeyPublicKeyCredentialRegistrationRequest.") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment