Module: HasSecurePasskey::ApplicationHelper

Defined in:
app/helpers/has_secure_passkey/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#button_to_passkey_login(text, path = nil, **options, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/has_secure_passkey/application_helper.rb', line 28

def (text, path = nil, **options, &block)
  if block_given?
    button_to has_secure_passkey.challenges_path(text), **options, &block
  else
    button_to text, has_secure_passkey.challenges_path(path), **options
  end
end

#login_with_passkey(callback:, **options) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/has_secure_passkey/application_helper.rb', line 19

def (callback:, **options)
  options_for_get = HasSecurePasskey::OptionsForGet.new

  tag.web_authn(nil, action: :get, callback:,
    options: options_for_get.to_json,
    message: options_for_get.message,
    **options)
end

#prompt_for_new_passkey(callback:, current_authenticatable: nil, **options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/has_secure_passkey/application_helper.rb', line 3

def prompt_for_new_passkey(callback:, current_authenticatable: nil, **options)
  options_for_create =
    if current_authenticatable.present?
      HasSecurePasskey::OptionsForCreate.new(authenticatable: current_authenticatable)
    else
      HasSecurePasskey::OptionsForCreate.
        from_message(params[:webauthn_message])
    end

  tag.web_authn(nil, action: :create, callback:,
    options: options_for_create.to_json,
    message: options_for_create.message, **options)
rescue ActiveSupport::MessageVerifier::InvalidSignature
  false
end