File tree 2 files changed +22
-2
lines changed
app/models/devise_token_auth/concerns
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -99,8 +99,8 @@ def token_is_current?(token, client_id)
99
99
self . tokens [ client_id ] [ 'expiry' ] and
100
100
self . tokens [ client_id ] [ 'token' ] and
101
101
102
- # ensure that the token was created within the last two weeks
103
- DateTime . strptime ( self . tokens [ client_id ] [ 'expiry' ] . to_s , '%s' ) > DeviseTokenAuth . token_lifespan . ago and
102
+ # ensure that the token has not yet expired
103
+ DateTime . strptime ( self . tokens [ client_id ] [ 'expiry' ] . to_s , '%s' ) > Time . now and
104
104
105
105
# ensure that the token is valid
106
106
BCrypt ::Password . new ( self . tokens [ client_id ] [ 'token' ] ) == token
Original file line number Diff line number Diff line change @@ -37,6 +37,26 @@ class UserTest < ActiveSupport::TestCase
37
37
end
38
38
end
39
39
40
+ describe 'token expiry' do
41
+ before do
42
+ @user = users ( :confirmed_email_user )
43
+ @user . skip_confirmation!
44
+ @user . save!
45
+
46
+ @auth_headers = @user . create_new_auth_token
47
+
48
+ @token = @auth_headers [ 'access-token' ]
49
+ @client_id = @auth_headers [ 'client' ]
50
+ end
51
+
52
+ test 'should properly indicate whether token is current' do
53
+ assert @user . token_is_current? ( @token , @client_id )
54
+ # we want to update the expiry without forcing a cleanup (see below)
55
+ @user . tokens [ @client_id ] [ 'expiry' ] = Time . now . to_i - 10 . seconds
56
+ refute @user . token_is_current? ( @token , @client_id )
57
+ end
58
+ end
59
+
40
60
describe 'expired tokens are destroyed on save' do
41
61
before do
42
62
@user = users ( :confirmed_email_user )
You can’t perform that action at this time.
0 commit comments