Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lib/generators/webauthn/rails/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/dist/esm/webauthn-json.js")
append_to_file "config/importmap.rb", %(pin "@github/webauthn-json", to: "https://ga.jspm.io/npm:@github/[email protected]/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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from "@hotwired/stimulus";
import * as WebAuthnJSON from "@github/webauthn-json";

export default class extends Controller {
static targets = ["errorElement"]
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion test/dummy/config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/dist/esm/webauthn-json.js"
pin "webauthn-rails/credential", to: "credential.js"
4 changes: 0 additions & 4 deletions test/generators/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down