diff --git a/lib/generators/webauthn/rails/install_generator.rb b/lib/generators/webauthn/rails/install_generator.rb index 7cf24ef0..697a93a4 100644 --- a/lib/generators/webauthn/rails/install_generator.rb +++ b/lib/generators/webauthn/rails/install_generator.rb @@ -27,21 +27,6 @@ def copy_stimulus_controllers end end - def inject_js_packages - if using_importmap? - say %(Appending: pin "@github/webauthn-json", to: "https://ga.jspm.io/npm:@github/webauthn-json@2.1.1/dist/esm/webauthn-json.js") - append_to_file "config/importmap.rb", %(pin "@github/webauthn-json", to: "https://ga.jspm.io/npm:@github/webauthn-json@2.1.1/dist/esm/webauthn-json.js"\n) - elsif using_bun? - say "Adding webauthn-json to your package manager" - run "bun add @github/webauthn-json" - elsif has_package_json? - say "Adding webauthn-json to your package manager" - run "yarn add @github/webauthn-json" - else - puts "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem." - end - end - def copy_initializer_file template "config/initializers/webauthn.rb" end diff --git a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/add_credential_controller.js b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/add_credential_controller.js index d8e603cf..1212ab02 100644 --- a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/add_credential_controller.js +++ b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/add_credential_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -14,7 +13,7 @@ export default class extends Controller { const nickname = event.target.querySelector("input[name='credential[nickname]']")?.value || ""; const callbackUrl = `/webauthn-rails/credentials/callback?credential_nickname=${encodeURIComponent(nickname)}`; - WebAuthnJSON.create({ publicKey: data }) + navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) }) .then((credential) => this.#submitCredential(callbackUrl, credential)) .catch((error) => this.#showError(error)); } else { diff --git a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_registration_controller.js b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_registration_controller.js index 6c0b9bff..903527bb 100644 --- a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_registration_controller.js +++ b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_registration_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -14,7 +13,7 @@ export default class extends Controller { const nickname = event.target.querySelector("input[name='registration[nickname]']")?.value || ""; const callbackUrl = `/webauthn-rails/registration/callback?credential_nickname=${encodeURIComponent(nickname)}`; - WebAuthnJSON.create({ publicKey: data }) + navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) }) .then((credential) => this.#submitRegistration(callbackUrl, credential)) .catch((error) => this.#showError(error)); } else { diff --git a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_session_controller.js b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_session_controller.js index ef25a7d0..18d3c3bc 100644 --- a/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_session_controller.js +++ b/lib/generators/webauthn/rails/templates/app/javascript/controllers/webauthn/rails/new_session_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -11,7 +10,7 @@ export default class extends Controller { fetchResponse.response.json().then((data) => { if (fetchResponse.succeeded) { - WebAuthnJSON.get({ publicKey: data }) + navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(data) }) .then((credential) => this.#submitCredential(credential)) .catch((error) => this.#showError(error)); } else { diff --git a/test/dummy/app/javascript/controllers/webauthn/rails/add_credential_controller.js b/test/dummy/app/javascript/controllers/webauthn/rails/add_credential_controller.js index f935c6f5..67b08350 100644 --- a/test/dummy/app/javascript/controllers/webauthn/rails/add_credential_controller.js +++ b/test/dummy/app/javascript/controllers/webauthn/rails/add_credential_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -14,7 +13,7 @@ export default class extends Controller { const nickname = event.target.querySelector("input[name='credential[nickname]']")?.value || ""; const callbackUrl = `/webauthn-rails/credentials/callback?credential_nickname=${encodeURIComponent(nickname)}`; - WebAuthnJSON.create({ publicKey: data }) + navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) }) .then((credential) => this.#submitCredential(callbackUrl, credential)) .catch((error) => this.#showError(error)); } else { diff --git a/test/dummy/app/javascript/controllers/webauthn/rails/new_registration_controller.js b/test/dummy/app/javascript/controllers/webauthn/rails/new_registration_controller.js index 908094e5..fcb0f153 100644 --- a/test/dummy/app/javascript/controllers/webauthn/rails/new_registration_controller.js +++ b/test/dummy/app/javascript/controllers/webauthn/rails/new_registration_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -14,7 +13,7 @@ export default class extends Controller { const nickname = event.target.querySelector("input[name='registration[nickname]']")?.value || ""; const callbackUrl = `/webauthn-rails/registration/callback?credential_nickname=${encodeURIComponent(nickname)}`; - WebAuthnJSON.create({ publicKey: data }) + navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(data) }) .then((credential) => this.#submitRegistration(callbackUrl, credential)) .catch((error) => this.#showError(error)); } else { diff --git a/test/dummy/app/javascript/controllers/webauthn/rails/new_session_controller.js b/test/dummy/app/javascript/controllers/webauthn/rails/new_session_controller.js index 93b0bc28..c86c2f77 100644 --- a/test/dummy/app/javascript/controllers/webauthn/rails/new_session_controller.js +++ b/test/dummy/app/javascript/controllers/webauthn/rails/new_session_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import * as WebAuthnJSON from "@github/webauthn-json"; export default class extends Controller { static targets = ["errorElement"] @@ -11,7 +10,7 @@ export default class extends Controller { fetchResponse.response.json().then((data) => { if (fetchResponse.succeeded) { - WebAuthnJSON.get({ publicKey: data }) + navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(data) }) .then((credential) => this.#submitCredential(credential)) .catch((error) => this.#showError(error)); } else { diff --git a/test/dummy/config/importmap.rb b/test/dummy/config/importmap.rb index 6982161e..77a38045 100644 --- a/test/dummy/config/importmap.rb +++ b/test/dummy/config/importmap.rb @@ -5,5 +5,4 @@ pin "@hotwired/stimulus", to: "stimulus.min.js" pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" pin_all_from "app/javascript/controllers", under: "controllers" -pin "@github/webauthn-json", to: "https://ga.jspm.io/npm:@github/webauthn-json@2.1.1/dist/esm/webauthn-json.js" pin "webauthn-rails/credential", to: "credential.js" diff --git a/test/generators/install_generator_test.rb b/test/generators/install_generator_test.rb index 7334df11..e4301c7c 100644 --- a/test/generators/install_generator_test.rb +++ b/test/generators/install_generator_test.rb @@ -28,8 +28,6 @@ class InstallGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/create_webauthn_credentials.rb", /create_table :webauthn_credentials/ assert_file "config/routes.rb", /mount Webauthn::Rails::Engine/ - - assert_file "config/importmap.rb", /pin "@github\/webauthn-json"/ end test "assert all files are properly created when user model already exists" do @@ -49,8 +47,6 @@ class InstallGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/create_webauthn_credentials.rb", /create_table :webauthn_credentials/ assert_file "config/routes.rb", /mount Webauthn::Rails::Engine/ - - assert_file "config/importmap.rb", /pin "@github\/webauthn-json"/ end private