jwt-auth 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jwt/auth/token.rb +27 -15
  3. data/version.yml +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1f15acad1cbf01398773956c92432bcb1011ab1a41e37ef8829196260274b9d
4
- data.tar.gz: add25d8fdb4425010c9a8a48fdded669818420d1e923d44a8ed7189861bf7279
3
+ metadata.gz: 5f8c312085d293598d22b4f524932f282f68e39ade3ba31e315665420c278f78
4
+ data.tar.gz: e2211deaea7d353ed280c0f94df7f0035ffd773a1db7365c185bd6e72828b71a
5
5
  SHA512:
6
- metadata.gz: 9aaaf2d95f5a00989134c7e5be578e2078bbe8c7f2d50c4575a2fbe6acdd4b181629f0236aafe8a2a0faa20edc6b8a4b8b2e2619235fd529eb4066573b09ca62
7
- data.tar.gz: 7f37a1e60dc8f81f61fee5d20529c62119c4f22e78b88a36fc94a8ecceff8c7a23e0b6a97d1778d85e26717f5018ccb12a946557910434cb3e6771816c80383e
6
+ metadata.gz: 69a5de0fe797c6b77bbaad79cdfb4415efb1dd1d41920d292d4034f04b2ce243e212a7de181103f5098c38f5a174facf42e71e0bb8ab87773161cbfe940039b0
7
+ data.tar.gz: 664f79452ae146be44c8c4b8e47e753930c2b1408eece4426aa1e139c41cdc901bb52adb305b4fe39de3a6f4c8af1690622b63e3fea1768bb16dc827638be8fb
@@ -50,29 +50,41 @@ module JWT
50
50
 
51
51
  class << self
52
52
  def from_jwt(token)
53
- @decoded_payload = JWT.decode(token, JWT::Auth.secret).first
53
+ payload = JWT.decode(token, JWT::Auth.secret).first
54
54
 
55
- params = {
56
- :issued_at => @decoded_payload['iat'],
57
- :version => @decoded_payload['ver'],
58
- :subject => model.find_by_token(:id => @decoded_payload['sub'],
59
- :token_version => @decoded_payload['ver'])
55
+ token = token_for payload['typ']
56
+
57
+ token ? token.new(parse payload) : nil
58
+ rescue JWT::DecodeError
59
+ nil
60
+ end
61
+
62
+ protected
63
+
64
+ ##
65
+ # Parse raw JWT payload into params object used to initialize a token class
66
+ #
67
+ def parse(payload)
68
+ {
69
+ :issued_at => payload['iat'],
70
+ :version => payload['ver'],
71
+ :subject => model.find_by_token(:id => payload['sub'],
72
+ :token_version => payload['ver'])
60
73
  }
74
+ end
61
75
 
62
- case @decoded_payload['typ']
76
+ ##
77
+ # Determine token class based on type identifier
78
+ #
79
+ def token_for(type)
80
+ case type
63
81
  when 'access'
64
- return AccessToken.new params
82
+ AccessToken
65
83
  when 'refresh'
66
- return RefreshToken.new params
67
- else
68
- return nil
84
+ RefreshToken
69
85
  end
70
- rescue JWT::DecodeError
71
- nil
72
86
  end
73
87
 
74
- private
75
-
76
88
  def model
77
89
  const_get JWT::Auth.model
78
90
  end
@@ -1 +1 @@
1
- --- 5.0.0
1
+ --- 5.0.1
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: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt