Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/webauthn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ module WebAuthn
def self.generate_user_id
configuration.encoder.encode(SecureRandom.random_bytes(64))
end

singleton_class.send(:alias_method, :generate_user_handle, :generate_user_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer to do:

class << self
  def generate_user_id
    configuration.encoder.encode(SecureRandom.random_bytes(64))
  end  
  alias_method :generate_user_handle, :generate_user_id
end

🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed e9fac49

end