Class: Unmagic::Passkeys::WebAuthn::PublicKeyCredential::RequestOptions
- Inherits:
-
Options
- Object
- Options
- Unmagic::Passkeys::WebAuthn::PublicKeyCredential::RequestOptions
- Defined in:
- lib/unmagic/passkeys/web_authn/public_key_credential/request_options.rb
Overview
Action Pack WebAuthn Public Key Credential Request Options
Generates options for the WebAuthn authentication ceremony (using an existing
credential). These options are passed to navigator.credentials.get() in
the browser to prompt the user to authenticate with a registered authenticator.
Usage
= Unmagic::Passkeys::WebAuthn::PublicKeyCredential::RequestOptions.new(
credentials: current_user.webauthn_credentials
)
# In your controller, return as JSON for the JavaScript WebAuthn API
render json: { publicKey: .as_json }
Attributes
[+credentials+]
A collection of credential records for the user. Each credential must
respond to id returning the Base64URL-encoded credential ID, and
transports returning an array of transport strings.
[+relying_party+]
The relying party (your application) configuration. Defaults to
Unmagic::Passkeys::WebAuthn.relying_party.
Constant Summary
Constants inherited from Options
Options::CHALLENGE_LENGTH, Options::USER_VERIFICATION_OPTIONS
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Object
Returns a Hash suitable for JSON serialization and passing to the WebAuthn JavaScript API.
-
#initialize(attributes = {}) ⇒ RequestOptions
constructor
A new instance of RequestOptions.
Methods inherited from Options
#challenge, #inspect, #validate!
Constructor Details
#initialize(attributes = {}) ⇒ RequestOptions
Returns a new instance of RequestOptions.
31 32 33 34 |
# File 'lib/unmagic/passkeys/web_authn/public_key_credential/request_options.rb', line 31 def initialize(attributes = {}) super validate! end |
Instance Method Details
#as_json(options = {}) ⇒ Object
Returns a Hash suitable for JSON serialization and passing to the WebAuthn JavaScript API.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/unmagic/passkeys/web_authn/public_key_credential/request_options.rb', line 38 def as_json( = {}) json = { challenge: challenge, rpId: .id, allowCredentials: credentials.map { |credential| allow_credential_json(credential) }, userVerification: user_verification.to_s } json.as_json() end |