Add WebAuthn sign in and sign up flows #881
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a few parts here due to how WebAuthn works:
WebAuthn requires scripts that run on both the relying party server and client and that communicate back and forth with each other. The RP client gets an email to identify the user, and then sends that to the RP server, which responds with an "options" object. The RP client then triggers the authenticator "ceremony" (registration or authentication) it's trying to do, and sends that back to the RP server.
The RP server functionality is broken up into four methods on the
Auth
class:getWebAuthnSignupOptionsUrl(email: string): string
: returns the URL to the EdgeDB server for getting the signup options. Applications use this to redirect the client to the correct URL on the EdgeDB server to get the registration/signup options.async signupWithWebAuthn( email: string, credentials: RegistrationResponseJSON, verifyUrl: string, userHandle: string ): Promise<SignupResponse>
: Sends the credentials that the authenticator generated to the EdgeDB server to create the appropriateLocalIdentity
andWebAuthnFactor
.getWebAuthnSigninOptionsUrl(email: string)
: returns the URL to the EdgeDB server gor getting the signin options. Applications use this to redirect the client to the correct URL on the EdgeDB server to get the authentication/signin options.async signinWithWebAuthn( email: string, assertion: AuthenticationResponseJSON ): Promise<TokenData>
: Sends the assertion that the authenticator generated to the EdgeDB server for validation. When successful, returns theTokenData
On the RP client, we have the
@edgedb/auth-core/webauthn
script which is used to fetch the options and trigger the signin or signup ceremonies. These functions would be used in client code to be triggered by button clicks or form submission. You'd call these functions with theemail
from a form, and then if successful redirect the user to the appropriate place or show an error.