Sha256: 83a3d03c0e2d463f9ced9728611e84873d23425869cb4232d0f3da315cda30ab
Contents?: true
Size: 1.16 KB
Versions: 24
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module Koi module Controller module HasWebauthn extend ActiveSupport::Concern included do helper_method :webauthn_auth_options end def webauthn_relying_party @webauthn_relying_party ||= WebAuthn::RelyingParty.new( name: Koi.config.admin_name, origin: request.base_url, ) end def webauthn_auth_options options = webauthn_relying_party.options_for_authentication( allow: Admin::Credential.pluck(:external_id), ) session[:authentication_challenge] = options.challenge options end def webauthn_authenticate! return if session_params[:response].blank? webauthn_credential, stored_credential = webauthn_relying_party.verify_authentication( JSON.parse(session_params[:response]), session[:authentication_challenge], ) do |credential| Admin::Credential.find_by!(external_id: credential.id) end stored_credential.update!(sign_count: webauthn_credential.sign_count) stored_credential.admin end end end end
Version data entries
24 entries across 24 versions & 1 rubygems