Module: BetterAuth::Plugins

Defined in:
lib/better_auth/plugins/passkey.rb

Constant Summary collapse

PASSKEY_ERROR_CODES =
BetterAuth::Passkey::ErrorCodes::PASSKEY_ERROR_CODES
PASSKEY_CHALLENGE_MAX_AGE =
BetterAuth::Passkey::Challenges::CHALLENGE_MAX_AGE

Class Method Summary collapse

Class Method Details

.delete_passkey_endpointObject



61
62
63
# File 'lib/better_auth/plugins/passkey.rb', line 61

def delete_passkey_endpoint
  BetterAuth::Passkey::Routes::Management.delete_passkey_endpoint
end

.generate_passkey_authentication_options_endpoint(config) ⇒ Object



49
50
51
# File 'lib/better_auth/plugins/passkey.rb', line 49

def generate_passkey_authentication_options_endpoint(config)
  BetterAuth::Passkey::Routes::Authentication.generate_passkey_authentication_options_endpoint(config)
end

.generate_passkey_registration_options_endpoint(config) ⇒ Object



41
42
43
# File 'lib/better_auth/plugins/passkey.rb', line 41

def generate_passkey_registration_options_endpoint(config)
  BetterAuth::Passkey::Routes::Registration.generate_passkey_registration_options_endpoint(config)
end

.list_passkeys_endpointObject



57
58
59
# File 'lib/better_auth/plugins/passkey.rb', line 57

def list_passkeys_endpoint
  BetterAuth::Passkey::Routes::Management.list_passkeys_endpoint
end

.passkey(options = {}) ⇒ Object



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
# File 'lib/better_auth/plugins/passkey.rb', line 13

def passkey(options = {})
  config = {
    origin: nil,
    advanced: {
      web_authn_challenge_cookie: "better-auth-passkey"
    }
  }.merge(BetterAuth::Passkey::Utils.normalize_hash(options))
  config[:advanced] = {
    web_authn_challenge_cookie: "better-auth-passkey"
  }.merge(config[:advanced] || {})

  Plugin.new(
    id: "passkey",
    schema: passkey_schema(config[:schema]),
    endpoints: {
      generate_passkey_registration_options: generate_passkey_registration_options_endpoint(config),
      generate_passkey_authentication_options: generate_passkey_authentication_options_endpoint(config),
      verify_passkey_registration: verify_passkey_registration_endpoint(config),
      verify_passkey_authentication: verify_passkey_authentication_endpoint(config),
      list_passkeys: list_passkeys_endpoint,
      delete_passkey: delete_passkey_endpoint,
      update_passkey: update_passkey_endpoint
    },
    error_codes: PASSKEY_ERROR_CODES,
    options: config
  )
end

.passkey_after_registration_verification_user_id(config, ctx, credential, challenge, response, session) ⇒ Object



133
134
135
# File 'lib/better_auth/plugins/passkey.rb', line 133

def passkey_after_registration_verification_user_id(config, ctx, credential, challenge, response, session)
  BetterAuth::Passkey::Utils.after_registration_verification_user_id(config, ctx, credential, challenge, response, session)
end

.passkey_allowed_origins(config, ctx, origin: nil) ⇒ Object



97
98
99
# File 'lib/better_auth/plugins/passkey.rb', line 97

def passkey_allowed_origins(config, ctx, origin: nil)
  BetterAuth::Passkey::Utils.allowed_origins(config, ctx, origin: origin)
end

.passkey_attestation_response(credential) ⇒ Object



145
146
147
# File 'lib/better_auth/plugins/passkey.rb', line 145

def passkey_attestation_response(credential)
  BetterAuth::Passkey::Credentials.attestation_response(credential)
end

.passkey_authenticator_data(credential) ⇒ Object



149
150
151
# File 'lib/better_auth/plugins/passkey.rb', line 149

def passkey_authenticator_data(credential)
  BetterAuth::Passkey::Credentials.authenticator_data(credential)
end

.passkey_authenticator_selection(config, query) ⇒ Object



105
106
107
# File 'lib/better_auth/plugins/passkey.rb', line 105

def passkey_authenticator_selection(config, query)
  BetterAuth::Passkey::Utils.authenticator_selection(config, query)
end

.passkey_call_callback(callback, data) ⇒ Object



137
138
139
# File 'lib/better_auth/plugins/passkey.rb', line 137

def passkey_call_callback(callback, data)
  BetterAuth::Passkey::Utils.call_callback(callback, data)
end


85
86
87
# File 'lib/better_auth/plugins/passkey.rb', line 85

def passkey_challenge_cookie(ctx, config)
  BetterAuth::Passkey::Challenges.challenge_cookie(ctx, config)
end

.passkey_challenge_token(ctx, config) ⇒ Object



81
82
83
# File 'lib/better_auth/plugins/passkey.rb', line 81

def passkey_challenge_token(ctx, config)
  BetterAuth::Passkey::Challenges.challenge_token(ctx, config)
end

.passkey_credential_descriptor(record, kind: :allow) ⇒ Object



161
162
163
# File 'lib/better_auth/plugins/passkey.rb', line 161

def passkey_credential_descriptor(record, kind: :allow)
  BetterAuth::Passkey::Credentials.credential_descriptor(record, kind: kind)
end

.passkey_credential_id(record) ⇒ Object



