jwt-auth 3.1.1 → 4.0.0

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
- SHA1:
3
- metadata.gz: 859222f960cc7aa8d3dac73c42196f6a2614ce7e
4
- data.tar.gz: e3945d68b8f1ccb52adec74c65831ad8f2037d50
2
+ SHA256:
3
+ metadata.gz: 3c956f873db709997837bf27371d2dc5f6315d072004be257a99a554f59ad67e
4
+ data.tar.gz: f8066ab1085f05a481d59f937c279e3a8d88a572761d36b76daed80db72b512f
5
5
  SHA512:
6
- metadata.gz: b46274a784cb489f73d6c7d942afe4415fff5f0d2cae577cc1d1c98db5910abfcb6b79f081f80bb1c2efb714bc127f108df7eb549f7b6bfaacb06b11f87b80fe
7
- data.tar.gz: 8f946e01493e82a624e1b9c071c06fb3e5b3afbc374e574a1a9c45926928de2071d59c1457d96dddaa4009a3c10c2ded743856461c2b6290faa772db60e7d73a
6
+ metadata.gz: ae88929951aaae1affd6bb29b9c6ef8392ae582ecd81b2a59bd02777798d1d2830ab266f9900d3b9b4374b61d4be18e7f1b22dffc61e046fb99cba7cba2e8043
7
+ data.tar.gz: 3b93f3b8b80cffc983a2baed9b3bbc296736bb1faacf0823ad78ce608e21d34faf2dfcdf5271068e0bbec1f4ca543bd31ec96dbb96327875ff24bedb24f8e4d3
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/numeric/time'
3
+ # require 'active_support/core_ext/numeric/time'
4
4
 
5
5
  require 'jwt/auth/configuration'
6
6
 
@@ -10,14 +10,14 @@ module JWT
10
10
  # In-memory representation of JWT
11
11
  #
12
12
  class Token
13
- attr_accessor :expiration, :subject, :token_version
13
+ attr_accessor :issued_at, :subject, :token_version
14
14
 
15
15
  def valid?
16
16
  # Reload subject to prevent caching the old token_version
17
17
  subject && subject.reload
18
18
 
19
- return false if subject.nil? || expiration.nil? || token_version.nil?
20
- return false if Time.at(expiration).past?
19
+ return false if subject.nil? || issued_at.nil? || token_version.nil?
20
+ return false if Time.at(issued_at + lifetime.to_i).past?
21
21
  return false if token_version != subject.token_version
22
22
 
23
23
  true
@@ -26,7 +26,7 @@ module JWT
26
26
  end
27
27
 
28
28
  def renew!
29
- self.expiration = nil
29
+ self.issued_at = nil
30
30
  self.token_version = nil
31
31
  end
32
32
 
@@ -43,7 +43,7 @@ module JWT
43
43
 
44
44
  def payload
45
45
  {
46
- :exp => expiration || lifetime.from_now.to_i,
46
+ :iat => issued_at || Time.now.to_i,
47
47
  :sub => subject.id,
48
48
  :ver => token_version || subject.token_version
49
49
  }
@@ -56,12 +56,12 @@ module JWT
56
56
  def self.from_token(token)
57
57
  begin
58
58
  @decoded_payload = JWT.decode(token, JWT::Auth.secret).first
59
- rescue JWT::ExpiredSignature, JWT::DecodeError
59
+ rescue JWT::DecodeError
60
60
  @decoded_payload = {}
61
61
  end
62
62
 
63
63
  token = self.new
64
- token.expiration = @decoded_payload['exp']
64
+ token.issued_at = @decoded_payload['iat']
65
65
  token.token_version = @decoded_payload['ver']
66
66
 
67
67
  if @decoded_payload['sub']
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JWT
4
4
  module Auth
5
- VERSION = '3.1.1'
5
+ VERSION = '4.0.0'
6
6
  end
7
7
  end
@@ -7,9 +7,9 @@ RSpec.describe JWT::Auth::Token do
7
7
  describe 'properties' do
8
8
  let(:token) { JWT::Auth::Token.from_user user }
9
9
 
10
- it 'has an expiration' do
11
- expect(token).to respond_to :expiration
12
- expect(token.expiration).to be_nil
10
+ it 'has an issued at' do
11
+ expect(token).to respond_to :issued_at
12
+ expect(token.issued_at).to be_nil
13
13
  end
14
14
 
15
15
  it 'has a subject' do
@@ -54,7 +54,7 @@ RSpec.describe JWT::Auth::Token do
54
54
  end
55
55
 
56
56
  it 'is invalid on past date' do
57
- token.expiration = 1.second.ago.to_i
57
+ token.issued_at = (JWT::Auth.token_lifetime + 1.second).ago.to_i
58
58
 
59
59
  t = JWT::Auth::Token.from_token token.to_jwt
60
60
 
@@ -62,7 +62,7 @@ RSpec.describe JWT::Auth::Token do
62
62
  end
63
63
 
64
64
  it 'is invalid after expiry date' do
65
- token.expiration = Time.now.to_i
65
+ token.issued_at = JWT::Auth.token_lifetime.ago.to_i
66
66
  sleep 2
67
67
 
68
68
  t = JWT::Auth::Token.from_token token.to_jwt
@@ -87,14 +87,16 @@ RSpec.describe JWT::Auth::Token do
87
87
 
88
88
  expect(new_token).to be_valid
89
89
  expect(new_jwt).not_to eq old_jwt
90
- expect(new_token.expiration).not_to eq old_token.expiration
90
+ expect(new_token.issued_at).not_to eq old_token.issued_at
91
91
  end
92
92
  end
93
93
 
94
94
  describe 'from token' do
95
+ let(:issued_at) { 1.second.ago.to_i }
96
+
95
97
  let(:jwt) do
96
98
  payload = {
97
- :exp => JWT::Auth.token_lifetime.from_now.to_i,
99
+ :iat => issued_at,
98
100
  :sub => user.id,
99
101
  :ver => user.token_version
100
102
  }
@@ -103,8 +105,8 @@ RSpec.describe JWT::Auth::Token do
103
105
 
104
106
  let(:token) { JWT::Auth::Token.from_token jwt }
105
107
 
106
- it 'matches expiration' do
107
- expect(token.expiration).to eq JWT::Auth.token_lifetime.from_now.to_i
108
+ it 'matches issued at' do
109
+ expect(token.issued_at).to eq issued_at
108
110
  end
109
111
 
110
112
  it 'matches subject' do
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.1.1
4
+ version: 4.0.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-31 00:00:00.000000000 Z
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -279,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  version: '0'
280
280
  requirements: []
281
281
  rubyforge_project:
282
- rubygems_version: 2.6.12
282
+ rubygems_version: 2.7.3
283
283
  signing_key:
284
284
  specification_version: 4
285
285
  summary: JWT-based authentication for Rails API