Skip to content

Commit 6f85070

Browse files
refactor: replace WebauthnJSON calls with native API calls
1 parent 25d7df8 commit 6f85070

6 files changed

Lines changed: 6 additions & 12 deletions

File tree

lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/add_credential_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -14,7 +13,7 @@ export default class extends Controller {
1413
const nickname = event.target.querySelector("input[name='credential[nickname]']")?.value || "";
1514
const callbackUrl = `/webauthn-rails/credentials/callback?credential_nickname=${encodeURIComponent(nickname)}`;
1615

17-
WebAuthnJSON.create({ publicKey: data })
16+
navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) })
1817
.then((credential) => this.#submitCredential(callbackUrl, credential))
1918
.catch((error) => this.#showError(error));
2019
} else {

lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_registration_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -14,7 +13,7 @@ export default class extends Controller {
1413
const nickname = event.target.querySelector("input[name='registration[nickname]']")?.value || "";
1514
const callbackUrl = `/webauthn-rails/registration/callback?credential_nickname=${encodeURIComponent(nickname)}`;
1615

17-
WebAuthnJSON.create({ publicKey: data })
16+
navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) })
1817
.then((credential) => this.#submitRegistration(callbackUrl, credential))
1918
.catch((error) => this.#showError(error));
2019
} else {

lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_session_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -11,7 +10,7 @@ export default class extends Controller {
1110

1211
fetchResponse.response.json().then((data) => {
1312
if (fetchResponse.succeeded) {
14-
WebAuthnJSON.get({ publicKey: data })
13+
navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(data) })
1514
.then((credential) => this.#submitCredential(credential))
1615
.catch((error) => this.#showError(error));
1716
} else {

test/dummy/app/javascript/controllers/webauthn/rails/add_credential_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -14,7 +13,7 @@ export default class extends Controller {
1413
const nickname = event.target.querySelector("input[name='credential[nickname]']")?.value || "";
1514
const callbackUrl = `/webauthn-rails/credentials/callback?credential_nickname=${encodeURIComponent(nickname)}`;
1615

17-
WebAuthnJSON.create({ publicKey: data })
16+
navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) })
1817
.then((credential) => this.#submitCredential(callbackUrl, credential))
1918
.catch((error) => this.#showError(error));
2019
} else {

test/dummy/app/javascript/controllers/webauthn/rails/new_registration_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -14,7 +13,7 @@ export default class extends Controller {
1413
const nickname = event.target.querySelector("input[name='registration[nickname]']")?.value || "";
1514
const callbackUrl = `/webauthn-rails/registration/callback?credential_nickname=${encodeURIComponent(nickname)}`;
1615

17-
WebAuthnJSON.create({ publicKey: data })
16+
navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) })
1817
.then((credential) => this.#submitRegistration(callbackUrl, credential))
1918
.catch((error) => this.#showError(error));
2019
} else {

test/dummy/app/javascript/controllers/webauthn/rails/new_session_controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import * as WebAuthnJSON from "@github/webauthn-json";
32

43
export default class extends Controller {
54
static targets = ["errorElement"]
@@ -11,7 +10,7 @@ export default class extends Controller {
1110

1211
fetchResponse.response.json().then((data) => {
1312
if (fetchResponse.succeeded) {
14-
WebAuthnJSON.get({ publicKey: data })
13+
navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(data) })
1514
.then((credential) => this.#submitCredential(credential))
1615
.catch((error) => this.#showError(error));
1716
} else {

0 commit comments

Comments
 (0)