jwt-auth 3.1.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/jwt/auth/token.rb +8 -8
- data/lib/jwt/auth/version.rb +1 -1
- data/spec/token_spec.rb +11 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c956f873db709997837bf27371d2dc5f6315d072004be257a99a554f59ad67e
|
4
|
+
data.tar.gz: f8066ab1085f05a481d59f937c279e3a8d88a572761d36b76daed80db72b512f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae88929951aaae1affd6bb29b9c6ef8392ae582ecd81b2a59bd02777798d1d2830ab266f9900d3b9b4374b61d4be18e7f1b22dffc61e046fb99cba7cba2e8043
|
7
|
+
data.tar.gz: 3b93f3b8b80cffc983a2baed9b3bbc296736bb1faacf0823ad78ce608e21d34faf2dfcdf5271068e0bbec1f4ca543bd31ec96dbb96327875ff24bedb24f8e4d3
|
data/lib/jwt/auth/token.rb
CHANGED
@@ -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 :
|
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? ||
|
20
|
-
return false if Time.at(
|
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.
|
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
|
-
:
|
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::
|
59
|
+
rescue JWT::DecodeError
|
60
60
|
@decoded_payload = {}
|
61
61
|
end
|
62
62
|
|
63
63
|
token = self.new
|
64
|
-
token.
|
64
|
+
token.issued_at = @decoded_payload['iat']
|
65
65
|
token.token_version = @decoded_payload['ver']
|
66
66
|
|
67
67
|
if @decoded_payload['sub']
|
data/lib/jwt/auth/version.rb
CHANGED
data/spec/token_spec.rb
CHANGED
@@ -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
|
11
|
-
expect(token).to respond_to :
|
12
|
-
expect(token.
|
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.
|
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.
|
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.
|
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
|
-
:
|
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
|
107
|
-
expect(token.
|
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:
|
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:
|
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.
|
282
|
+
rubygems_version: 2.7.3
|
283
283
|
signing_key:
|
284
284
|
specification_version: 4
|
285
285
|
summary: JWT-based authentication for Rails API
|