devise-passwordless 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +9 -0
- data/README.md +36 -6
- data/devise-passwordless.gemspec +0 -4
- data/lib/devise/passwordless/login_token.rb +1 -1
- data/lib/devise/passwordless/version.rb +1 -1
- data/lib/generators/devise/passwordless/install_generator.rb +15 -5
- data/lib/generators/devise/passwordless/templates/magic_links_controller.rb.erb +2 -1
- metadata +3 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c015970325061c0bd86aac15d0a2a90e200cd036cbe85249503d16881fb07d9a
|
4
|
+
data.tar.gz: 562b24b072376547b0e4bb6d503924dc58ad6d404a8e01397751af52e7a318cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9bd36c841f32e9e017e0ae672636ef0e2708064b7d10b9e001af148f3e6fbeee3b3ee117a21ee1947c3d91f7a036b9e33079f28f15d582681d75bdac11d995d
|
7
|
+
data.tar.gz: ab507245047decac1f9fbeb871dc54e7bef7e056c5c065550dcdedb1082ecf7db3c0caf911346b83ac93b636b2512b4735bdecf7754b9079327427b4160854f6
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -4,3 +4,12 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in devise-passwordless.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 10.0"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "rspec", "~> 3.0"
|
12
|
+
gem "generator_spec"
|
13
|
+
gem "timecop"
|
14
|
+
gem "pry"
|
15
|
+
end
|
data/README.md
CHANGED
@@ -37,16 +37,12 @@ See the [customization section](#customization) for details on what gets install
|
|
37
37
|
|
38
38
|
This gem adds a `:magic_link_authenticatable` strategy that can be used in your Devise models for passwordless authentication. This strategy plays well with most other Devise strategies (see [*notes on other Devise strategies*](#notes-on-other-devise-strategies)).
|
39
39
|
|
40
|
-
For example,
|
40
|
+
For example, if your Devise model is User, enable the strategy like this:
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
# app/models/user.rb
|
44
44
|
class User < ApplicationRecord
|
45
|
-
devise :magic_link_authenticatable,
|
46
|
-
:registerable,
|
47
|
-
:rememberable,
|
48
|
-
:validatable,
|
49
|
-
:confirmable
|
45
|
+
devise :magic_link_authenticatable #, :registerable, :rememberable, ...
|
50
46
|
end
|
51
47
|
```
|
52
48
|
|
@@ -84,6 +80,15 @@ And these should be edited to remove password references:
|
|
84
80
|
* `app/views/devise/sessions/new.html.erb`
|
85
81
|
* Delete field `:password`
|
86
82
|
|
83
|
+
#### Manually sending magic links
|
84
|
+
|
85
|
+
You can very easily send a magic link at any point like so:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
remember_me = true
|
89
|
+
User.send_magic_link(remember_me)
|
90
|
+
```
|
91
|
+
|
87
92
|
## Customization
|
88
93
|
|
89
94
|
Configuration options are stored in Devise's initializer at `config/initializers/devise.rb`:
|
@@ -192,6 +197,24 @@ en:
|
|
192
197
|
admin_subject: "Here's your ADMIN magic login link ✨"
|
193
198
|
```
|
194
199
|
|
200
|
+
#### Scoped views
|
201
|
+
|
202
|
+
If you have multiple Devise models, some that are passwordless and some that aren't, you will probably want to enable [Devise's `scoped_views` setting](https://henrytabima.github.io/rails-setup/docs/devise/configuring-views) so that the models have different signup and login pages (since some models will need password fields and others won't).
|
203
|
+
|
204
|
+
If you need to generate fresh Devise views for your models, you can do so like so:
|
205
|
+
|
206
|
+
```
|
207
|
+
$ rails generate devise:views users
|
208
|
+
$ rails generate devise:views admins
|
209
|
+
```
|
210
|
+
|
211
|
+
Which will generate the whole set of Devise views under these paths:
|
212
|
+
|
213
|
+
```
|
214
|
+
app/views/users/
|
215
|
+
app/views/admins/
|
216
|
+
```
|
217
|
+
|
195
218
|
### Notes on other Devise strategies
|
196
219
|
|
197
220
|
If using the `:rememberable` strategy for "remember me" functionality, you'll need to add a `remember_token` column to your resource, as by default that strategy assumes you're using a password auth strategy and relies on comparing the password's salt to validate cookies:
|
@@ -204,6 +227,13 @@ end
|
|
204
227
|
|
205
228
|
If using the `:confirmable` strategy, you may want to override the default Devise behavior of requiring a fresh login after email confirmation (e.g. [this](https://stackoverflow.com/a/39010334/215168) or [this](https://stackoverflow.com/a/25865526/215168) approach). Otherwise, users will have to get a fresh login link after confirming their email, which makes little sense if they just confirmed they own the email address.
|
206
229
|
|
230
|
+
## Alternatives
|
231
|
+
|
232
|
+
Other Ruby libraries that offer passwordless authentication:
|
233
|
+
|
234
|
+
* [passwordless](https://github.com/mikker/passwordless)
|
235
|
+
* [magic-link](https://github.com/dvanderbeek/magic-link)
|
236
|
+
|
207
237
|
## License
|
208
238
|
|
209
239
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/devise-passwordless.gemspec
CHANGED
@@ -38,8 +38,4 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.required_ruby_version = ">= 2.1.0"
|
39
39
|
|
40
40
|
spec.add_dependency "devise"
|
41
|
-
|
42
|
-
spec.add_development_dependency "bundler", "~> 1.17"
|
43
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
44
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
45
41
|
end
|
@@ -60,10 +60,13 @@ module Devise::Passwordless
|
|
60
60
|
|
61
61
|
def update_devise_yaml
|
62
62
|
devise_yaml = "config/locales/devise.en.yml"
|
63
|
+
existing_config = {}
|
63
64
|
begin
|
64
|
-
|
65
|
+
in_root do
|
66
|
+
existing_config = YAML.load_file(devise_yaml)
|
67
|
+
end
|
65
68
|
rescue Errno::ENOENT
|
66
|
-
|
69
|
+
say_status :skip, devise_yaml, :yellow
|
67
70
|
return
|
68
71
|
end
|
69
72
|
default_config = {
|
@@ -84,9 +87,16 @@ module Devise::Passwordless
|
|
84
87
|
}
|
85
88
|
}
|
86
89
|
}
|
87
|
-
merged_config =
|
88
|
-
|
89
|
-
|
90
|
+
merged_config = existing_config.deep_merge(default_config.deep_stringify_keys)
|
91
|
+
if existing_config.to_yaml == merged_config.to_yaml
|
92
|
+
say_status :identical, devise_yaml, :blue
|
93
|
+
else
|
94
|
+
in_root do
|
95
|
+
File.open(devise_yaml, "w") do |f|
|
96
|
+
f.write(force_double_quote_yaml(merged_config.to_yaml))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
say_status :insert, devise_yaml, :green
|
90
100
|
end
|
91
101
|
end
|
92
102
|
|
@@ -17,7 +17,8 @@ class Devise::Passwordless::MagicLinksController < DeviseController
|
|
17
17
|
protected
|
18
18
|
|
19
19
|
def auth_options
|
20
|
-
|
20
|
+
mapping = Devise.mappings[resource_name]
|
21
|
+
{ scope: resource_name, recall: "#{mapping.controllers[:sessions]}#new" }
|
21
22
|
end
|
22
23
|
|
23
24
|
def translation_scope
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-passwordless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abe Voelker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -24,48 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.17'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.17'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
27
|
description:
|
70
28
|
email:
|
71
29
|
- _@abevoelker.com
|
@@ -113,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
71
|
- !ruby/object:Gem::Version
|
114
72
|
version: '0'
|
115
73
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.1.2
|
117
75
|
signing_key:
|
118
76
|
specification_version: 4
|
119
77
|
summary: Passwordless (email-only) login strategy for Devise
|