jwt_keeper 2.0.0 → 3.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 +4 -4
- data/.rubocop.yml +2 -2
- data/.travis.yml +4 -3
- data/README.md +6 -4
- data/Rakefile +3 -1
- data/example/.gitignore +15 -0
- data/example/Gemfile +15 -0
- data/example/Rakefile +6 -0
- data/example/app/controllers/application_controller.rb +27 -0
- data/example/app/controllers/sessions_controller.rb +52 -0
- data/example/bin/bundle +3 -0
- data/example/bin/rails +9 -0
- data/example/bin/rake +9 -0
- data/example/bin/setup +29 -0
- data/example/bin/spring +15 -0
- data/example/config/application.rb +32 -0
- data/example/config/boot.rb +3 -0
- data/example/config/environment.rb +5 -0
- data/example/config/environments/development.rb +24 -0
- data/example/config/environments/production.rb +63 -0
- data/example/config/environments/test.rb +42 -0
- data/example/config/initializers/backtrace_silencer.rb +1 -0
- data/example/config/initializers/cookies_serializer.rb +3 -0
- data/example/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/config/initializers/jwt_keeper.rb +11 -0
- data/example/config/initializers/session_store.rb +3 -0
- data/example/config/initializers/wrap_parameters.rb +9 -0
- data/example/config/locales/en.yml +23 -0
- data/example/config/routes.rb +3 -0
- data/example/config/secrets.yml +22 -0
- data/example/config.ru +4 -0
- data/example/example.env +1 -0
- data/example/log/.keep +0 -0
- data/lib/generators/{keeper → jwt_keeper}/install/install_generator.rb +1 -1
- data/lib/generators/templates/jwt_keeper.rb +13 -2
- data/lib/jwt_keeper/configuration.rb +13 -1
- data/lib/jwt_keeper/controller.rb +52 -49
- data/lib/jwt_keeper/engine.rb +1 -1
- data/lib/jwt_keeper/token.rb +27 -12
- data/lib/jwt_keeper/version.rb +1 -1
- data/spec/lib/{keeper → jwt_keeper}/configuration_spec.rb +0 -0
- data/spec/lib/{keeper → jwt_keeper}/controller_spec.rb +38 -50
- data/spec/lib/{keeper → jwt_keeper}/datastore_spec.rb +0 -0
- data/spec/lib/{keeper → jwt_keeper}/token_spec.rb +35 -4
- data/spec/lib/jwt_keeper_spec.rb +29 -0
- data/spec/spec_helper.rb +5 -3
- metadata +41 -13
- data/spec/lib/keeper_spec.rb +0 -38
@@ -1,66 +1,69 @@
|
|
1
1
|
module JWTKeeper
|
2
2
|
module Controller
|
3
|
-
|
4
|
-
klass.class_eval do
|
5
|
-
include InstanceMethods
|
6
|
-
end
|
7
|
-
end
|
3
|
+
extend ActiveSupport::Concern
|
8
4
|
|
9
|
-
module
|
10
|
-
|
11
|
-
# the main logical section for decoding, and automatically rotating tokens
|
12
|
-
def require_authentication
|
13
|
-
token = authentication_token
|
14
|
-
return not_authenticated if token.nil?
|
5
|
+
module ClassMethods
|
6
|
+
end
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
8
|
+
# Available to be used as a before_action by the application's controllers. This is
|
9
|
+
# the main logical section for decoding, and automatically rotating tokens
|
10
|
+
def require_authentication
|
11
|
+
token = read_authentication_token
|
21
12
|
|
22
|
-
|
13
|
+
if token.nil?
|
14
|
+
clear_authentication_token
|
15
|
+
return not_authenticated
|
23
16
|
end
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def regenerate_claims(old_token)
|
18
|
+
if token.version_mismatch? || token.pending?
|
19
|
+
new_claims = regenerate_claims(token)
|
20
|
+
token.rotate(new_claims)
|
29
21
|
end
|
30
22
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
23
|
+
write_authentication_token(token)
|
24
|
+
authenticated(token)
|
25
|
+
end
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
# Decodes and returns the token
|
28
|
+
def read_authentication_token
|
29
|
+
return nil unless request.headers['Authorization']
|
30
|
+
@authentication_token ||=
|
31
|
+
JWTKeeper::Token.find(
|
32
|
+
request.headers['Authorization'].split.last,
|
33
|
+
cookies.signed['jwt_keeper']
|
34
|
+
)
|
35
|
+
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
# Encodes and writes the token
|
38
|
+
def write_authentication_token(token)
|
39
|
+
return clear_authentication_token if token.nil?
|
40
|
+
response.headers['Authorization'] = "Bearer #{token.to_jwt}"
|
41
|
+
cookies.signed['jwt_keeper'] = token.to_cookie
|
42
|
+
@authentication_token = token
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
# delets the authentication token
|
46
|
+
def clear_authentication_token
|
47
|
+
response.headers['Authorization'] = nil
|
48
|
+
cookies.delete('jwt_keeper')
|
49
|
+
@authentication_token = nil
|
50
|
+
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
# The default action for denying non-authenticated connections.
|
53
|
+
# You can override this method in your controllers
|
54
|
+
def not_authenticated
|
55
|
+
redirect_to root_path
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
# The default action for accepting authenticated connections.
|
59
|
+
# You can override this method in your controllers
|
60
|
+
def authenticated(token)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Invoked by the require_authentication method as part of the automatic rotation
|
64
|
+
# process. The application should override this method to include the necessary
|
65
|
+
# claims.
|
66
|
+
def regenerate_claims(old_token)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
data/lib/jwt_keeper/engine.rb
CHANGED
@@ -5,7 +5,7 @@ module JWTKeeper
|
|
5
5
|
# The Sorcery engine takes care of extending ActiveRecord (if used) and ActionController,
|
6
6
|
# With the plugin logic.
|
7
7
|
class Engine < ::Rails::Engine
|
8
|
-
initializer 'extend Controller with
|
8
|
+
initializer 'extend Controller with jwt_keeper' do |_app|
|
9
9
|
ActionController::Base.send(:include, JWTKeeper::Controller)
|
10
10
|
end
|
11
11
|
end
|
data/lib/jwt_keeper/token.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module JWTKeeper
|
2
2
|
class Token
|
3
|
-
attr_accessor :claims
|
3
|
+
attr_accessor :claims, :cookie_secret
|
4
4
|
|
5
5
|
# Initalizes a new web token
|
6
6
|
# @param private_claims [Hash] the custom claims to encode
|
7
|
-
def initialize(private_claims = {})
|
7
|
+
def initialize(private_claims = {}, cookie_secret = nil)
|
8
|
+
@cookie_secret = cookie_secret
|
8
9
|
@claims = {
|
9
10
|
nbf: DateTime.now.to_i, # not before
|
10
11
|
iat: DateTime.now.to_i, # issued at
|
@@ -18,17 +19,18 @@ module JWTKeeper
|
|
18
19
|
# @param private_claims [Hash] the custom claims to encode
|
19
20
|
# @return [Token] token object
|
20
21
|
def self.create(private_claims)
|
21
|
-
|
22
|
+
cookie_secret = SecureRandom.hex(16) if JWTKeeper.configuration.cookie_lock
|
23
|
+
new(private_claims, cookie_secret)
|
22
24
|
end
|
23
25
|
|
24
26
|
# Decodes and validates an existing token
|
25
27
|
# @param raw_token [String] the raw token
|
26
28
|
# @return [Token] token object
|
27
|
-
def self.find(raw_token)
|
28
|
-
claims = decode(raw_token)
|
29
|
+
def self.find(raw_token, cookie_secret = nil)
|
30
|
+
claims = decode(raw_token, cookie_secret)
|
29
31
|
return nil if claims.nil?
|
30
32
|
|
31
|
-
new_token = new(claims)
|
33
|
+
new_token = new(claims, cookie_secret)
|
32
34
|
return nil if new_token.revoked?
|
33
35
|
new_token
|
34
36
|
end
|
@@ -60,8 +62,10 @@ module JWTKeeper
|
|
60
62
|
revoke
|
61
63
|
|
62
64
|
new_claims ||= claims.except(:iss, :aud, :exp, :nbf, :iat, :jti)
|
63
|
-
new_token = self.class.
|
65
|
+
new_token = self.class.create(new_claims)
|
66
|
+
|
64
67
|
@claims = new_token.claims
|
68
|
+
@cookie_secret = new_token.cookie_secret
|
65
69
|
self
|
66
70
|
end
|
67
71
|
|
@@ -98,7 +102,7 @@ module JWTKeeper
|
|
98
102
|
# Checks if the token invalid?
|
99
103
|
# @return [Boolean]
|
100
104
|
def invalid?
|
101
|
-
self.class.decode(encode).nil? || revoked?
|
105
|
+
self.class.decode(encode, cookie_secret).nil? || revoked?
|
102
106
|
end
|
103
107
|
|
104
108
|
# Encodes the jwt
|
@@ -108,9 +112,18 @@ module JWTKeeper
|
|
108
112
|
end
|
109
113
|
alias to_s to_jwt
|
110
114
|
|
115
|
+
# Encodes the cookie
|
116
|
+
# @return [Hash]
|
117
|
+
def to_cookie
|
118
|
+
{
|
119
|
+
value: cookie_secret,
|
120
|
+
expires: Time.at(claims[:exp])
|
121
|
+
}.merge(JWTKeeper.configuration.cookie_options)
|
122
|
+
end
|
123
|
+
|
111
124
|
# @!visibility private
|
112
|
-
def self.decode(raw_token)
|
113
|
-
JWT.decode(raw_token, JWTKeeper.configuration.secret, true,
|
125
|
+
def self.decode(raw_token, cookie_secret)
|
126
|
+
JWT.decode(raw_token, JWTKeeper.configuration.secret.to_s + cookie_secret.to_s, true,
|
114
127
|
algorithm: JWTKeeper.configuration.algorithm,
|
115
128
|
verify_iss: true,
|
116
129
|
verify_aud: true,
|
@@ -118,7 +131,6 @@ module JWTKeeper
|
|
118
131
|
verify_sub: false,
|
119
132
|
verify_jti: false,
|
120
133
|
leeway: 0,
|
121
|
-
|
122
134
|
iss: JWTKeeper.configuration.issuer,
|
123
135
|
aud: JWTKeeper.configuration.audience
|
124
136
|
).first.symbolize_keys
|
@@ -131,7 +143,10 @@ module JWTKeeper
|
|
131
143
|
|
132
144
|
# @!visibility private
|
133
145
|
def encode
|
134
|
-
JWT.encode(claims,
|
146
|
+
JWT.encode(claims,
|
147
|
+
JWTKeeper.configuration.secret.to_s + cookie_secret.to_s,
|
148
|
+
JWTKeeper.configuration.algorithm
|
149
|
+
)
|
135
150
|
end
|
136
151
|
end
|
137
152
|
end
|
data/lib/jwt_keeper/version.rb
CHANGED
File without changes
|
@@ -6,8 +6,20 @@ RSpec.describe JWTKeeper do
|
|
6
6
|
|
7
7
|
let(:token) { JWTKeeper::Token.create(claim: "Jet fuel can't melt steel beams") }
|
8
8
|
subject(:test_controller) do
|
9
|
+
cookies_klass = Class.new(Hash) do
|
10
|
+
def signed
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
message_klass = Class.new(Hash) do
|
16
|
+
def headers
|
17
|
+
self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
instance = Class.new do
|
10
|
-
attr_accessor :request, :response
|
22
|
+
attr_accessor :request, :response, :cookies
|
11
23
|
include RSpec::Mocks::ExampleMethods
|
12
24
|
include JWTKeeper::Controller
|
13
25
|
|
@@ -27,20 +39,21 @@ RSpec.describe JWTKeeper do
|
|
27
39
|
end
|
28
40
|
end.new
|
29
41
|
|
30
|
-
instance.request
|
31
|
-
|
32
|
-
instance.
|
33
|
-
|
42
|
+
instance.request = message_klass.new
|
43
|
+
instance.response = message_klass.new
|
44
|
+
instance.cookies = cookies_klass.new
|
45
|
+
instance.request['Authorization'] = "Bearer #{token}"
|
34
46
|
instance
|
35
47
|
end
|
36
48
|
|
37
49
|
describe '#included' do
|
38
50
|
it { is_expected.to respond_to(:require_authentication) }
|
39
|
-
it { is_expected.to respond_to(:
|
40
|
-
it { is_expected.to respond_to(:
|
41
|
-
it { is_expected.to respond_to(:
|
51
|
+
it { is_expected.to respond_to(:read_authentication_token) }
|
52
|
+
it { is_expected.to respond_to(:write_authentication_token) }
|
53
|
+
it { is_expected.to respond_to(:clear_authentication_token) }
|
42
54
|
it { is_expected.to respond_to(:not_authenticated) }
|
43
55
|
it { is_expected.to respond_to(:authenticated) }
|
56
|
+
it { is_expected.to respond_to(:regenerate_claims) }
|
44
57
|
end
|
45
58
|
|
46
59
|
describe '#require_authentication' do
|
@@ -56,7 +69,7 @@ RSpec.describe JWTKeeper do
|
|
56
69
|
|
57
70
|
it 'does not rotates the token' do
|
58
71
|
expect { subject.require_authentication }.to_not change {
|
59
|
-
subject.
|
72
|
+
subject.read_authentication_token.id
|
60
73
|
}
|
61
74
|
end
|
62
75
|
end
|
@@ -90,7 +103,7 @@ RSpec.describe JWTKeeper do
|
|
90
103
|
|
91
104
|
it 'rotates the token' do
|
92
105
|
expect { subject.require_authentication }.to change {
|
93
|
-
subject.
|
106
|
+
subject.read_authentication_token.id
|
94
107
|
}
|
95
108
|
end
|
96
109
|
end
|
@@ -108,7 +121,7 @@ RSpec.describe JWTKeeper do
|
|
108
121
|
|
109
122
|
it 'rotates the token' do
|
110
123
|
expect { subject.require_authentication }.to change {
|
111
|
-
subject.
|
124
|
+
subject.read_authentication_token.id
|
112
125
|
}
|
113
126
|
end
|
114
127
|
end
|
@@ -125,52 +138,27 @@ RSpec.describe JWTKeeper do
|
|
125
138
|
end
|
126
139
|
|
127
140
|
it 'is used to update the token claims on rotation' do
|
128
|
-
expect(subject.
|
129
|
-
|
130
|
-
expect(subject.
|
141
|
+
expect(subject.read_authentication_token.claims[:regenerate_claims]).to be nil
|
142
|
+
subject.require_authentication
|
143
|
+
expect(subject.read_authentication_token.claims[:regenerate_claims]).to be true
|
131
144
|
end
|
132
145
|
end
|
133
146
|
|
134
|
-
describe '#
|
135
|
-
before do
|
136
|
-
subject.
|
147
|
+
describe '#clear_authentication_token' do
|
148
|
+
before :each do
|
149
|
+
subject.write_authentication_token(JWTKeeper::Token.create({}))
|
137
150
|
end
|
138
151
|
|
139
|
-
it '
|
140
|
-
subject.
|
141
|
-
|
152
|
+
it 'clears the cookie' do
|
153
|
+
expect(subject.cookies.signed['jwt_keeper']).not_to be_nil
|
154
|
+
subject.clear_authentication_token
|
155
|
+
expect(subject.cookies.signed['jwt_keeper']).to be_nil
|
142
156
|
end
|
143
|
-
end
|
144
157
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
151
|
-
context 'no token in request' do
|
152
|
-
before do
|
153
|
-
token = JWTKeeper::Token.create(exp: 3.hours.ago)
|
154
|
-
subject.request =
|
155
|
-
instance_double('Request', headers: { 'Authorization' => "Bearer #{token}" })
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'returns nil' do
|
159
|
-
expect(subject.authentication_token).to be nil
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
describe '#redirect_back_or_to' do
|
165
|
-
let(:path) { 'http://www.example.com' }
|
166
|
-
|
167
|
-
before do
|
168
|
-
allow(test_controller).to receive(:redirect_to)
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'it calls redirect_to' do
|
172
|
-
subject.redirect_back_or_to(path)
|
173
|
-
expect(subject).to have_received(:redirect_to).with(path, anything)
|
158
|
+
it 'clears the header' do
|
159
|
+
expect(subject.response.headers['Authorization']).not_to be_nil
|
160
|
+
subject.clear_authentication_token
|
161
|
+
expect(subject.response.headers['Authorization']).to be_nil
|
174
162
|
end
|
175
163
|
end
|
176
164
|
|
File without changes
|
@@ -4,13 +4,19 @@ module JWTKeeper
|
|
4
4
|
RSpec.describe Token do
|
5
5
|
include_context 'initialize config'
|
6
6
|
let(:private_claims) { { claim: "Jet fuel can't melt steel beams" } }
|
7
|
-
let(:
|
7
|
+
let(:token) { described_class.create(private_claims) }
|
8
|
+
let(:raw_token) { token.to_jwt }
|
8
9
|
|
9
10
|
describe '.create' do
|
10
11
|
subject { described_class.create(private_claims) }
|
11
12
|
|
12
13
|
it { is_expected.to be_instance_of described_class }
|
13
14
|
it { expect(subject.claims[:claim]).to eql private_claims[:claim] }
|
15
|
+
|
16
|
+
context 'with cookie_lock enabled' do
|
17
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(cookie_lock: true))) }
|
18
|
+
it { expect(subject.cookie_secret).not_to be_empty }
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
describe '.find' do
|
@@ -21,15 +27,25 @@ module JWTKeeper
|
|
21
27
|
|
22
28
|
context 'with invalid token' do
|
23
29
|
let(:private_claims) { { exp: 1.hour.ago } }
|
24
|
-
|
25
30
|
it { is_expected.to be nil }
|
26
31
|
end
|
27
32
|
|
28
33
|
context 'with revoked token' do
|
29
34
|
before { described_class.find(raw_token).revoke }
|
35
|
+
it { is_expected.to be nil }
|
36
|
+
end
|
30
37
|
|
38
|
+
context 'with bad cookie' do
|
39
|
+
subject { described_class.find(raw_token, 'BAD_COOKIE') }
|
31
40
|
it { is_expected.to be nil }
|
32
41
|
end
|
42
|
+
|
43
|
+
context 'with valid cookie' do
|
44
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(cookie_lock: true))) }
|
45
|
+
subject { described_class.find(raw_token, token.cookie_secret) }
|
46
|
+
|
47
|
+
it { is_expected.to be_instance_of described_class }
|
48
|
+
end
|
33
49
|
end
|
34
50
|
|
35
51
|
describe '.rotate' do
|
@@ -142,6 +158,7 @@ module JWTKeeper
|
|
142
158
|
end
|
143
159
|
|
144
160
|
describe '#rotate' do
|
161
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(cookie_lock: true))) }
|
145
162
|
let(:old_token) { described_class.create(private_claims) }
|
146
163
|
let(:new_token) { old_token.dup.rotate }
|
147
164
|
before { new_token }
|
@@ -149,13 +166,14 @@ module JWTKeeper
|
|
149
166
|
it { expect(old_token).to be_invalid }
|
150
167
|
it { expect(new_token).to be_valid }
|
151
168
|
it { expect(old_token.claims[:claim]).to eq new_token.claims[:claim] }
|
169
|
+
it { expect(old_token.cookie_secret).not_to eq new_token.cookie_secret }
|
152
170
|
end
|
153
171
|
|
154
172
|
describe '#valid?' do
|
155
173
|
subject { described_class.create(private_claims) }
|
156
174
|
|
157
175
|
context 'when invalid' do
|
158
|
-
before { JWTKeeper.configure(JWTKeeper::Configuration.new(
|
176
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(expiry: -1.hours))) }
|
159
177
|
it { is_expected.not_to be_valid }
|
160
178
|
end
|
161
179
|
|
@@ -168,13 +186,26 @@ module JWTKeeper
|
|
168
186
|
subject { described_class.create(private_claims) }
|
169
187
|
|
170
188
|
context 'when invalid' do
|
171
|
-
before { JWTKeeper.configure(JWTKeeper::Configuration.new(
|
189
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(expiry: -1.hours))) }
|
172
190
|
it { is_expected.to be_invalid }
|
173
191
|
end
|
174
192
|
|
175
193
|
context 'when valid' do
|
176
194
|
it { is_expected.not_to be_invalid }
|
177
195
|
end
|
196
|
+
|
197
|
+
context 'with cookie_lock enabled' do
|
198
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(cookie_lock: true))) }
|
199
|
+
|
200
|
+
context 'when invalid' do
|
201
|
+
before { JWTKeeper.configure(JWTKeeper::Configuration.new(config.merge(expiry: -1.hours))) }
|
202
|
+
it { is_expected.to be_invalid }
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when valid' do
|
206
|
+
it { is_expected.not_to be_invalid }
|
207
|
+
end
|
208
|
+
end
|
178
209
|
end
|
179
210
|
end
|
180
211
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe JWTKeeper do
|
4
|
+
describe '#configure' do
|
5
|
+
let(:new_config) { { secret: '#configure-secret' } }
|
6
|
+
|
7
|
+
context 'without block' do
|
8
|
+
before do
|
9
|
+
described_class.configure(JWTKeeper::Configuration.new(new_config))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets the configuration based on param' do
|
13
|
+
expect(described_class.configuration.secret).to eql new_config[:secret]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with block' do
|
18
|
+
before do
|
19
|
+
described_class.configure do |config|
|
20
|
+
config.secret = new_config[:secret]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets configuration based on the block' do
|
25
|
+
expect(described_class.configuration.secret).to eql new_config[:secret]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,18 +41,20 @@ RSpec.configure do |config|
|
|
41
41
|
end
|
42
42
|
|
43
43
|
RSpec.shared_context 'initialize config' do
|
44
|
-
let(:
|
44
|
+
let(:config) do
|
45
45
|
{
|
46
46
|
algorithm: 'HS256',
|
47
47
|
secret: 'secret',
|
48
48
|
expiry: 24.hours,
|
49
49
|
issuer: 'api.example.com',
|
50
50
|
audience: 'example.com',
|
51
|
-
redis_connection: Redis.new(url: ENV['REDIS_URL'])
|
51
|
+
redis_connection: Redis.new(url: ENV['REDIS_URL']),
|
52
|
+
version: nil,
|
53
|
+
cookie_lock: false
|
52
54
|
}
|
53
55
|
end
|
54
56
|
|
55
57
|
before(:each) do
|
56
|
-
JWTKeeper.configure(JWTKeeper::Configuration.new(
|
58
|
+
JWTKeeper.configure(JWTKeeper::Configuration.new(config))
|
57
59
|
end
|
58
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jwt_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Rivera
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -212,8 +212,36 @@ files:
|
|
212
212
|
- Rakefile
|
213
213
|
- docker-compose.yml
|
214
214
|
- example.env
|
215
|
+
- example/.gitignore
|
216
|
+
- example/Gemfile
|
217
|
+
- example/Rakefile
|
218
|
+
- example/app/controllers/application_controller.rb
|
219
|
+
- example/app/controllers/sessions_controller.rb
|
220
|
+
- example/bin/bundle
|
221
|
+
- example/bin/rails
|
222
|
+
- example/bin/rake
|
223
|
+
- example/bin/setup
|
224
|
+
- example/bin/spring
|
225
|
+
- example/config.ru
|
226
|
+
- example/config/application.rb
|
227
|
+
- example/config/boot.rb
|
228
|
+
- example/config/environment.rb
|
229
|
+
- example/config/environments/development.rb
|
230
|
+
- example/config/environments/production.rb
|
231
|
+
- example/config/environments/test.rb
|
232
|
+
- example/config/initializers/backtrace_silencer.rb
|
233
|
+
- example/config/initializers/cookies_serializer.rb
|
234
|
+
- example/config/initializers/filter_parameter_logging.rb
|
235
|
+
- example/config/initializers/jwt_keeper.rb
|
236
|
+
- example/config/initializers/session_store.rb
|
237
|
+
- example/config/initializers/wrap_parameters.rb
|
238
|
+
- example/config/locales/en.yml
|
239
|
+
- example/config/routes.rb
|
240
|
+
- example/config/secrets.yml
|
241
|
+
- example/example.env
|
242
|
+
- example/log/.keep
|
215
243
|
- jwt_keeper.gemspec
|
216
|
-
- lib/generators/
|
244
|
+
- lib/generators/jwt_keeper/install/install_generator.rb
|
217
245
|
- lib/generators/templates/jwt_keeper.rb
|
218
246
|
- lib/jwt_keeper.rb
|
219
247
|
- lib/jwt_keeper/configuration.rb
|
@@ -223,11 +251,11 @@ files:
|
|
223
251
|
- lib/jwt_keeper/exceptions.rb
|
224
252
|
- lib/jwt_keeper/token.rb
|
225
253
|
- lib/jwt_keeper/version.rb
|
226
|
-
- spec/lib/
|
227
|
-
- spec/lib/
|
228
|
-
- spec/lib/
|
229
|
-
- spec/lib/
|
230
|
-
- spec/lib/
|
254
|
+
- spec/lib/jwt_keeper/configuration_spec.rb
|
255
|
+
- spec/lib/jwt_keeper/controller_spec.rb
|
256
|
+
- spec/lib/jwt_keeper/datastore_spec.rb
|
257
|
+
- spec/lib/jwt_keeper/token_spec.rb
|
258
|
+
- spec/lib/jwt_keeper_spec.rb
|
231
259
|
- spec/spec_helper.rb
|
232
260
|
homepage: https://github.com/sirwolfgang/jwt_keeper
|
233
261
|
licenses:
|
@@ -254,10 +282,10 @@ signing_key:
|
|
254
282
|
specification_version: 4
|
255
283
|
summary: JWT for Rails made easy
|
256
284
|
test_files:
|
257
|
-
- spec/lib/
|
258
|
-
- spec/lib/
|
259
|
-
- spec/lib/
|
260
|
-
- spec/lib/
|
261
|
-
- spec/lib/
|
285
|
+
- spec/lib/jwt_keeper/configuration_spec.rb
|
286
|
+
- spec/lib/jwt_keeper/controller_spec.rb
|
287
|
+
- spec/lib/jwt_keeper/datastore_spec.rb
|
288
|
+
- spec/lib/jwt_keeper/token_spec.rb
|
289
|
+
- spec/lib/jwt_keeper_spec.rb
|
262
290
|
- spec/spec_helper.rb
|
263
291
|
has_rdoc:
|
data/spec/lib/keeper_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe JWTKeeper do
|
4
|
-
describe '#configure' do
|
5
|
-
let(:test_config) do
|
6
|
-
{
|
7
|
-
algorithm: 'HS256',
|
8
|
-
secret: 'secret',
|
9
|
-
expiry: 24.hours,
|
10
|
-
issuer: 'api.example.com',
|
11
|
-
audience: 'example.com',
|
12
|
-
redis_connection: Redis.new(url: ENV['REDIS_URL'])
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'without block' do
|
17
|
-
before do
|
18
|
-
described_class.configure(JWTKeeper::Configuration.new(test_config))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets the configuration based on param' do
|
22
|
-
expect(described_class.configuration.secret).to eql test_config[:secret]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with block' do
|
27
|
-
before do
|
28
|
-
described_class.configure do |config|
|
29
|
-
config.secret = test_config[:secret]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'sets configuration based on the block' do
|
34
|
-
expect(described_class.configuration.secret).to eql test_config[:secret]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|