devise-passkeys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +59 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +151 -0
- data/LICENSE.txt +21 -0
- data/README.md +200 -0
- data/Rakefile +17 -0
- data/devise-passkeys.gemspec +41 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_6.gemfile +25 -0
- data/gemfiles/rails_7.gemfile +25 -0
- data/lib/devise/passkeys/controllers/concerns/passkey_reauthentication.rb +39 -0
- data/lib/devise/passkeys/controllers/concerns/reauthentication_challenge.rb +21 -0
- data/lib/devise/passkeys/controllers/passkeys_controller_concern.rb +140 -0
- data/lib/devise/passkeys/controllers/reauthentication_controller_concern.rb +78 -0
- data/lib/devise/passkeys/controllers/registrations_controller_concern.rb +141 -0
- data/lib/devise/passkeys/controllers/sessions_controller_concern.rb +38 -0
- data/lib/devise/passkeys/controllers.rb +15 -0
- data/lib/devise/passkeys/model.rb +9 -0
- data/lib/devise/passkeys/passkey_issuer.rb +51 -0
- data/lib/devise/passkeys/rails.rb +6 -0
- data/lib/devise/passkeys/reauthentication_strategy.rb +16 -0
- data/lib/devise/passkeys/strategy.rb +64 -0
- data/lib/devise/passkeys/version.rb +7 -0
- data/lib/devise/passkeys.rb +29 -0
- data/sig/devise/passkeys.rbs +6 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2447f73b6085c64f92155f7fbef7e0fec400c1d0850e267bd75d0c5f5d1c5131
|
4
|
+
data.tar.gz: 4574971ab7925b50c8513273c9dd077e09732a22952533c7a92ceabee7071115
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0be4cd6b62abe8589b238b09684abaed8a1434cc3377880111dbb521edea92a085fd4d108490bc0bafb0270d642bc1b1426d4141420fce7198aa14e3d7da47c
|
7
|
+
data.tar.gz: 93752f8ef25cb01502abc1420d6fda0861a43719ab38dfd843b5699ec6f51126668e91da6bc5fce681f94c153c3a64d192b19829657bbedd4945a4f9e68b62ca
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
Exclude:
|
4
|
+
- 'test/rails_app/**/*.rb'
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
|
18
|
+
Style/SignalException:
|
19
|
+
Exclude:
|
20
|
+
- 'lib/devise/passkeys/strategy.rb'
|
21
|
+
|
22
|
+
Style/ClassAndModuleChildren:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 50
|
27
|
+
|
28
|
+
Metrics/ModuleLength:
|
29
|
+
Max: 300
|
30
|
+
|
31
|
+
Layout/LineLength:
|
32
|
+
Max: 180
|
33
|
+
|
34
|
+
Lint/UselessAssignment:
|
35
|
+
Exclude:
|
36
|
+
- 'test/**/*.rb'
|
37
|
+
|
38
|
+
Metrics/BlockLength:
|
39
|
+
Exclude:
|
40
|
+
- 'test/**/*.rb'
|
41
|
+
|
42
|
+
Metrics/ClassLength:
|
43
|
+
Exclude:
|
44
|
+
- 'test/**/*.rb'
|
45
|
+
|
46
|
+
Naming/VariableNumber:
|
47
|
+
Exclude:
|
48
|
+
- 'test/**/*.rb'
|
49
|
+
|
50
|
+
Metrics/AbcSize:
|
51
|
+
Exclude:
|
52
|
+
- 'test/**/*.rb'
|
53
|
+
|
54
|
+
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
|
55
|
+
Enabled: true
|
56
|
+
Gemspec/DevelopmentDependencies: # new in 1.44
|
57
|
+
Enabled: true
|
58
|
+
Gemspec/RequireMFA: # new in 1.23
|
59
|
+
Enabled: true
|
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tcannon00@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in devise-passkeys.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "appraisal"
|
10
|
+
gem "debug"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "database_cleaner-active_record"
|
17
|
+
gem "database_cleaner-mongoid"
|
18
|
+
gem "m"
|
19
|
+
gem "minitest", "~> 5.0"
|
20
|
+
gem "minitest-ci", require: false
|
21
|
+
gem "rack"
|
22
|
+
gem "simplecov"
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
devise-passkeys (0.1.0)
|
5
|
+
devise
|
6
|
+
warden-webauthn (>= 0.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (7.0.4.2)
|
12
|
+
activesupport (= 7.0.4.2)
|
13
|
+
activerecord (7.0.4.2)
|
14
|
+
activemodel (= 7.0.4.2)
|
15
|
+
activesupport (= 7.0.4.2)
|
16
|
+
activesupport (7.0.4.2)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
android_key_attestation (0.3.0)
|
22
|
+
appraisal (2.4.1)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
thor (>= 0.14.0)
|
26
|
+
ast (2.4.2)
|
27
|
+
awrence (1.2.1)
|
28
|
+
bcrypt (3.1.18)
|
29
|
+
bcrypt-ruby (3.1.5)
|
30
|
+
bcrypt (>= 3.1.3)
|
31
|
+
bindata (2.4.15)
|
32
|
+
bson (4.15.0)
|
33
|
+
cbor (0.5.9.6)
|
34
|
+
concurrent-ruby (1.2.0)
|
35
|
+
cose (1.3.0)
|
36
|
+
cbor (~> 0.5.9)
|
37
|
+
openssl-signature_algorithm (~> 1.0)
|
38
|
+
database_cleaner-active_record (2.1.0)
|
39
|
+
activerecord (>= 5.a)
|
40
|
+
database_cleaner-core (~> 2.0.0)
|
41
|
+
database_cleaner-core (2.0.1)
|
42
|
+
database_cleaner-mongoid (2.0.1)
|
43
|
+
database_cleaner-core (~> 2.0.0)
|
44
|
+
mongoid
|
45
|
+
debug (1.7.1)
|
46
|
+
irb (>= 1.5.0)
|
47
|
+
reline (>= 0.3.1)
|
48
|
+
devise (1.5.4)
|
49
|
+
bcrypt-ruby (~> 3.0)
|
50
|
+
orm_adapter (~> 0.0.3)
|
51
|
+
warden (~> 1.1)
|
52
|
+
docile (1.4.0)
|
53
|
+
i18n (1.12.0)
|
54
|
+
concurrent-ruby (~> 1.0)
|
55
|
+
io-console (0.6.0)
|
56
|
+
irb (1.6.2)
|
57
|
+
reline (>= 0.3.0)
|
58
|
+
json (2.6.3)
|
59
|
+
jwt (2.7.0)
|
60
|
+
m (1.6.1)
|
61
|
+
method_source (>= 0.6.7)
|
62
|
+
rake (>= 0.9.2.2)
|
63
|
+
method_source (1.0.0)
|
64
|
+
minitest (5.17.0)
|
65
|
+
minitest-ci (3.4.0)
|
66
|
+
minitest (>= 5.0.6)
|
67
|
+
mongo (2.18.2)
|
68
|
+
bson (>= 4.14.1, < 5.0.0)
|
69
|
+
mongoid (8.0.3)
|
70
|
+
activemodel (>= 5.1, < 7.1, != 7.0.0)
|
71
|
+
mongo (>= 2.18.0, < 3.0.0)
|
72
|
+
ruby2_keywords (~> 0.0.5)
|
73
|
+
openssl (3.1.0)
|
74
|
+
openssl-signature_algorithm (1.3.0)
|
75
|
+
openssl (> 2.0)
|
76
|
+
orm_adapter (0.0.7)
|
77
|
+
parallel (1.22.1)
|
78
|
+
parser (3.2.1.0)
|
79
|
+
ast (~> 2.4.1)
|
80
|
+
rack (3.0.4.1)
|
81
|
+
rainbow (3.1.1)
|
82
|
+
rake (13.0.6)
|
83
|
+
regexp_parser (2.7.0)
|
84
|
+
reline (0.3.2)
|
85
|
+
io-console (~> 0.5)
|
86
|
+
rexml (3.2.5)
|
87
|
+
rubocop (1.45.1)
|
88
|
+
json (~> 2.3)
|
89
|
+
parallel (~> 1.10)
|
90
|
+
parser (>= 3.2.0.0)
|
91
|
+
rainbow (>= 2.2.2, < 4.0)
|
92
|
+
regexp_parser (>= 1.8, < 3.0)
|
93
|
+
rexml (>= 3.2.5, < 4.0)
|
94
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
95
|
+
ruby-progressbar (~> 1.7)
|
96
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
97
|
+
rubocop-ast (1.26.0)
|
98
|
+
parser (>= 3.2.1.0)
|
99
|
+
ruby-progressbar (1.11.0)
|
100
|
+
ruby2_keywords (0.0.5)
|
101
|
+
safety_net_attestation (0.4.0)
|
102
|
+
jwt (~> 2.0)
|
103
|
+
simplecov (0.22.0)
|
104
|
+
docile (~> 1.1)
|
105
|
+
simplecov-html (~> 0.11)
|
106
|
+
simplecov_json_formatter (~> 0.1)
|
107
|
+
simplecov-html (0.12.3)
|
108
|
+
simplecov_json_formatter (0.1.4)
|
109
|
+
thor (1.2.1)
|
110
|
+
tpm-key_attestation (0.12.0)
|
111
|
+
bindata (~> 2.4)
|
112
|
+
openssl (> 2.0)
|
113
|
+
openssl-signature_algorithm (~> 1.0)
|
114
|
+
tzinfo (2.0.6)
|
115
|
+
concurrent-ruby (~> 1.0)
|
116
|
+
unicode-display_width (2.4.2)
|
117
|
+
warden (1.2.9)
|
118
|
+
rack (>= 2.0.9)
|
119
|
+
warden-webauthn (0.2.0)
|
120
|
+
warden
|
121
|
+
webauthn (>= 3)
|
122
|
+
webauthn (3.0.0)
|
123
|
+
android_key_attestation (~> 0.3.0)
|
124
|
+
awrence (~> 1.1)
|
125
|
+
bindata (~> 2.4)
|
126
|
+
cbor (~> 0.5.9)
|
127
|
+
cose (~> 1.1)
|
128
|
+
openssl (>= 2.2)
|
129
|
+
safety_net_attestation (~> 0.4.0)
|
130
|
+
tpm-key_attestation (~> 0.12.0)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
arm64-darwin-21
|
134
|
+
x86_64-linux
|
135
|
+
|
136
|
+
DEPENDENCIES
|
137
|
+
appraisal
|
138
|
+
database_cleaner-active_record
|
139
|
+
database_cleaner-mongoid
|
140
|
+
debug
|
141
|
+
devise-passkeys!
|
142
|
+
m
|
143
|
+
minitest (~> 5.0)
|
144
|
+
minitest-ci
|
145
|
+
rack
|
146
|
+
rake (~> 13.0)
|
147
|
+
rubocop (~> 1.21)
|
148
|
+
simplecov
|
149
|
+
|
150
|
+
BUNDLED WITH
|
151
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Thomas Cannon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
# Devise::Passkeys
|
2
|
+
|
3
|
+
This Devise extension allows you to use passkeys instead of passwords for user authentication.
|
4
|
+
|
5
|
+
`Devise::Passkeys` is lightweight and non-configurable. It does what it has to do and leaves some manual implementation to you.
|
6
|
+
|
7
|
+
|
8
|
+
# Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
```ruby
|
12
|
+
gem 'devise-passkeys'
|
13
|
+
```
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
# Usage
|
21
|
+
|
22
|
+
1. Add `:passkey_authenticatable` in your Devise-enabled model
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class User < ApplicationRecord
|
26
|
+
devise :passkey_authenticatable, ...
|
27
|
+
|
28
|
+
has_many :passkeys
|
29
|
+
|
30
|
+
def self.passkeys_class
|
31
|
+
Passkey
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.find_for_passkey(passkey)
|
35
|
+
self.find_by(id: passkey.user.id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_passkey_authentication
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
The Devise-enabled model must have a `webauthn_id` field in the model; which is:
|
44
|
+
|
45
|
+
- A string
|
46
|
+
- Has a unique index
|
47
|
+
|
48
|
+
This will allow you to explictly establish the relationship between a user & its passkeys (to help both your app & the user's authenticator with credential management)
|
49
|
+
|
50
|
+
2. Generate the model that will store passkeys. The model name is not important, but the Devise-enabled model should have:
|
51
|
+
- A `has_many :passkeys` association
|
52
|
+
- A `passkey_class` class method that returns the passkey class
|
53
|
+
- A `find_for_passkey(passkey)` class method that finds the user for a given passkey
|
54
|
+
|
55
|
+
```sh
|
56
|
+
rails g model Passkey user:references label:string external_id:string:index:uniq public_key:string:index sign_count:integer last_used_at:datetime
|
57
|
+
```
|
58
|
+
|
59
|
+
The following fields are required:
|
60
|
+
|
61
|
+
- `label:string` (required, cannot be blank you'll want to scope it to the Devise-enabled model)
|
62
|
+
- `external_id:string`
|
63
|
+
- `public_key:string`
|
64
|
+
- `sign_count:integer`
|
65
|
+
- `last_used_at:datetime`
|
66
|
+
|
67
|
+
It's recommended to add unique indexes on `external_id` and `public_key`
|
68
|
+
|
69
|
+
3. Generate custom devise controllers & views for your Devise-enabled model
|
70
|
+
|
71
|
+
[Since Devise does not have built-in passkeys support yet](https://github.com/heartcombo/devise/issues/5527), you'll need to customize both the controllers & the views
|
72
|
+
|
73
|
+
```shell
|
74
|
+
rails generate devise:controllers users
|
75
|
+
rails generate devise:views users
|
76
|
+
```
|
77
|
+
|
78
|
+
If you're trying to keep your codebase small, these instructions only concern the `Users::SessionsController` & `Users::RegistrationsController`, so you can delete any other generated custom controllers if needed. You will likely need to modify the `views/users/shared/*` partials though, because they assume passwords are being used.
|
79
|
+
|
80
|
+
4. Include the passkeys concerns into your controllers
|
81
|
+
|
82
|
+
Rather than having base classes, `Devise::Passkeys` has a series of concerns that can be mixed into your controllers. This allows you to change behavior, and does not keep you stuck down a path that could be incompatible with your existing authentication setup.
|
83
|
+
|
84
|
+
Here are examples of common controllers
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Users::RegistrationsController < Devise::RegistrationsController
|
88
|
+
include Devise::Passkeys::Controllers::RegistrationsControllerConcern
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
class Users::SessionsController < Devise::SessionsController
|
93
|
+
include Devise::Passkeys::Controllers::SessionsControllerConcern
|
94
|
+
# ... any custom code you need
|
95
|
+
|
96
|
+
def relying_party
|
97
|
+
WebAuthn::RelyingParty.new(...)
|
98
|
+
end
|
99
|
+
|
100
|
+
def set_relying_party_in_request_env
|
101
|
+
request.env[relying_party_key] = relying_party
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# frozen_string_literal: true
|
106
|
+
|
107
|
+
class Users::ReauthenticationController < DeviseController
|
108
|
+
include Devise::Passkeys::Controllers::ReauthenticationControllerConcern
|
109
|
+
# ... any custom code you need
|
110
|
+
|
111
|
+
def relying_party
|
112
|
+
WebAuthn::RelyingParty.new(...)
|
113
|
+
end
|
114
|
+
|
115
|
+
def set_relying_party_in_request_env
|
116
|
+
request.env[relying_party_key] = relying_party
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# frozen_string_literal: true
|
121
|
+
|
122
|
+
class Users::PasskeysController < DeviseController
|
123
|
+
include Devise::Passkeys::Controllers::PasskeysControllerConcern
|
124
|
+
# ... any custom code you need
|
125
|
+
|
126
|
+
def relying_party
|
127
|
+
WebAuthn::RelyingParty.new(...)
|
128
|
+
end
|
129
|
+
|
130
|
+
def set_relying_party_in_request_env
|
131
|
+
request.env[relying_party_key] = relying_party
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
6. Add necessary routes
|
138
|
+
|
139
|
+
Given the customization routes usually require, you'll need to hook up the routes yourself. Here's an example:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
devise_for :users, controllers: {
|
143
|
+
registrations: 'users/registrations',
|
144
|
+
sessions: 'users/sessions'
|
145
|
+
}
|
146
|
+
|
147
|
+
devise_scope :user do
|
148
|
+
post 'sign_up/new_challenge', to: 'users/registrations#new_challenge', as: :new_user_registration_challenge
|
149
|
+
post 'sign_in/new_challenge', to: 'users/sessions#new_challenge', as: :new_user_session_challenge
|
150
|
+
|
151
|
+
post 'reauthenticate/new_challenge', to: 'users/reauthentication#new_challenge', as: :new_user_reauthentication_challenge
|
152
|
+
post 'reauthenticate', to: 'users/reauthentication#reauthenticate', as: :user_reauthentication
|
153
|
+
|
154
|
+
namespace :users do
|
155
|
+
resources :passkeys, only: [:index, :create, :destroy] do
|
156
|
+
collection do
|
157
|
+
post :new_create_challenge
|
158
|
+
end
|
159
|
+
|
160
|
+
member do
|
161
|
+
post :new_destroy_challenge
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
|
169
|
+
## What about the Webauthn javascript? Mailers? Error handling?
|
170
|
+
|
171
|
+
You will have to implement these, since `Devise::Passkeys` is focused on the authentication handshakes, and each app is different (with different javascript setups, mailer needs, etc.)
|
172
|
+
|
173
|
+
## I need to see it in action
|
174
|
+
|
175
|
+
Here's a template repo! https://github.com/ruby-passkeys/devise-passkeys-template
|
176
|
+
|
177
|
+
## Development
|
178
|
+
|
179
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
180
|
+
|
181
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
182
|
+
|
183
|
+
## Contributing
|
184
|
+
|
185
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devise-passkeys. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/devise-passkeys/blob/main/CODE_OF_CONDUCT.md).
|
186
|
+
|
187
|
+
## License
|
188
|
+
|
189
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
190
|
+
|
191
|
+
## Code of Conduct
|
192
|
+
|
193
|
+
Everyone interacting in the Devise::Passkeys project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devise-passkeys/blob/main/CODE_OF_CONDUCT.md).
|
194
|
+
|
195
|
+
|
196
|
+
## Acknowledgements
|
197
|
+
|
198
|
+
This work is based on [Petr Hlavicka](https://github.com/CiTroNaK)'s [webauthn-with-devise](https://github.com/CiTroNaK/webauthn-with-devise/compare/main...3-passwordless).
|
199
|
+
|
200
|
+
The ethos of the library is inspired from [Tiddle](https://github.com/adamniedzielski/tiddle)'s straightforward, minimally-scoped approach.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
t.warning = false
|
11
|
+
end
|
12
|
+
|
13
|
+
require "rubocop/rake_task"
|
14
|
+
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/devise/passkeys/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "devise-passkeys"
|
7
|
+
spec.version = Devise::Passkeys::VERSION
|
8
|
+
spec.authors = ["Thomas Cannon"]
|
9
|
+
spec.email = ["tcannon00@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Use passkeys instead of passwords for Devise"
|
12
|
+
spec.description = "A Devise extension to use passkeys instead of passwords for authentication, using warden-webauthn"
|
13
|
+
spec.homepage = "https://github.com/ruby-passkeys/devise-passkeys"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/ruby-passkeys/devise-passkeys"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/ruby-passkeys/devise-passkeys/blob/main/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "devise"
|
36
|
+
spec.add_dependency "warden-webauthn", ">= 0.2.0"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, check out our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6"
|
6
|
+
gem "sqlite3"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "appraisal"
|
10
|
+
gem "debug"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "database_cleaner-active_record"
|
17
|
+
gem "database_cleaner-mongoid"
|
18
|
+
gem "m"
|
19
|
+
gem "minitest", "~> 5.0"
|
20
|
+
gem "minitest-ci", require: false
|
21
|
+
gem "rack"
|
22
|
+
gem "simplecov"
|
23
|
+
end
|
24
|
+
|
25
|
+
gemspec path: "../"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 7"
|
6
|
+
gem "sqlite3"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "appraisal"
|
10
|
+
gem "debug"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "database_cleaner-active_record"
|
17
|
+
gem "database_cleaner-mongoid"
|
18
|
+
gem "m"
|
19
|
+
gem "minitest", "~> 5.0"
|
20
|
+
gem "minitest-ci", require: false
|
21
|
+
gem "rack"
|
22
|
+
gem "simplecov"
|
23
|
+
end
|
24
|
+
|
25
|
+
gemspec path: "../"
|