Module: Authn::WebauthnErrors

Extended by:
ActiveSupport::Concern
Included in:
Passkey::AuthenticateService, Passkey::RegisterService, Webauthn::AuthenticateService, Webauthn::RegisterService
Defined in:
app/services/concerns/authn/webauthn_errors.rb

Instance Method Summary collapse

Instance Method Details

#webauthn_error_messagesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/services/concerns/authn/webauthn_errors.rb', line 10

def webauthn_error_messages
  {
    'WebAuthn::AttestationStatementVerificationError' => {
      webauthn: _('Could not verify device authenticity. Try using a different device.'),
      passkey: _('Could not verify passkey authenticity. Try using a different passkey.')
    },
    'WebAuthn::AttestedCredentialVerificationError' => {
      webauthn: _('Invalid credential data received. Try registering the device again.'),
      passkey: _('Invalid passkey data received. Try creating a new passkey.')
    },
    'WebAuthn::AuthenticatorDataVerificationError' => {
      webauthn: _('Failed to add authentication method. Try again.'),
      passkey: _('Failed to add passkey. Try again.')
    },
    'WebAuthn::ChallengeVerificationError' => {
      webauthn: _('Failed to verify WebAuthn challenge. Try again.'),
      passkey: _('Failed to verify WebAuthn challenge. Try again.')
    },
    'WebAuthn::OriginVerificationError' => {
      webauthn: _('Unable to use this authentication method. Try a different authentication method.'),
      passkey: _('Unable to use this authentication method. Try a different authentication method.')
    },
    'WebAuthn::RpIdVerificationError' => {
      webauthn: _('Failed to authenticate due to a configuration issue. Try again later or contact support.'),
      passkey: _('Failed to authenticate due to a configuration issue. Try again later or contact support.')
    },
    'WebAuthn::SignatureVerificationError' => {
      webauthn: _('Failed to verify cryptographic signature. Try authenticating again.'),
      passkey: _('Failed to verify cryptographic signature. Try authenticating again.')
    },
    'WebAuthn::SignCountVerificationError' => {
      webauthn: _('Authenticator may have been cloned. Contact your administrator.'),
      passkey: _('Passkey may have been cloned. Contact your administrator.')
    },
    'WebAuthn::TokenBindingVerificationError' => {
      webauthn: _('Failed to verify connection security. Try adding the authentication method again.'),
      passkey: _('Failed to verify connection security. Try adding the authentication method again.')
    },
    'WebAuthn::TypeVerificationError' => {
      webauthn: _('This authentication method is not supported. Use a different authentication method.'),
      passkey: _('This authentication method is not supported. Use a different authentication method.')
    },
    'WebAuthn::UserPresenceVerificationError' => {
      webauthn: _('Failed to authenticate. Verify your identity with your device.'),
      passkey: _('Failed to authenticate. Verify your identity with your device.')
    },
    'WebAuthn::UserVerifiedVerificationError' => {
      webauthn: _('Failed to authenticate. Verify your identity with your device.'),
      passkey: _('Failed to authenticate. Verify your identity with your device.')
    }
  }.freeze
end

#webauthn_generic_error_messagesObject



63
64
65
66
67
68
# File 'app/services/concerns/authn/webauthn_errors.rb', line 63

def webauthn_generic_error_messages
  {
    webauthn: _('Failed to add authentication method. Try again.'),
    passkey: _('Failed to connect to your device. Try again.')
  }.freeze
end

#webauthn_human_readable_errors(error_message_class_name, passkey: nil) ⇒ Object

Returns a human readable error message, given a webauthn/passkey error class_name.

Accepts a WebAuthn::Error class.name and an optional keyword argument ‘passkey: true` if called from a Passkey bounded context.



75
76
77
78
79
80
81
82
83
84
85
# File 'app/services/concerns/authn/webauthn_errors.rb', line 75

def webauthn_human_readable_errors(error_message_class_name, passkey: nil)
  return unless error_message_class_name && error_message_class_name.is_a?(String)

  if passkey
    webauthn_error_messages.dig(error_message_class_name, :passkey) ||
      webauthn_generic_error_messages[:passkey]
  else
    webauthn_error_messages.dig(error_message_class_name, :webauthn) ||
      webauthn_generic_error_messages[:webauthn]
  end
end