signinable 2.0.13 → 2.0.16
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/lib/signinable/model_additions.rb +17 -9
- data/lib/signinable/version.rb +1 -1
- data/spec/dummy/log/test.log +2749 -0
- data/spec/models/user_spec.rb +20 -5
- data/spec/support/utilities.rb +2 -2
- 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: 98c939505c7a77333b6244200b4e2f1e6337cd00ab721773db89333910d4b0b4
|
4
|
+
data.tar.gz: 32917bd4f4f2671a9727f17c8b57b83f852fbd7b5c7259e6abe3f72b69669896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4728c3a79d4d85443e8d92a51a156409bb616a4be5782ad236ffe8c5006a8a60bd777655c38559dc390fffc2fc447aef0cedd08c2beeb4d142731e238337f326
|
7
|
+
data.tar.gz: 1f0ae333d9cd6d4b53338a50b0a16fd2ec592ff7f5dfc87d400958eeddf33a51b8f6386172ecb2754291d811925637ac548968373030bfee09005107499cc06e
|
@@ -16,7 +16,7 @@ module Signinable
|
|
16
16
|
cattr_reader :jwt_exp
|
17
17
|
|
18
18
|
def signinable(options = {})
|
19
|
-
self.refresh_exp = options.fetch(:
|
19
|
+
self.refresh_exp = options.fetch(:refresh_exp, DEFAULT_REFRESH_EXP)
|
20
20
|
self.simultaneous_signings = options.fetch(:simultaneous, true)
|
21
21
|
self.signin_restrictions = options[:restrictions]
|
22
22
|
self.jwt_secret = options.fetch(:jwt_secret)
|
@@ -31,7 +31,11 @@ module Signinable
|
|
31
31
|
jwt_payload = extract_jwt_payload(jwt)
|
32
32
|
return refresh_jwt(jwt, ip, user_agent, skip_restrictions: skip_restrictions) unless jwt_payload
|
33
33
|
|
34
|
-
find_by(primary_key => jwt_payload['signinable_id'])
|
34
|
+
signinable = find_by(primary_key => jwt_payload['signinable_id'])
|
35
|
+
return nil unless signinable
|
36
|
+
|
37
|
+
signinable.jwt = jwt
|
38
|
+
signinable
|
35
39
|
end
|
36
40
|
|
37
41
|
def check_signin_permission(signin, restrictions_to_check, skip_restrictions)
|
@@ -71,6 +75,12 @@ module Signinable
|
|
71
75
|
signin.signinable
|
72
76
|
end
|
73
77
|
|
78
|
+
def refresh_token_from_jwt(jwt)
|
79
|
+
JWT.decode(jwt, jwt_secret, true, { verify_expiration: false, algorithm: 'HS256' })[0]['refresh_token']
|
80
|
+
rescue JWT::DecodeError
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
74
84
|
private
|
75
85
|
|
76
86
|
cattr_writer :refresh_exp
|
@@ -85,12 +95,6 @@ module Signinable
|
|
85
95
|
nil
|
86
96
|
end
|
87
97
|
|
88
|
-
def refresh_token_from_jwt(jwt)
|
89
|
-
JWT.decode(jwt, jwt_secret, true, { verify_expiration: false, algorithm: 'HS256' })[0]['refresh_token']
|
90
|
-
rescue JWT::DecodeError
|
91
|
-
nil
|
92
|
-
end
|
93
|
-
|
94
98
|
def signin_permitted?(signin, restrictions_to_check, skip_restrictions)
|
95
99
|
restriction_fields = signin_restriction_fields(signin, skip_restrictions)
|
96
100
|
|
@@ -129,10 +133,14 @@ module Signinable
|
|
129
133
|
self.jwt = self.class.generate_jwt(signin.token, signin.signinable_id)
|
130
134
|
end
|
131
135
|
|
132
|
-
def signout(
|
136
|
+
def signout(jwt, ip, user_agent, skip_restrictions: [])
|
137
|
+
token = self.class.refresh_token_from_jwt(jwt)
|
138
|
+
return unless token
|
139
|
+
|
133
140
|
signin = Signin.find_by_token(token)
|
134
141
|
|
135
142
|
return unless signin
|
143
|
+
return if signin.expired?
|
136
144
|
return unless self.class.check_signin_permission(
|
137
145
|
signin,
|
138
146
|
{ ip: ip, user_agent: user_agent },
|
data/lib/signinable/version.rb
CHANGED