Skip to content

Commit 0350783

Browse files
chore: fetch options endpoints from javascript
1 parent 56db786 commit 0350783

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

app/assets/javascript/devise/webauthn.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export class WebauthnCreateElement extends HTMLElement {
44
event.preventDefault();
55

66
try {
7-
const options = JSON.parse(this.getAttribute('data-options-json'));
8-
const publicKey = PublicKeyCredential.parseCreationOptionsFromJSON(options);
7+
const response = await fetch(this.getAttribute('data-options-url');
8+
const publicKey = PublicKeyCredential.parseCreationOptionsFromJSON(await response.json());
99
const credential = await navigator.credentials.create({ publicKey });
1010

1111
this.querySelector('[data-webauthn-target="response"]').value = JSON.stringify(credential);
@@ -37,8 +37,8 @@ export class WebauthnGetElement extends HTMLElement {
3737
event.preventDefault();
3838

3939
try {
40-
const options = JSON.parse(this.getAttribute('data-options-json'));
41-
const publicKey = PublicKeyCredential.parseRequestOptionsFromJSON(options);
40+
const response = await fetch(this.getAttribute('data-options-url');
41+
const publicKey = PublicKeyCredential.parseRequestOptionsFromJSON(await response.json());
4242
const credential = await navigator.credentials.get({ publicKey });
4343

4444
this.querySelector('[data-webauthn-target="response"]').value = JSON.stringify(credential);

lib/devise/webauthn/helpers/credentials_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def passkey_creation_form_for(resource, form_classes: nil, &block)
99
method: :post,
1010
class: form_classes
1111
) do |f|
12-
tag.webauthn_create(data: { options_json: create_passkey_options(resource) }) do
12+
tag.webauthn_create(data: { options_url: options_for_create_passkeys_path(resource) }) do
1313
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
1414
concat capture(f, &block)
1515
end
@@ -22,7 +22,7 @@ def login_with_passkey_button(text = nil, session_path:, button_classes: nil, fo
2222
method: :post,
2323
class: form_classes
2424
) do |f|
25-
tag.webauthn_get(data: { options_json: passkey_authentication_options }) do
25+
tag.webauthn_get(data: { options_url: options_for_get_passkeys_path(resource) }) do
2626
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
2727

2828
concat f.button(text, type: "submit", class: button_classes, &block)
@@ -36,7 +36,7 @@ def security_key_creation_form_for(resource, form_classes: nil, &block)
3636
method: :post,
3737
class: form_classes
3838
) do |f|
39-
tag.webauthn_create(data: { options_json: create_security_key_options(resource) }) do
39+
tag.webauthn_create(data: { options_url: options_for_create_second_factor_webauthn_credentials_path(resource) }) do
4040
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
4141
concat capture(f, &block)
4242
end
@@ -49,7 +49,7 @@ def login_with_security_key_button(text = nil, resource:, button_classes: nil, f
4949
method: :post,
5050
class: form_classes
5151
) do |f|
52-
tag.webauthn_get(data: { options_json: security_key_authentication_options(resource) }) do
52+
tag.webauthn_get(data: { options_url: options_for_get_second_factor_webauthn_credentials_path(resource) }) do
5353
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
5454
concat f.button(text, type: "submit", class: button_classes, &block)
5555
end

0 commit comments

Comments
 (0)