Repository navigation
feat(expo-passkeys): support preferImmediatelyAvailableCredentials for passkey sign-in #10755
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@clerk/expo-passkeys': minor | ||
| '@clerk/expo': minor | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/shared': minor | ||
| --- | ||
|
|
||
| Add a `preferImmediatelyAvailableCredentials` option to `signIn.authenticateWithPasskey()` and `signIn.passkey()`. In Expo apps on iOS and Android, it limits passkey sign-in to passkeys already on the device. When there are none, the request fails with `passkey_registration_cancelled` and the system's "use a passkey from another device" sheet doesn't appear, so an app can prompt for a passkey automatically on sign-in. Browsers ignore it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,7 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv | |
| } | ||
|
|
||
|
|
||
| func getPasskey(challengeBase64URL: String, rpId: String, promise: Promise) { | ||
| func getPasskey(challengeBase64URL: String, rpId: String, preferImmediatelyAvailableCredentials: Bool, promise: Promise) { | ||
| let publicKeyCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: rpId) | ||
|
|
||
| let challenge = dataFromBase64URL(base64urlString: challengeBase64URL)! | ||
|
|
@@ -68,7 +68,11 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv | |
| let authController = ASAuthorizationController(authorizationRequests: [ assertionRequest ] ) | ||
| authController.delegate = self | ||
| authController.presentationContextProvider = self | ||
| authController.performRequests() | ||
| if preferImmediatelyAvailableCredentials { | ||
| authController.performRequests(options: .preferImmediatelyAvailableCredentials) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard the iOS 16 authorization option.
Proposed availability guard
|
||
| } else { | ||
| authController.performRequests() | ||
| } | ||
|
|
||
| self.authCallback = { result,error in | ||
| if (error != nil) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,8 +115,10 @@ const makeSerializedGetResponse = ( | |
|
|
||
| export async function get({ | ||
| publicKeyOptions, | ||
| preferImmediatelyAvailableCredentials = false, | ||
| }: { | ||
| publicKeyOptions: PublicKeyCredentialRequestOptionsWithoutExtensions; | ||
| preferImmediatelyAvailableCredentials?: boolean; | ||
| }): Promise<CredentialReturn<PublicKeyCredentialWithAuthenticatorAssertionResponse>> { | ||
| if (!publicKeyOptions) { | ||
| throw new Error('publicKeyCredential has not been provided'); | ||
|
|
@@ -129,8 +131,14 @@ export async function get({ | |
| }; | ||
|
|
||
| const getPasskeyModule = Platform.select({ | ||
| android: async () => ClerkExpoPasskeys.get(JSON.stringify(serializedPublicCredential)), | ||
| ios: async () => ClerkExpoPasskeys.get(serializedPublicCredential.challenge, serializedPublicCredential.rpId), | ||
| android: async () => | ||
| ClerkExpoPasskeys.get(JSON.stringify(serializedPublicCredential), preferImmediatelyAvailableCredentials), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ios: async () => | ||
| ClerkExpoPasskeys.get( | ||
| serializedPublicCredential.challenge, | ||
| serializedPublicCredential.rpId, | ||
| preferImmediatelyAvailableCredentials, | ||
| ), | ||
| default: null, | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: clerk/javascript
Length of output: 8953
Script executed:
Repository: clerk/javascript
Length of output: 16883
Web query:
AndroidX credentials NoCredentialException preferImmediatelyAvailableCredentials no credentials immediately available GetCredentialRequest documentationResult:
Script executed:
Repository: clerk/javascript
Length of output: 19082
Script executed:
Repository: clerk/javascript
Length of output: 13884
Map the Android no-credential result to the documented error.
When the preference is enabled and Android returns
NoCredentialException,authenticateWithPasskeythrowspasskey_retrieval_failedinstead ofpasskey_registration_cancelled. Callers that handle the documented code can miss the fallback.Suggested fix