Closed MasterKale closed 2 years ago
@MasterKale How is this supposed to work?
Right now, fetch('/generate-authentication-options')
requires the user to be signed in, so that their registered authenticators can be fetched and filled into allowCredentials
.
@P4sca1 good question, let's take this into a Discussion: https://github.com/MasterKale/SimpleWebAuthn/discussions/225
This PR adds support for upcoming browsers' conditional UI capability to @simplewebauthn/browser's
startAuthentication()
.To use it, pass in
true
for the new seconduseBrowserAutofill
positional argument tostartAuthentication()
, then specify Promise resolution (or rejection) logic to handle the user possibly, eventually choosing a WebAuthn credential via the browser's autofill mechanism:Guidance from platform vendors indicates that it is important to initialize WebAuthn's Conditional UI experience as soon as possible. Placing this logic in
<head>
should give browsers enough time to query authenticators for any discoverable credentials to display to the user. It may also work to delay painting UI For N milliseconds to achieve the same thing in something like a single-page app that would trigger this experience some time after page load. It's still early days for this capability so ymmv.A new asynchronous
browserSupportsWebAuthnAutofill()
helper is also being added in this PR. This method can be used independently of the call that's made instartAuthentication()
when initializing browser autofill support.Existing authentication UI and logic should not need to be refactored. This new "pending" WebAuthn request will be automatically cancelled on a subsequent execution of
startAuthentication()
in, say, an existing click handler that triggers the browser's typical "modal" WebAuthn experience.Conditional UI is still a nascent capability, but this method should be pretty reliable since the API is largely settled. This new logic has been successfully tested in both Chrome Canary[1][2] and Safari in the macOS Ventura beta.
Screenshots
Chrome Canary:
Safari in the macOS Ventura beta:
Addresses #209.
[1] The following flag must be specified when launching Chrome Canary to enable Conditional UI:
[2] I've been informed there's a race condition deep within Chrome Canary that sometimes prevents the autofill from populating with WebAuthn credentials. If they aren't showing up just keep refreshing and eventually they'll appear. This is a temporary issue and will definitely be resolved before Chrome's Conditional UI support lands in Chrome Stable.