devise-webauthn 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ruby.yml +6 -2
- data/.rubocop.yml +1 -0
- data/Appraisals +18 -4
- data/CHANGELOG.md +50 -8
- data/Gemfile +2 -2
- data/Gemfile.lock +3 -5
- data/README.md +158 -5
- data/app/assets/javascript/devise/webauthn.js +179 -0
- data/app/controllers/devise/passkeys_controller.rb +6 -1
- data/app/controllers/devise/second_factor_webauthn_credentials_controller.rb +31 -4
- data/config/locales/en.yml +6 -0
- data/devise-webauthn.gemspec +1 -1
- data/gemfiles/devise_5_0.gemfile +26 -0
- data/gemfiles/rails_7_1.gemfile +3 -2
- data/gemfiles/rails_7_2.gemfile +3 -2
- data/gemfiles/rails_8_0.gemfile +3 -2
- data/gemfiles/rails_8_1.gemfile +3 -2
- data/gemfiles/rails_edge.gemfile +2 -1
- data/lib/devise/strategies/database_authenticatable.rb +1 -0
- data/lib/devise/strategies/webauthn_two_factor_authenticatable.rb +11 -5
- data/lib/devise/webauthn/engine.rb +6 -0
- data/lib/devise/webauthn/helpers/credentials_helper.rb +21 -36
- data/lib/devise/webauthn/routes.rb +1 -1
- data/lib/devise/webauthn/test/authenticator_helpers.rb +42 -0
- data/lib/devise/webauthn/version.rb +1 -1
- data/lib/generators/devise/webauthn/controllers_generator.rb +5 -1
- data/lib/generators/devise/webauthn/install/install_generator.rb +2 -2
- data/lib/generators/devise/webauthn/javascript/javascript_configuration_generator.rb +64 -0
- data/lib/generators/devise/webauthn/templates/controllers/second_factor_webauthn_credentials_controller.rb.tt +48 -0
- data/lib/generators/devise/webauthn/templates/controllers/two_factor_authentications_controller.rb.tt +13 -0
- data/lib/generators/devise/webauthn/views_generator.rb +2 -0
- data/lib/generators/devise/webauthn/webauthn_credential_model/templates/webauthn_credential_migration.rb.erb +17 -0
- data/lib/generators/devise/webauthn/webauthn_credential_model/webauthn_credential_model_generator.rb +15 -9
- metadata +10 -5
- data/lib/generators/devise/webauthn/stimulus/stimulus_generator.rb +0 -24
- data/lib/generators/devise/webauthn/stimulus/templates/webauthn_credentials_controller.js +0 -31
data/lib/generators/devise/webauthn/webauthn_credential_model/webauthn_credential_model_generator.rb
CHANGED
|
@@ -6,22 +6,28 @@ require "rails/generators/active_record"
|
|
|
6
6
|
module Devise
|
|
7
7
|
module Webauthn
|
|
8
8
|
class WebauthnCredentialModelGenerator < Rails::Generators::Base
|
|
9
|
+
include Rails::Generators::Migration
|
|
10
|
+
|
|
9
11
|
hide!
|
|
10
12
|
namespace "devise:webauthn:webauthn_credential_model"
|
|
11
13
|
|
|
14
|
+
source_root File.expand_path("templates", __dir__)
|
|
15
|
+
|
|
12
16
|
desc "Generate a WebauthnCredential model with the required fields for WebAuthn"
|
|
13
17
|
class_option :resource_name, type: :string, default: "user", desc: "The resource name for Devise (default: user)"
|
|
14
18
|
|
|
19
|
+
def self.next_migration_number(dirname)
|
|
20
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
def generate_model
|
|
16
|
-
invoke "active_record:model", [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"authentication_factor:integer{1}"
|
|
24
|
-
]
|
|
24
|
+
invoke "active_record:model", ["webauthn_credential"], migration: false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# TODO: Remove this in favor of strandard model generator with
|
|
28
|
+
# not null modifier (`!`) once we drop support for Rails < 8.
|
|
29
|
+
def generate_migration
|
|
30
|
+
migration_template "webauthn_credential_migration.rb.erb", "db/migrate/create_webauthn_credentials.rb"
|
|
25
31
|
end
|
|
26
32
|
|
|
27
33
|
def inject_webauthn_credential_content
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: devise-webauthn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cedarcode
|
|
@@ -13,14 +13,14 @@ dependencies:
|
|
|
13
13
|
name: devise
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '4.9'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '4.9'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
@@ -44,6 +44,7 @@ extensions: []
|
|
|
44
44
|
extra_rdoc_files: []
|
|
45
45
|
files:
|
|
46
46
|
- ".github/FUNDING.yml"
|
|
47
|
+
- ".github/dependabot.yml"
|
|
47
48
|
- ".github/workflows/release.yml"
|
|
48
49
|
- ".github/workflows/ruby.yml"
|
|
49
50
|
- ".gitignore"
|
|
@@ -57,6 +58,7 @@ files:
|
|
|
57
58
|
- LICENSE.txt
|
|
58
59
|
- README.md
|
|
59
60
|
- Rakefile
|
|
61
|
+
- app/assets/javascript/devise/webauthn.js
|
|
60
62
|
- app/controllers/devise/passkeys_controller.rb
|
|
61
63
|
- app/controllers/devise/second_factor_webauthn_credentials_controller.rb
|
|
62
64
|
- app/controllers/devise/two_factor_authentications_controller.rb
|
|
@@ -70,6 +72,7 @@ files:
|
|
|
70
72
|
- config.ru
|
|
71
73
|
- config/locales/en.yml
|
|
72
74
|
- devise-webauthn.gemspec
|
|
75
|
+
- gemfiles/devise_5_0.gemfile
|
|
73
76
|
- gemfiles/rails_7_1.gemfile
|
|
74
77
|
- gemfiles/rails_7_2.gemfile
|
|
75
78
|
- gemfiles/rails_8_0.gemfile
|
|
@@ -91,11 +94,13 @@ files:
|
|
|
91
94
|
- lib/generators/devise/webauthn/controllers_generator.rb
|
|
92
95
|
- lib/generators/devise/webauthn/install/install_generator.rb
|
|
93
96
|
- lib/generators/devise/webauthn/install/templates/webauthn.rb
|
|
94
|
-
- lib/generators/devise/webauthn/
|
|
95
|
-
- lib/generators/devise/webauthn/stimulus/templates/webauthn_credentials_controller.js
|
|
97
|
+
- lib/generators/devise/webauthn/javascript/javascript_configuration_generator.rb
|
|
96
98
|
- lib/generators/devise/webauthn/templates/controllers/README
|
|
97
99
|
- lib/generators/devise/webauthn/templates/controllers/passkeys_controller.rb.tt
|
|
100
|
+
- lib/generators/devise/webauthn/templates/controllers/second_factor_webauthn_credentials_controller.rb.tt
|
|
101
|
+
- lib/generators/devise/webauthn/templates/controllers/two_factor_authentications_controller.rb.tt
|
|
98
102
|
- lib/generators/devise/webauthn/views_generator.rb
|
|
103
|
+
- lib/generators/devise/webauthn/webauthn_credential_model/templates/webauthn_credential_migration.rb.erb
|
|
99
104
|
- lib/generators/devise/webauthn/webauthn_credential_model/webauthn_credential_model_generator.rb
|
|
100
105
|
- lib/generators/devise/webauthn/webauthn_id/webauthn_id_generator.rb
|
|
101
106
|
homepage: https://github.com/cedarcode/devise-webauthn
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rails/generators"
|
|
4
|
-
|
|
5
|
-
module Devise
|
|
6
|
-
module Webauthn
|
|
7
|
-
class StimulusGenerator < Rails::Generators::Base
|
|
8
|
-
hide!
|
|
9
|
-
source_root File.expand_path("templates", __dir__)
|
|
10
|
-
|
|
11
|
-
desc "Copy DeviseWebauthn Stimulus controller to your application"
|
|
12
|
-
|
|
13
|
-
def copy_stimulus_controller
|
|
14
|
-
copy_file "webauthn_credentials_controller.js",
|
|
15
|
-
"app/javascript/controllers/webauthn_credentials_controller.js"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def show_instructions
|
|
19
|
-
say "✓ Stimulus controller setup complete!", :green
|
|
20
|
-
say "The webauthn_credentials controller has been installed and will be automatically registered by Stimulus."
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Controller } from "@hotwired/stimulus"
|
|
2
|
-
|
|
3
|
-
export default class extends Controller {
|
|
4
|
-
static targets = ["credentialHiddenInput"]
|
|
5
|
-
|
|
6
|
-
async create({ params: { options } }) {
|
|
7
|
-
try {
|
|
8
|
-
const credentialOptions = PublicKeyCredential.parseCreationOptionsFromJSON(options);
|
|
9
|
-
const credential = await navigator.credentials.create({ publicKey: credentialOptions });
|
|
10
|
-
|
|
11
|
-
this.credentialHiddenInputTarget.value = JSON.stringify(credential);
|
|
12
|
-
|
|
13
|
-
this.element.submit();
|
|
14
|
-
} catch (error) {
|
|
15
|
-
alert(error.message || error);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async get({ params: { options } }) {
|
|
20
|
-
try {
|
|
21
|
-
const credentialOptions = PublicKeyCredential.parseRequestOptionsFromJSON(options);
|
|
22
|
-
const credential = await navigator.credentials.get({ publicKey: credentialOptions });
|
|
23
|
-
|
|
24
|
-
this.credentialHiddenInputTarget.value = JSON.stringify(credential);
|
|
25
|
-
|
|
26
|
-
this.element.submit();
|
|
27
|
-
} catch (error) {
|
|
28
|
-
alert(error.message || error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|