Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions lib/webauthn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading