signinable 2.0.14 → 2.0.17
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/db/migrate/20220814152804_change_signinable_id_to_string.rb +12 -0
- data/lib/signinable/model_additions.rb +12 -8
- data/lib/signinable/version.rb +1 -1
- data/spec/dummy/log/test.log +2350 -0
- data/spec/models/user_spec.rb +11 -5
- data/spec/support/utilities.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 523362dea01356b6cbdaf4b31dfcd466d4a27d45d968e754fa2d553794e1afd2
|
4
|
+
data.tar.gz: d129d2e715ee9376fd6aa4de5904ffbb617518c46136d2d4801bb01b034a2fd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d53f8b61728737d073ee40251b0fda57275032df9bfd8a32a9e79c69702551955d781d9fcb16b49a617de244137beb6efa776a357f09c127a67a1da033ccd5c
|
7
|
+
data.tar.gz: ea5ded123711f4be9d5587f2177bbe3dd48b8c1a3be4665a6e8fe37aff4c33576b0235dbf1cb64e7b3ab4509c62f63c1402fe003ccfd98f2b16fdd1210511a58
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
migration_kls = Rails::VERSION::MAJOR > 4 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
|
4
|
+
class ChangeSigninableIdToString < migration_kls
|
5
|
+
def self.up
|
6
|
+
change_column :signins, :signinable_id, :string, null: false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
change_column :signins, :signinable_id, :integer, null: false
|
11
|
+
end
|
12
|
+
end
|
@@ -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)
|
@@ -75,6 +75,12 @@ module Signinable
|
|
75
75
|
signin.signinable
|
76
76
|
end
|
77
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
|
+
|
78
84
|
private
|
79
85
|
|
80
86
|
cattr_writer :refresh_exp
|
@@ -89,12 +95,6 @@ module Signinable
|
|
89
95
|
nil
|
90
96
|
end
|
91
97
|
|
92
|
-
def refresh_token_from_jwt(jwt)
|
93
|
-
JWT.decode(jwt, jwt_secret, true, { verify_expiration: false, algorithm: 'HS256' })[0]['refresh_token']
|
94
|
-
rescue JWT::DecodeError
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
|
98
98
|
def signin_permitted?(signin, restrictions_to_check, skip_restrictions)
|
99
99
|
restriction_fields = signin_restriction_fields(signin, skip_restrictions)
|
100
100
|
|
@@ -133,10 +133,14 @@ module Signinable
|
|
133
133
|
self.jwt = self.class.generate_jwt(signin.token, signin.signinable_id)
|
134
134
|
end
|
135
135
|
|
136
|
-
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
|
+
|
137
140
|
signin = Signin.find_by_token(token)
|
138
141
|
|
139
142
|
return unless signin
|
143
|
+
return if signin.expired?
|
140
144
|
return unless self.class.check_signin_permission(
|
141
145
|
signin,
|
142
146
|
{ ip: ip, user_agent: user_agent },
|
data/lib/signinable/version.rb
CHANGED