Check if there is any stored passkey on iOS

295 views Asked by At

Is it possible to check if device has any passkeys stored or not? Context: I need to sign in with passkeys only if there is saved one. I don't want to show QR code and scan it with other device. My goal is to show passkeys system popup only if there is at least one passkey stored for specific domain.

2

There are 2 answers

0
Michael Braga On

There isn't a direct way to determine if a device has a passkey for the given domain. Currently, the best approach is to utilize conditional UI autofill without implementing some kind of device tracking mechanism on the backend.

0
Amit Nadir On

If you want to avoid the QR option for authenticating from a nearby device, set the ASAuthorizationController with the option preferImmediatelyAvailableCredentials:

// Pass in any mix of supported sign-in request types.   
let authController = ASAuthorizationController(authorizationRequests:[assertionRequest, passwordRequest])

// If credentials are available, presents a modal sign-in sheet.
// If there are no locally saved credentials, no UI appears and
// the system passes ASAuthorizationError.Code.canceled to call
// `AccountManager.authorizationController(controller:didCompleteWithError:)`.
authController.performRequests(options: .preferImmediatelyAvailableCredentials)