157
158
159
# File 'lib/better_auth/plugins/passkey.rb', line 157

def passkey_credential_id(record)
  BetterAuth::Passkey::Credentials.credential_id(record)
end

.passkey_deep_merge_hashes(base, override) ⇒ Object



165
166
167
# File 'lib/better_auth/plugins/passkey.rb', line 165

def passkey_deep_merge_hashes(base, override)
  BetterAuth::Passkey::Schema.deep_merge_hashes(base, override)
end

.passkey_find_challenge(ctx, verification_token) ⇒ Object



77
78
79
# File 'lib/better_auth/plugins/passkey.rb', line 77

def passkey_find_challenge(ctx, verification_token)
  BetterAuth::Passkey::Challenges.find_challenge(ctx, verification_token)
end

.passkey_origin(config, ctx) ⇒ Object



93
94
95
# File 'lib/better_auth/plugins/passkey.rb', line 93

def passkey_origin(config, ctx)
  BetterAuth::Passkey::Utils.origin(config, ctx)
end

.passkey_registration_user_data(id:, name:, display_name: nil, email: nil) ⇒ Object



125
126
127
# File 'lib/better_auth/plugins/passkey.rb', line 125

def passkey_registration_user_data(id:, name:, display_name: nil, email: nil)
  BetterAuth::Passkey::Utils.registration_user_data(id: id, name: name, display_name: display_name, email: email)
end

.passkey_relying_party(config, ctx, origin: nil) ⇒ Object



89
90
91
# File 'lib/better_auth/plugins/passkey.rb', line 89

def passkey_relying_party(config, ctx, origin: nil)
  BetterAuth::Passkey::Utils.relying_party(config, ctx, origin: origin)
end

.passkey_require_key!(body, key) ⇒ Object



113
114
115
# File 'lib/better_auth/plugins/passkey.rb', line 113

def passkey_require_key!(body, key)
  BetterAuth::Passkey::Utils.require_key!(body, key)
end

.passkey_require_string!(body, key) ⇒ Object



117
118
119
# File 'lib/better_auth/plugins/passkey.rb', line 117

def passkey_require_string!(body, key)
  BetterAuth::Passkey::Utils.require_string!(body, key)
end

.passkey_resolve_extensions(extensions, ctx) ⇒ Object



129
130
131
# File 'lib/better_auth/plugins/passkey.rb', line 129

def passkey_resolve_extensions(extensions, ctx)
  BetterAuth::Passkey::Utils.resolve_extensions(extensions, ctx)
end

.passkey_resolve_registration_user(config, ctx, query) ⇒ Object



121
122
123
# File 'lib/better_auth/plugins/passkey.rb', line 121

def passkey_resolve_registration_user(config, ctx, query)
  BetterAuth::Passkey::Utils.resolve_registration_user(config, ctx, query)
end

.passkey_rp_id(config, ctx) ⇒ Object



101
102
103
# File 'lib/better_auth/plugins/passkey.rb', line 101

def passkey_rp_id(config, ctx)
  BetterAuth::Passkey::Utils.rp_id(config, ctx)
end

.passkey_schema(custom_schema = nil) ⇒ Object



69
70
71
# File 'lib/better_auth/plugins/passkey.rb', line 69

def passkey_schema(custom_schema = nil)
  BetterAuth::Passkey::Schema.passkey_schema(custom_schema)
end

.passkey_store_challenge(ctx, config, challenge, user_id) ⇒ Object



73
74
75
# File 'lib/better_auth/plugins/passkey.rb', line 73

def passkey_store_challenge(ctx, config, challenge, user_id)
  BetterAuth::Passkey::Challenges.store_challenge(ctx, config, challenge, user_id)
end

.passkey_validate_authenticator_attachment!(value) ⇒ Object



109
110
111
# File 'lib/better_auth/plugins/passkey.rb', line 109

def passkey_validate_authenticator_attachment!(value)
  BetterAuth::Passkey::Utils.validate_authenticator_attachment!(value)
end

.passkey_webauthn_response(value) ⇒ Object



141
142
143
# File 'lib/better_auth/plugins/passkey.rb', line 141

def passkey_webauthn_response(value)
  BetterAuth::Passkey::Credentials.webauthn_response(value)
end

.passkey_wire(record) ⇒ Object



153
154
155
# File 'lib/better_auth/plugins/passkey.rb', line 153

def passkey_wire(record)
  BetterAuth::Passkey::Credentials.wire(record)
end

.update_passkey_endpointObject



65
66
67
# File 'lib/better_auth/plugins/passkey.rb', line 65

def update_passkey_endpoint
  BetterAuth::Passkey::Routes::Management.update_passkey_endpoint
end

.verify_passkey_authentication_endpoint(config) ⇒ Object



53
54
55
# File 'lib/better_auth/plugins/passkey.rb', line 53

def verify_passkey_authentication_endpoint(config)
  BetterAuth::Passkey::Routes::Authentication.verify_passkey_authentication_endpoint(config)
end

.verify_passkey_registration_endpoint(config) ⇒ Object



45
46
47
# File 'lib/better_auth/plugins/passkey.rb', line 45

def verify_passkey_registration_endpoint(config)
  BetterAuth::Passkey::Routes::Registration.verify_passkey_registration_endpoint(config)
end