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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e090b91cbbcbbfe860ca07984e3a19a965cc96bf2909f4e469e5d0ed48794dbe
4
- data.tar.gz: c84bacb35618b62991ab60c984ec8f8c9786d783c3dd3dc8dc6a9ea76ed4881e
3
+ metadata.gz: 98c939505c7a77333b6244200b4e2f1e6337cd00ab721773db89333910d4b0b4
4
+ data.tar.gz: 32917bd4f4f2671a9727f17c8b57b83f852fbd7b5c7259e6abe3f72b69669896
5
5
  SHA512:
6
- metadata.gz: 3e96a9511dd6560c05ddfdc03b94d71ea83720e982526412a59a8e4a0461d475a4fb970ceb680636f23f144cb2273a811a0014897bf77597eeff7c7652d7e962
7
- data.tar.gz: 2dcc381256505cebdeb990ac0340200c3134c8e1337f1bbe41082e233d35187ecdc4e30aebf71d316ea99da7de861649415514d9043eaf958df59b630c38d439
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(:expiration, DEFAULT_REFRESH_EXP)
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(token, ip, user_agent, skip_restrictions: [])
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 },
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Signinable
4
- VERSION = '2.0.13'
4
+ VERSION = '2.0.16'
5
5
  end