diff --git a/README.md b/README.md index 9fb0d6cd..9785dae5 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ end ```ruby # Generate and store the WebAuthn User ID the first time the user registers a credential if !user.webauthn_id - user.update!(webauthn_id: WebAuthn.generate_user_id) + user.update!(webauthn_id: WebAuthn.generate_user_handle) end options = WebAuthn::Credential.options_for_create( @@ -327,14 +327,16 @@ A list of all currently defined extensions: ## API -#### `WebAuthn.generate_user_id` +#### `WebAuthn.generate_user_handle` Generates a [WebAuthn User Handle](https://www.w3.org/TR/webauthn-2/#user-handle) that follows the WebAuthn spec recommendations. ```ruby -WebAuthn.generate_user_id # "lWoMZTGf_ml2RoY5qPwbwrkxrvTqWjGOxEoYBgxft3zG-LlrICvE-y8bxFi06zMyIOyNsJoWx4Fa2TOqoRmnxA" +WebAuthn.generate_user_handle # "lWoMZTGf_ml2RoY5qPwbwrkxrvTqWjGOxEoYBgxft3zG-LlrICvE-y8bxFi06zMyIOyNsJoWx4Fa2TOqoRmnxA" ``` +> `WebAuthn.generate_user_id` is also available as an alias. + #### `WebAuthn::Credential.options_for_create(options)` Helper method to build the necessary [PublicKeyCredentialCreationOptions](https://www.w3.org/TR/webauthn-2/#dictdef-publickeycredentialcreationoptions) diff --git a/lib/webauthn.rb b/lib/webauthn.rb index ee2bd098..f966b10d 100644 --- a/lib/webauthn.rb +++ b/lib/webauthn.rb @@ -10,7 +10,10 @@ module WebAuthn TYPE_PUBLIC_KEY = "public-key" - def self.generate_user_id - configuration.encoder.encode(SecureRandom.random_bytes(64)) + class << self + def generate_user_id + configuration.encoder.encode(SecureRandom.random_bytes(64)) + end + alias_method :generate_user_handle, :generate_user_id end end