Module: Warden::WebAuthn::RegistrationHelpers

Defined in:
lib/warden/webauthn/registration_helpers.rb

Overview

Helper methods to bootstrap registration challenges for implementors

Instance Method Summary collapse

Instance Method Details

#authenticator_selection_optionsObject



51
52
53
# File 'lib/warden/webauthn/registration_helpers.rb', line 51

def authenticator_selection_options
  { resident_key: "required", user_verification: "required" }
end

#delete_registration_challengeObject



31
32
33
# File 'lib/warden/webauthn/registration_helpers.rb', line 31

def delete_registration_challenge
  session.delete(registration_challenge_key)
end

#generate_registration_options(relying_party:, user_details:, exclude: [], options: {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/warden/webauthn/registration_helpers.rb', line 7

def generate_registration_options(relying_party:, user_details:, exclude: [], options: {})
  relying_party.options_for_registration(**{
    user: user_details,
    exclude: exclude,
    authenticator_selection: authenticator_selection_options
  }.merge(options))
end

#parsed_credentialObject



35
36
37
# File 'lib/warden/webauthn/registration_helpers.rb', line 35

def parsed_credential
  JSON.parse(raw_credential)
end

#raw_credentialObject



39
40
41
# File 'lib/warden/webauthn/registration_helpers.rb', line 39

def raw_credential
  params[raw_credential_key]
end

#raw_credential_keyObject



43
44
45
# File 'lib/warden/webauthn/registration_helpers.rb', line 43

def raw_credential_key
  "credential"
end

#registration_challengeObject



27
28
29
# File 'lib/warden/webauthn/registration_helpers.rb', line 27

def registration_challenge
  session[registration_challenge_key]
end

#registration_challenge_keyObject



47
48
49
# File 'lib/warden/webauthn/registration_helpers.rb', line 47

def registration_challenge_key
  "current_webauthn_registration_challenge"
end

#store_challenge_in_session(options_for_registration:) ⇒ Object



15
16
17
# File 'lib/warden/webauthn/registration_helpers.rb', line 15

def store_challenge_in_session(options_for_registration:)
  session[registration_challenge_key] = options_for_registration.challenge
end

#verify_registration(relying_party:) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/warden/webauthn/registration_helpers.rb', line 19

def verify_registration(relying_party:)
  relying_party.verify_registration(
    parsed_credential, registration_challenge, user_verification: true
  )
ensure
  delete_registration_challenge
end