Module: Devise::Webauthn::CredentialsHelper

Defined in:
lib/devise/webauthn/helpers/credentials_helper.rb

Instance Method Summary collapse

Instance Method Details

#login_with_passkey_form_for(resource_or_resource_name, **options, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/devise/webauthn/helpers/credentials_helper.rb', line 17

def (resource_or_resource_name, **options, &block)
  scope = Devise::Mapping.find_scope!(resource_or_resource_name)

  form_with(
    **options, scope: scope, url: session_path(resource_or_resource_name), method: :post
  ) do |f|
    tag.webauthn_get(data: { options_url: passkey_authentication_options_path(resource_or_resource_name) }) do
      concat hidden_field_tag(:public_key_credential, nil, data: { webauthn_target: "response" })
      concat capture(f, &block)
    end
  end
end

#login_with_security_key_form_for(resource_or_resource_name, **options, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/devise/webauthn/helpers/credentials_helper.rb', line 43

def (resource_or_resource_name, **options, &block)
  form_with(
    **options, url: two_factor_authentication_path(resource_or_resource_name), method: :post
  ) do |f|
    tag.webauthn_get(data: {
                       options_url: security_key_authentication_options_path(resource_or_resource_name)
                     }) do
      concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
      concat capture(f, &block)
    end
  end
end

#passkey_creation_form_for(resource_or_resource_name, **options, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/devise/webauthn/helpers/credentials_helper.rb', line 6

def passkey_creation_form_for(resource_or_resource_name, **options, &block)
  form_with(
    **options, url: passkeys_path(resource_or_resource_name), method: :post
  ) do |f|
    tag.webauthn_create(data: { options_url: passkey_registration_options_path(resource_or_resource_name) }) do
      concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
      concat capture(f, &block)
    end
  end
end

#security_key_creation_form_for(resource_or_resource_name, **options, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/devise/webauthn/helpers/credentials_helper.rb', line 30

def security_key_creation_form_for(resource_or_resource_name, **options, &block)
  form_with(
    **options, url: second_factor_webauthn_credentials_path(resource_or_resource_name), method: :post
  ) do |f|
    tag.webauthn_create(
      data: { options_url: security_key_registration_options_path(resource_or_resource_name) }
    ) do
      concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
      concat capture(f, &block)
    end
  end
end