Class: Unmagic::Passkeys::WebAuthn::Authenticator::Response
- Inherits:
-
Object
- Object
- Unmagic::Passkeys::WebAuthn::Authenticator::Response
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/unmagic/passkeys/web_authn/authenticator/response.rb
Overview
Action Pack WebAuthn Authenticator Response
Abstract base class for WebAuthn authenticator responses. Provides common validation logic for both registration (attestation) and authentication (assertion) ceremonies.
This class should not be instantiated directly. Use AttestationResponse for registration or AssertionResponse for authentication.
Validation
The validate! method performs security checks required by the WebAuthn specification:
-
Challenge verification - ensures the response matches the server-generated challenge
-
Origin verification - ensures the response comes from the expected origin
-
User verification - optionally requires biometric or PIN verification
Example
response = Unmagic::Passkeys::WebAuthn::Authenticator::AssertionResponse.new(
client_data_json: client_data_json,
authenticator_data: authenticator_data,
signature: signature,
credential: credential,
origin: "https://example.com",
user_verification: :required
)
response.validate!
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client_data_json ⇒ Object
readonly
Returns the value of attribute client_data_json.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#user_verification ⇒ Object
Returns the value of attribute user_verification.
Instance Method Summary collapse
- #authenticator_data ⇒ Object
-
#client_data ⇒ Object
Parses the client data JSON string into a Hash.
-
#initialize(client_data_json:, origin: nil, user_verification: :preferred) ⇒ Response
constructor
A new instance of Response.
-
#relying_party ⇒ Object
Returns the RelyingParty used for RP ID validation.
- #validate! ⇒ Object
Constructor Details
#initialize(client_data_json:, origin: nil, user_verification: :preferred) ⇒ Response
Returns a new instance of Response.
47 48 49 50 51 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 47 def initialize(client_data_json:, origin: nil, user_verification: :preferred) @client_data_json = client_data_json @origin = origin @user_verification = user_verification.to_sym end |
Instance Attribute Details
#client_data_json ⇒ Object (readonly)
Returns the value of attribute client_data_json.
35 36 37 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 35 def client_data_json @client_data_json end |
#origin ⇒ Object
Returns the value of attribute origin.
36 37 38 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 36 def origin @origin end |
#user_verification ⇒ Object
Returns the value of attribute user_verification.
36 37 38 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 36 def user_verification @user_verification end |
Instance Method Details
#authenticator_data ⇒ Object
72 73 74 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 72 def authenticator_data nil end |
#client_data ⇒ Object
Parses the client data JSON string into a Hash. Raises InvalidResponseError if the JSON is malformed.
66 67 68 69 70 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 66 def client_data @client_data ||= JSON.parse(client_data_json) rescue JSON::ParserError raise Unmagic::Passkeys::WebAuthn::InvalidResponseError, "Client data is not valid JSON" end |
#relying_party ⇒ Object
Returns the RelyingParty used for RP ID validation.
60 61 62 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 60 def Unmagic::Passkeys::WebAuthn. end |
#validate! ⇒ Object
53 54 55 56 57 |
# File 'lib/unmagic/passkeys/web_authn/authenticator/response.rb', line 53 def validate! super rescue ActiveModel::ValidationError raise Unmagic::Passkeys::WebAuthn::InvalidResponseError, errors..join(", ") end |