passwordless 1.0.1 → 1.1.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/README.md +1 -1
- data/app/controllers/passwordless/sessions_controller.rb +11 -10
- data/app/mailers/passwordless/mailer.rb +10 -1
- data/app/models/passwordless/session.rb +5 -0
- data/config/locales/en.yml +2 -0
- data/db/migrate/20171104221735_create_passwordless_sessions.rb +1 -0
- data/lib/passwordless/router_helpers.rb +4 -2
- data/lib/passwordless/test_helpers.rb +43 -12
- data/lib/passwordless/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d3bfd49106dd713d65f26a575911bdcb1a903a62273d741f08f1c0b36ea9a77
|
4
|
+
data.tar.gz: 239fdcce54d30e39f39bb6eb2d7ffdd6c2f2f50e04fe38ec7f53bca000b449d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7afa9aed4245ed2a3ab13bd7624ec8561d8c0e47db9435a1e415442f6c1d4e6e1770cd9d799095888a189a0485fc9bd5d3fa22e9e3145f2e351e8deee04277b
|
7
|
+
data.tar.gz: 5f4d8142044cdaff3f9746bad1d184d587b293241ab4f2d0344924fc452cb65590f91840b0db698d535588098cb72098c67f09c2243530177e45f395ab1466a9
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ module Passwordless
|
|
37
37
|
end
|
38
38
|
|
39
39
|
redirect_to(
|
40
|
-
url_for(id: @session.
|
40
|
+
url_for(id: @session.identifier, action: "show"),
|
41
41
|
flash: {notice: I18n.t("passwordless.sessions.create.email_sent")}
|
42
42
|
)
|
43
43
|
else
|
@@ -54,7 +54,7 @@ module Passwordless
|
|
54
54
|
# Shows the form for confirming a Session record.
|
55
55
|
# renders sessions/show.html.erb.
|
56
56
|
def show
|
57
|
-
@session =
|
57
|
+
@session = passwordless_session
|
58
58
|
end
|
59
59
|
|
60
60
|
# patch "/:resource/sign_in/:id"
|
@@ -66,7 +66,7 @@ module Passwordless
|
|
66
66
|
# @see ControllerHelpers#sign_in
|
67
67
|
# @see ControllerHelpers#save_passwordless_redirect_location!
|
68
68
|
def update
|
69
|
-
@session =
|
69
|
+
@session = passwordless_session
|
70
70
|
|
71
71
|
artificially_slow_down_brute_force_attacks(passwordless_session_params[:token])
|
72
72
|
|
@@ -86,7 +86,7 @@ module Passwordless
|
|
86
86
|
# safe. We don't want to sign in the user in that case.
|
87
87
|
return head(:ok) if request.head?
|
88
88
|
|
89
|
-
@session =
|
89
|
+
@session = passwordless_session
|
90
90
|
|
91
91
|
artificially_slow_down_brute_force_attacks(params[:token])
|
92
92
|
|
@@ -98,7 +98,12 @@ module Passwordless
|
|
98
98
|
# @see ControllerHelpers#sign_out
|
99
99
|
def destroy
|
100
100
|
sign_out(authenticatable_class)
|
101
|
-
|
101
|
+
|
102
|
+
redirect_to(
|
103
|
+
passwordless_sign_out_redirect_path,
|
104
|
+
notice: I18n.t("passwordless.sessions.destroy.signed_out"),
|
105
|
+
**redirect_to_options
|
106
|
+
)
|
102
107
|
end
|
103
108
|
|
104
109
|
protected
|
@@ -161,10 +166,6 @@ module Passwordless
|
|
161
166
|
authenticatable_type.constantize
|
162
167
|
end
|
163
168
|
|
164
|
-
def find_session
|
165
|
-
Session.find_by!(id: params[:id], authenticatable_type: authenticatable_type)
|
166
|
-
end
|
167
|
-
|
168
169
|
def find_authenticatable
|
169
170
|
email = passwordless_session_params[email_field].downcase.strip
|
170
171
|
|
@@ -196,7 +197,7 @@ module Passwordless
|
|
196
197
|
|
197
198
|
def passwordless_session
|
198
199
|
@passwordless_session ||= Session.find_by!(
|
199
|
-
|
200
|
+
identifier: params[:id],
|
200
201
|
authenticatable_type: authenticatable_type
|
201
202
|
)
|
202
203
|
end
|
@@ -12,7 +12,16 @@ module Passwordless
|
|
12
12
|
# is still in memory (optional)
|
13
13
|
def sign_in(session, token = nil)
|
14
14
|
@token = token || session.token
|
15
|
-
@magic_link =
|
15
|
+
@magic_link = url_for(
|
16
|
+
{
|
17
|
+
controller: "passwordless/sessions",
|
18
|
+
action: "confirm",
|
19
|
+
id: session.identifier,
|
20
|
+
token: token,
|
21
|
+
authenticatable: "user",
|
22
|
+
resource: "users"
|
23
|
+
}
|
24
|
+
)
|
16
25
|
email_field = session.authenticatable.class.passwordless_email_field
|
17
26
|
|
18
27
|
mail(
|
@@ -61,6 +61,10 @@ module Passwordless
|
|
61
61
|
!expired?
|
62
62
|
end
|
63
63
|
|
64
|
+
def to_param
|
65
|
+
identifier
|
66
|
+
end
|
67
|
+
|
64
68
|
private
|
65
69
|
|
66
70
|
def token_digest_available?(token_digest)
|
@@ -68,6 +72,7 @@ module Passwordless
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def set_defaults
|
75
|
+
self.identifier = SecureRandom.uuid
|
71
76
|
self.expires_at ||= Passwordless.config.expires_at.call
|
72
77
|
self.timeout_at ||= Passwordless.config.timeout_at.call
|
73
78
|
|
data/config/locales/en.yml
CHANGED
@@ -17,6 +17,8 @@ en:
|
|
17
17
|
invalid_token: "Token is invalid"
|
18
18
|
session_expired: "Your session has expired, please sign in again."
|
19
19
|
token_claimed: "This link has already been used, try requesting the link again"
|
20
|
+
destroy:
|
21
|
+
signed_out: "Signed out successfully"
|
20
22
|
mailer:
|
21
23
|
sign_in:
|
22
24
|
subject: "Signing in ✨"
|
@@ -13,6 +13,7 @@ class CreatePasswordlessSessions < ActiveRecord::Migration[5.1]
|
|
13
13
|
t.datetime(:expires_at, null: false)
|
14
14
|
t.datetime(:claimed_at)
|
15
15
|
t.string(:token_digest, null: false)
|
16
|
+
t.string(:identifier, null: false, index: {unique: true}, length: 36)
|
16
17
|
|
17
18
|
t.timestamps
|
18
19
|
end
|
@@ -23,14 +23,16 @@ module Passwordless
|
|
23
23
|
# (Default: 'passwordless/sessions')
|
24
24
|
def passwordless_for(resource, at: :na, as: :na, controller: "passwordless/sessions")
|
25
25
|
at == :na && at = "/#{resource.to_s}"
|
26
|
-
as == :na && as =
|
26
|
+
as == :na && as = resource.to_s
|
27
|
+
|
28
|
+
as = as.to_s + "_" unless !as || as.to_s.end_with?("_")
|
27
29
|
|
28
30
|
plural = resource.to_s
|
29
31
|
singular = plural.singularize
|
30
32
|
|
31
33
|
defaults = {
|
32
34
|
authenticatable: singular,
|
33
|
-
resource: resource
|
35
|
+
resource: resource
|
34
36
|
}
|
35
37
|
|
36
38
|
scope(defaults: defaults) do
|
@@ -1,17 +1,32 @@
|
|
1
1
|
module Passwordless
|
2
2
|
module TestHelpers
|
3
3
|
module TestCase
|
4
|
-
def passwordless_sign_out
|
5
|
-
|
4
|
+
def passwordless_sign_out(cls = nil)
|
5
|
+
cls ||= "User".constantize
|
6
|
+
dest = url_for(
|
7
|
+
{
|
8
|
+
controller: "passwordless/sessions",
|
9
|
+
action: "destroy",
|
10
|
+
authenticatable: cls.model_name.singular,
|
11
|
+
resource: cls.model_name.to_s.tableize
|
12
|
+
}
|
13
|
+
)
|
14
|
+
delete(dest)
|
6
15
|
follow_redirect!
|
7
16
|
end
|
8
17
|
|
9
18
|
def passwordless_sign_in(resource)
|
19
|
+
cls = resource.class
|
10
20
|
session = Passwordless::Session.create!(authenticatable: resource)
|
11
|
-
magic_link =
|
12
|
-
|
13
|
-
|
14
|
-
|
21
|
+
magic_link = url_for(
|
22
|
+
{
|
23
|
+
controller: "passwordless/sessions",
|
24
|
+
action: "confirm",
|
25
|
+
id: session.id,
|
26
|
+
token: session.token,
|
27
|
+
authenticatable: cls.model_name.singular,
|
28
|
+
resource: cls.model_name.to_s.tableize
|
29
|
+
}
|
15
30
|
)
|
16
31
|
get(magic_link)
|
17
32
|
follow_redirect!
|
@@ -19,16 +34,32 @@ module Passwordless
|
|
19
34
|
end
|
20
35
|
|
21
36
|
module SystemTestCase
|
22
|
-
def passwordless_sign_out
|
23
|
-
|
37
|
+
def passwordless_sign_out(cls = nil)
|
38
|
+
cls ||= "User".constantize
|
39
|
+
visit(
|
40
|
+
url_for(
|
41
|
+
{
|
42
|
+
controller: "passwordless/sessions",
|
43
|
+
action: "destroy",
|
44
|
+
authenticatable: cls.model_name.singular,
|
45
|
+
resource: cls.model_name.to_s.tableize
|
46
|
+
}
|
47
|
+
)
|
48
|
+
)
|
24
49
|
end
|
25
50
|
|
26
51
|
def passwordless_sign_in(resource)
|
52
|
+
cls = resource.class
|
27
53
|
session = Passwordless::Session.create!(authenticatable: resource)
|
28
|
-
magic_link =
|
29
|
-
|
30
|
-
|
31
|
-
|
54
|
+
magic_link = url_for(
|
55
|
+
{
|
56
|
+
controller: "passwordless/sessions",
|
57
|
+
action: "confirm",
|
58
|
+
id: session.id,
|
59
|
+
token: session.token,
|
60
|
+
authenticatable: cls.model_name.singular,
|
61
|
+
resource: cls.model_name.to_s.tableize
|
62
|
+
}
|
32
63
|
)
|
33
64
|
visit(magic_link)
|
34
65
|
end
|
data/lib/passwordless/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passwordless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|