Module: Koi::Controller::HasWebauthn
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/koi/controller/has_webauthn.rb
Defined Under Namespace
Modules: Helper
Instance Method Summary collapse
- #webauthn_authenticate!(response) ⇒ Object
- #webauthn_nickname ⇒ Object
- #webauthn_register!(response) ⇒ Object
- #webauthn_relying_party ⇒ Object
Instance Method Details
#webauthn_authenticate!(response) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/concerns/koi/controller/has_webauthn.rb', line 49 def webauthn_authenticate!(response) return if response.blank? webauthn_credential, stored_credential = .verify_authentication( JSON.parse(response), session.delete(:authentication_challenge), ) do |credential| Admin::Credential.find_by!(external_id: credential.id) end stored_credential.update( sign_count: webauthn_credential.sign_count, updated_at: DateTime.current, ) stored_credential.admin rescue ActiveRecord::RecordNotFound, WebAuthn::VerificationError false end |
#webauthn_nickname ⇒ Object
88 89 90 91 |
# File 'app/controllers/concerns/koi/controller/has_webauthn.rb', line 88 def webauthn_nickname user_agent = UserAgent.parse(request.user_agent) "#{user_agent.browser} (#{user_agent.platform})" end |
#webauthn_register!(response) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/concerns/koi/controller/has_webauthn.rb', line 69 def webauthn_register!(response) return if response.blank? webauthn_credential = .verify_registration( JSON.parse(response), session.delete(:registration_challenge), ) Koi::Current .admin_user .credentials .create_with(nickname: webauthn_nickname, public_key: webauthn_credential.public_key, sign_count: webauthn_credential.sign_count) .create_or_find_by!( external_id: webauthn_credential.id, ) end |