jwt-auth 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jwt/auth/token.rb +20 -13
- data/lib/jwt/auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b11dc2531ed00ed8ead4181d0a3a50aa498039c
|
4
|
+
data.tar.gz: 1d2ee0029f04f2612f6ef857a0e853c38b12db13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df54f9949ad17b040fffd7ee642a6e206c61587fcde549a78849ebc013e346d311be7a7da8801eae724acf452b6607c89785ac423a332726fb6d6512487dd3e6
|
7
|
+
data.tar.gz: 25e85ed1f67349905b5228182a0ba2d2fde4ca122cba7f86b367bbf19ddac5e4e06b242234ba8a32920306c852ea2ba56053b0cb245fb1d1dfc9694334514d70
|
data/lib/jwt/auth/token.rb
CHANGED
@@ -31,35 +31,42 @@ module JWT
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_jwt
|
34
|
-
payload = {
|
35
|
-
:exp => expiration || JWT::Auth.token_lifetime.from_now.to_i,
|
36
|
-
:sub => subject.id,
|
37
|
-
:ver => token_version || subject.token_version
|
38
|
-
}
|
39
34
|
JWT.encode payload, JWT::Auth.secret
|
40
35
|
end
|
41
36
|
|
42
37
|
def self.from_user(subject)
|
43
|
-
token =
|
38
|
+
token = self.new
|
44
39
|
token.subject = subject
|
45
40
|
|
46
41
|
token
|
47
42
|
end
|
48
43
|
|
44
|
+
def payload
|
45
|
+
{
|
46
|
+
:exp => expiration || lifetime.from_now.to_i,
|
47
|
+
:sub => subject.id,
|
48
|
+
:ver => token_version || subject.token_version
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def lifetime
|
53
|
+
JWT::Auth.token_lifetime
|
54
|
+
end
|
55
|
+
|
49
56
|
def self.from_token(token)
|
50
57
|
begin
|
51
|
-
|
58
|
+
@decoded_payload = JWT.decode(token, JWT::Auth.secret).first
|
52
59
|
rescue JWT::ExpiredSignature
|
53
|
-
|
60
|
+
@decoded_payload = {}
|
54
61
|
end
|
55
62
|
|
56
|
-
token =
|
57
|
-
token.expiration =
|
58
|
-
token.token_version =
|
63
|
+
token = self.new
|
64
|
+
token.expiration = @decoded_payload['exp']
|
65
|
+
token.token_version = @decoded_payload['ver']
|
59
66
|
|
60
|
-
if
|
67
|
+
if @decoded_payload['sub']
|
61
68
|
find_method = JWT::Auth.model.respond_to?(:find_by_token) ? :find_by_token : :find_by
|
62
|
-
token.subject = JWT::Auth.model.send find_method, :id =>
|
69
|
+
token.subject = JWT::Auth.model.send find_method, :id => @decoded_payload['sub'], :token_version => @decoded_payload['ver']
|
63
70
|
end
|
64
71
|
|
65
72
|
token
|
data/lib/jwt/auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jwt-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dejonckheere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|