Skip to content

Commit 3f0ebd7

Browse files
feat: store id instead of encoded raw_id on external_id column
With webauthn-json the create() method expects createOptions of type JSON. However, for using the browser's native API, the create() call must receive the options in type CredentialCreationOptions. To pass from JSON to CredentialCreationOptions the method parseRequestOptionsFromJSON is used. parseRequestOptionsFromJSON in turn, expects to receive this format: https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialcreationoptionsjson Therefore, the credential ids inside excludeCredentials need to be of type Base64URLString, which is not the case now. As of now, the raw_id is being strict encoded which still doesn't comply with being of type Base64URLString. Instead of strictly encoding the raw_id, the id attribute starts being stored. The id is a base64url encoded version of PublicKeyCredential.rawId.
1 parent ecae6dc commit 3f0ebd7

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

app/controllers/credentials_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def callback
2525
webauthn_credential.verify(session[:current_registration]["challenge"], user_verification: true)
2626

2727
credential = current_user.credentials.find_or_initialize_by(
28-
external_id: Base64.strict_encode64(webauthn_credential.raw_id)
28+
external_id: webauthn_credential.id
2929
)
3030

3131
if credential.update(

app/controllers/registrations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def callback
3737
webauthn_credential.verify(session[:current_registration]["challenge"], user_verification: true)
3838

3939
user.credentials.build(
40-
external_id: Base64.strict_encode64(webauthn_credential.raw_id),
40+
external_id: webauthn_credential.id,
4141
nickname: params[:credential_nickname],
4242
public_key: webauthn_credential.public_key,
4343
sign_count: webauthn_credential.sign_count

app/controllers/sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def callback
3131
user = User.find_by(username: session[:current_authentication]["username"])
3232
raise "user #{session[:current_authentication]["username"]} never initiated sign up" unless user
3333

34-
credential = user.credentials.find_by(external_id: Base64.strict_encode64(webauthn_credential.raw_id))
34+
credential = user.credentials.find_by(external_id: webauthn_credential.id)
3535

3636
begin
3737
webauthn_credential.verify(

test/controllers/registrations_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
4747
username: "bob",
4848
credentials: [
4949
Credential.new(
50-
external_id: Base64.strict_encode64(webauthn_credential.raw_id),
50+
external_id: webauthn_credential.id,
5151
nickname: "Bob's USB Key",
5252
public_key: webauthn_credential.public_key,
5353
sign_count: webauthn_credential.sign_count

0 commit comments

Comments
 (0)