fix/528-simplify-use-of-credential-id #529
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.
This PR attempts to make @simplewebauthn/server simpler to use by keeping
credentialID
astring
throughout registration and authentication. This PR contains the following breaking changes!Fixes #528.
Registration
excludeCredentials
when callinggenerateRegistrationOptions()
expectsid
to be astring
.type
is no longer necessary here either.registrationInfo.credentialID
returned fromverifyRegistrationResponse()
is now the base64url-encoded credential IDstring
instead of aUint8Array
.Authentication
allowCredentials
when callinggenerateAuthenticationOptions()
expectsid
to be a string.type
is no longer necessary here either.authenticationInfo.credentialID
returned fromverifyAuthenticationResponse()
is now the base64url-encoded credential IDstring
instead of aUint8Array
.AuthenticatorDevice.credentialID
(in @simplewebauthn/types) is now a base64url-encodedstring
instead of aUint8Array
. This will break existing use of theauthenticator
argument inverifyAuthenticationResponse()
.Helpers
isoBase64URL.isBase64url()
is now calledisoBase64URL.isBase64URL()
(note the "URL" in the method name)Rationale
The idea here is that, in practice, it makes a lot of sense for a given credential ID to be persisted as the base64url-encoded string. This makes it easier, for example, to confirm which credentials are making it to the WebAuthn API call, to copy-paste the ID from a WebAuthn response to look up the credential in the RP's database, to share the credential ID with others...in all of these, strings help the developer discern one credential from another.
Thinking about the developer experience, let's start with an RP dev wiring up registration for a user. First they generate WebAuthn registration options:
Then the options make it to WebAuthn via @simplewebauthn/browser, and a response is sent back to be verified:
Later, the user comes back to authenticate with a passkey. The RP dev first generates authentication options, specifying the user's registered credential:
When verifying the authentication response, the credential ID can again be used as-is with no helpers needed:
Thinking about how
credentialID
might get persisted across various SQL and NoSQL solutions, strings are so easy to implement, query, and think about that most users of this library are probably already storingcredentialID
as a string, but needing to maintain code that goes to and from base64url string and bytes. I think in my gut this PR will simplify use of this library even further by removing the need to remember how and when to go between the two formats.Yes, the spec says these values are bytes, but this is a library intended to make it simpler to implement WebAuthn. This PR feels like a great direction to take things in the spirit of that.