Module: Koi::Controller::HasWebauthn::Helper

Defined in:
app/controllers/concerns/koi/controller/has_webauthn.rb

Instance Method Summary collapse

Instance Method Details

#webauthn_authentication_options_valueObject



21
22
23
24
25
26
27
# File 'app/controllers/concerns/koi/controller/has_webauthn.rb', line 21

def webauthn_authentication_options_value
  options = controller.webauthn_relying_party.options_for_authentication

  session[:authentication_challenge] = options.challenge

  options
end

#webauthn_registration_options_valueObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/concerns/koi/controller/has_webauthn.rb', line 29

def webauthn_registration_options_value
  user = Koi::Current.admin_user.tap do |u|
    u.update!(webauthn_id: WebAuthn.generate_user_id) unless u.webauthn_id
  end

  options = controller.webauthn_relying_party.options_for_registration(
    user:    {
      id:           user.webauthn_id,
      name:         user.email,
      display_name: user.name,
    },
    exclude: user.credentials.pluck(:external_id),
  )

  session[:registration_challenge] = options.challenge

  options
end