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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cd012fc046f4777af5d9ee5f6265f5ca2d62af9
4
- data.tar.gz: 9170ff259b31aa1867b40da3572db62b4b1af852
3
+ metadata.gz: 0b11dc2531ed00ed8ead4181d0a3a50aa498039c
4
+ data.tar.gz: 1d2ee0029f04f2612f6ef857a0e853c38b12db13
5
5
  SHA512:
6
- metadata.gz: cee44e1a66ed06d4ecb6298542b45b13c72a2806c271805c2e8772dcab5b755ad4f9cf9c862c8f507a511744fa52c28e600c458b48ef50b555ca6ae1e946afb1
7
- data.tar.gz: b34a80b8d6bb0f0cf068b4505101edbc9030f96bcccf3bd5b5bcb5ffe55b7e7fd77726177dbb2ac68b3fe1981edf2c68ecdd5a04a54d7b2ff2d2ab9dbb4c8eda
6
+ metadata.gz: df54f9949ad17b040fffd7ee642a6e206c61587fcde549a78849ebc013e346d311be7a7da8801eae724acf452b6607c89785ac423a332726fb6d6512487dd3e6
7
+ data.tar.gz: 25e85ed1f67349905b5228182a0ba2d2fde4ca122cba7f86b367bbf19ddac5e4e06b242234ba8a32920306c852ea2ba56053b0cb245fb1d1dfc9694334514d70
@@ -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 = JWT::Auth::Token.new
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
- payload = JWT.decode(token, JWT::Auth.secret).first
58
+ @decoded_payload = JWT.decode(token, JWT::Auth.secret).first
52
59
  rescue JWT::ExpiredSignature
53
- payload = {}
60
+ @decoded_payload = {}
54
61
  end
55
62
 
56
- token = JWT::Auth::Token.new
57
- token.expiration = payload['exp']
58
- token.token_version = payload['ver']
63
+ token = self.new
64
+ token.expiration = @decoded_payload['exp']
65
+ token.token_version = @decoded_payload['ver']
59
66
 
60
- if payload['sub']
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 => payload['sub'], :token_version => payload['ver']
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JWT
4
4
  module Auth
5
- VERSION = '3.0.1'
5
+ VERSION = '3.1.0'
6
6
  end
7
7
  end
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.1
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-26 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt