Skip to content

Commit 00d0744

Browse files
Merge pull request #502 from ttanimichi/rename-webauthn-id
Rename `webauthn_id` in README examples to avoid ambiguity
2 parents be094a4 + 3c0b15d commit 00d0744

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ end
169169
#### Initiation phase
170170

171171
```ruby
172-
# Generate and store the WebAuthn User ID the first time the user registers a credential
173-
if !user.webauthn_id
174-
user.update!(webauthn_id: WebAuthn.generate_user_handle)
172+
# Generate and store the WebAuthn User Handle the first time the user registers a credential
173+
if !user.webauthn_user_handle
174+
user.update!(webauthn_user_handle: WebAuthn.generate_user_handle)
175175
end
176176

177177
options = WebAuthn::Credential.options_for_create(
178-
user: { id: user.webauthn_id, name: user.name },
179-
exclude: user.credentials.map { |c| c.webauthn_id },
178+
user: { id: user.webauthn_user_handle, name: user.name },
179+
exclude: user.webauthn_credentials.map { |c| c.webauthn_id },
180180
authenticator_selection: {
181181
resident_key: "discouraged", # For a passwordless login or 2FA. Use "required" for a passkey-based (passwordless and usernameless) login.
182182
user_verification: "required" # For a passwordless or passkey-based (passwordless and usernameless) login. Use "discouraged" for 2FA.
@@ -212,7 +212,7 @@ begin
212212
webauthn_credential.verify(session[:creation_challenge], user_verification: true)
213213

214214
# Store Credential ID, Credential Public Key and Sign Count for future authentications
215-
user.credentials.create!(
215+
user.webauthn_credentials.create!(
216216
webauthn_id: webauthn_credential.id,
217217
public_key: webauthn_credential.public_key,
218218
sign_count: webauthn_credential.sign_count
@@ -232,7 +232,7 @@ end
232232
options = WebAuthn::Credential.options_for_get(
233233
# Pass `allow` when the user is already known (passwordless/2FA/reauth).
234234
# For a passkey-based (usernameless and passwordless) login, omit it and resolve the user from `user_handle` after `from_get`.
235-
allow: user.credentials.map { |c| c.webauthn_id },
235+
allow: user.webauthn_credentials.map { |c| c.webauthn_id },
236236
user_verification: "required" # For a passwordless or passkey-based (passwordless and usernameless) login. Use "discouraged" for 2FA.
237237
)
238238

@@ -264,7 +264,7 @@ attributes must be passed as keyword arguments to the `verify` method call.
264264
# in params[:publicKeyCredential]:
265265
webauthn_credential = WebAuthn::Credential.from_get(params[:publicKeyCredential])
266266

267-
stored_credential = user.credentials.find_by(webauthn_id: webauthn_credential.id)
267+
stored_credential = user.webauthn_credentials.find_by(webauthn_id: webauthn_credential.id)
268268

269269
begin
270270
webauthn_credential.verify(
@@ -299,8 +299,8 @@ Extensions can be requested in the initiation phase in both Credential Registrat
299299
```ruby
300300
# Credential Registration
301301
creation_options = WebAuthn::Credential.options_for_create(
302-
user: { id: user.webauthn_id, name: user.name },
303-
exclude: user.credentials.map { |c| c.webauthn_id },
302+
user: { id: user.webauthn_user_handle, name: user.name },
303+
exclude: user.webauthn_credentials.map { |c| c.webauthn_id },
304304
extensions: { appidExclude: domain.to_s },
305305
authenticator_selection: {
306306
resident_key: "discouraged", # For a passwordless login or 2FA. Use "required" for a passkey-based (passwordless and usernameless) login.
@@ -312,7 +312,7 @@ creation_options = WebAuthn::Credential.options_for_create(
312312

313313
# Credential Authentication
314314
options = WebAuthn::Credential.options_for_get(
315-
allow: user.credentials.map { |c| c.webauthn_id },
315+
allow: user.webauthn_credentials.map { |c| c.webauthn_id },
316316
extensions: { appid: domain.to_s }
317317
)
318318
```
@@ -359,8 +359,8 @@ to be used in the client-side code to call `navigator.credentials.create({ "publ
359359

360360
```ruby
361361
creation_options = WebAuthn::Credential.options_for_create(
362-
user: { id: user.webauthn_id, name: user.name },
363-
exclude: user.credentials.map { |c| c.webauthn_id }
362+
user: { id: user.webauthn_user_handle, name: user.name },
363+
exclude: user.webauthn_credentials.map { |c| c.webauthn_id }
364364
)
365365

366366
# Store the newly generated challenge somewhere so you can have it
@@ -382,7 +382,7 @@ Helper method to build the necessary [PublicKeyCredentialRequestOptions](https:/
382382
to be used in the client-side code to call `navigator.credentials.get({ "publicKey": publicKeyCredentialRequestOptions })`.
383383

384384
```ruby
385-
request_options = WebAuthn::Credential.options_for_get(allow: user.credentials.map { |c| c.webauthn_id })
385+
request_options = WebAuthn::Credential.options_for_get(allow: user.webauthn_credentials.map { |c| c.webauthn_id })
386386

387387
# Store the newly generated challenge somewhere so you can have it
388388
# for the verification phase.

0 commit comments

Comments
 (0)