jwt-auth 2.1.0 → 2.1.1
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 +4 -4
- data/jwt-auth.gemspec +1 -0
- data/lib/jwt/auth/authentication.rb +6 -6
- data/lib/jwt/auth/version.rb +1 -1
- data/spec/configuration_spec.rb +5 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/dummy_user.rb +0 -2
- data/spec/token_spec.rb +0 -8
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42a50e3f1afb56c8a515e6e3db6c6dac43a9a252
|
4
|
+
data.tar.gz: 8e67ea27890271ccadf46286cad3db9bdccdaa4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69f38d3381bbc286f861b69ab1b4ed8b8bfcd2f774c8404be269cf503d1694d89ae946222d0f07978d8d379b46a60901ed6f5057a32b731f764c2dc8967f3e61
|
7
|
+
data.tar.gz: 30e3db0cd10b4f2d668013939a48d17fb4f8681016843d1621551323a4d880d79e9beed7cc1dd8dec32a58536ef202854be60cb1335f1d6b22c1eb0e53468a05
|
data/jwt-auth.gemspec
CHANGED
@@ -12,14 +12,14 @@ module JWT
|
|
12
12
|
# Current user helper
|
13
13
|
#
|
14
14
|
def current_user
|
15
|
-
|
15
|
+
jwt&.subject
|
16
16
|
end
|
17
17
|
|
18
18
|
##
|
19
19
|
# Authenticate a request
|
20
20
|
#
|
21
21
|
def authenticate_user
|
22
|
-
raise JWT::Auth::UnauthorizedError unless
|
22
|
+
raise JWT::Auth::UnauthorizedError unless jwt&.valid?
|
23
23
|
|
24
24
|
# Regenerate token (renews expiration date)
|
25
25
|
add_token_to_response
|
@@ -29,9 +29,9 @@ module JWT
|
|
29
29
|
# Add JWT header to response
|
30
30
|
#
|
31
31
|
def add_token_to_response
|
32
|
-
return unless
|
33
|
-
|
34
|
-
response.headers['Authorization'] = "Bearer #{
|
32
|
+
return unless jwt&.valid?
|
33
|
+
jwt.renew!
|
34
|
+
response.headers['Authorization'] = "Bearer #{jwt.to_jwt}"
|
35
35
|
end
|
36
36
|
|
37
37
|
protected
|
@@ -39,7 +39,7 @@ module JWT
|
|
39
39
|
##
|
40
40
|
# Extract JWT from request
|
41
41
|
#
|
42
|
-
def
|
42
|
+
def jwt
|
43
43
|
return @token if @token
|
44
44
|
|
45
45
|
header = request.env['HTTP_AUTHORIZATION']
|
data/lib/jwt/auth/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
require 'rails_helper'
|
4
6
|
|
5
7
|
RSpec.describe JWT::Auth do
|
6
8
|
it 'configures correctly' do
|
7
9
|
JWT::Auth.configure do |config|
|
8
|
-
config.token_lifetime =
|
10
|
+
config.token_lifetime = 24.hours
|
9
11
|
config.secret = 'mysecret'
|
10
12
|
end
|
11
13
|
|
12
|
-
expect(subject.token_lifetime).to eq
|
14
|
+
expect(subject.token_lifetime).to eq 24.hours
|
13
15
|
expect(subject.secret).to eq 'mysecret'
|
14
16
|
expect(subject.model).to eq DummyUser
|
15
17
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/dummy_user.rb
CHANGED
data/spec/token_spec.rb
CHANGED
@@ -3,14 +3,6 @@
|
|
3
3
|
require 'support/dummy_user'
|
4
4
|
|
5
5
|
RSpec.describe JWT::Auth::Token do
|
6
|
-
before :each do
|
7
|
-
JWT::Auth.configure do |config|
|
8
|
-
config.token_lifetime = 24.hours
|
9
|
-
|
10
|
-
config.secret = 'mysecret'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
let(:user) { DummyUser.new }
|
15
7
|
|
16
8
|
describe 'properties' 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: 2.1.
|
4
|
+
version: 2.1.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: 2017-04-
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.5'
|
97
111
|
description: Authentication middleware for Rails API that uses JWTs, without depending
|
98
112
|
on Devise
|
99
113
|
email:
|