simple_token_authentication 1.6.0 → 1.7.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/README.md +2 -2
- data/lib/simple_token_authentication.rb +6 -2
- data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +5 -0
- data/lib/simple_token_authentication/adapters/rails_api_adapter.rb +18 -0
- data/lib/simple_token_authentication/configuration.rb +6 -1
- data/lib/simple_token_authentication/token_authentication_handler.rb +23 -3
- data/lib/simple_token_authentication/token_comparator.rb +7 -0
- data/lib/simple_token_authentication/version.rb +1 -1
- data/spec/configuration/header_names_option_spec.rb +9 -0
- data/spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb +43 -0
- data/spec/lib/simple_token_authentication/configuration_spec.rb +14 -2
- data/spec/lib/simple_token_authentication/token_authentication_handler_spec.rb +101 -0
- data/spec/lib/simple_token_authentication_spec.rb +36 -0
- metadata +28 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d1e730c48d4c9f3816d431719e033c8b295191ef
|
|
4
|
+
data.tar.gz: 2bf59bfe3dc641daa8ba148b9bd5ac453d240031
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc2423b6fcf422ecf6d6147a3ea3800015325214446b83423718192178d75e339e17d346f662a28396fe410699b8c0ab264c9a60ed35f8eb163fc5b1f5dbb6f3
|
|
7
|
+
data.tar.gz: 449f14e10164ed7a2c90a7b99bfe9934ed1f64b2033b31ee8fc84bd919856732ad3d62a78eb44a44471c4417474685b12178b4f5a13f352dd570b0ea5cc80d75
|
data/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Install [Devise][devise] with any modules you want, then add the gem to your `Ge
|
|
|
29
29
|
```ruby
|
|
30
30
|
# Gemfile
|
|
31
31
|
|
|
32
|
-
gem 'simple_token_authentication'
|
|
32
|
+
gem 'simple_token_authentication', '~> 1.0' # see semver.org
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Make models token authenticatable
|
|
@@ -94,7 +94,7 @@ Finally define which controllers will handle token authentication (typ. `Applica
|
|
|
94
94
|
```ruby
|
|
95
95
|
# app/controllers/application_controller.rb
|
|
96
96
|
|
|
97
|
-
class ApplicationController < ActionController::Base
|
|
97
|
+
class ApplicationController < ActionController::Base # or ActionController::API
|
|
98
98
|
# ...
|
|
99
99
|
|
|
100
100
|
acts_as_token_authentication_handler_for User
|
|
@@ -34,18 +34,22 @@ module SimpleTokenAuthentication
|
|
|
34
34
|
def self.load_available_adapters adapters_short_names
|
|
35
35
|
available_adapters = adapters_short_names.collect do |short_name|
|
|
36
36
|
adapter_name = "simple_token_authentication/adapters/#{short_name}_adapter"
|
|
37
|
-
if
|
|
37
|
+
if adapter_dependency_fulfilled?(short_name) && require(adapter_name)
|
|
38
38
|
adapter_name.camelize.constantize
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
available_adapters.compact!
|
|
42
42
|
|
|
43
|
-
# stop here if
|
|
43
|
+
# stop here if dependencies are missing or no adequate adapters are present
|
|
44
44
|
raise SimpleTokenAuthentication::NoAdapterAvailableError if available_adapters.empty?
|
|
45
45
|
|
|
46
46
|
available_adapters
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
def self.adapter_dependency_fulfilled? adapter_short_name
|
|
50
|
+
qualified_const_defined?(SimpleTokenAuthentication.adapters_dependencies[adapter_short_name])
|
|
51
|
+
end
|
|
52
|
+
|
|
49
53
|
available_model_adapters = load_available_adapters SimpleTokenAuthentication.model_adapters
|
|
50
54
|
ensure_models_can_act_as_token_authenticatables available_model_adapters
|
|
51
55
|
|
|
@@ -14,6 +14,10 @@ module SimpleTokenAuthentication
|
|
|
14
14
|
private :token_generator
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# Set an authentication token if missing
|
|
18
|
+
#
|
|
19
|
+
# Because it is intended to be used as a filter,
|
|
20
|
+
# this method is -and should be kept- idempotent.
|
|
17
21
|
def ensure_authentication_token
|
|
18
22
|
if authentication_token.blank?
|
|
19
23
|
self.authentication_token = generate_authentication_token(token_generator)
|
|
@@ -31,6 +35,7 @@ module SimpleTokenAuthentication
|
|
|
31
35
|
self.class.where(authentication_token: token).count == 0
|
|
32
36
|
end
|
|
33
37
|
|
|
38
|
+
# Private: Get one (always the same) object which behaves as a token generator
|
|
34
39
|
def token_generator
|
|
35
40
|
@token_generator ||= TokenGenerator.new
|
|
36
41
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'action_controller'
|
|
2
|
+
require 'simple_token_authentication/adapter'
|
|
3
|
+
|
|
4
|
+
module SimpleTokenAuthentication
|
|
5
|
+
module Adapters
|
|
6
|
+
class RailsAPIAdapter
|
|
7
|
+
extend SimpleTokenAuthentication::Adapter
|
|
8
|
+
|
|
9
|
+
def self.base_class
|
|
10
|
+
::ActionController::API
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# make the adpater available even if the 'API' acronym is not defined
|
|
15
|
+
RailsApiAdapter = RailsAPIAdapter
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
@@ -6,13 +6,18 @@ module SimpleTokenAuthentication
|
|
|
6
6
|
mattr_accessor :sign_in_token
|
|
7
7
|
mattr_accessor :controller_adapters
|
|
8
8
|
mattr_accessor :model_adapters
|
|
9
|
+
mattr_accessor :adapters_dependencies
|
|
9
10
|
|
|
10
11
|
# Default configuration
|
|
11
12
|
@@fallback = :devise
|
|
12
13
|
@@header_names = {}
|
|
13
14
|
@@sign_in_token = false
|
|
14
|
-
@@controller_adapters = ['rails']
|
|
15
|
+
@@controller_adapters = ['rails', 'rails_api']
|
|
15
16
|
@@model_adapters = ['active_record', 'mongoid']
|
|
17
|
+
@@adapters_dependencies = { 'active_record' => 'ActiveRecord::Base',
|
|
18
|
+
'mongoid' => 'Mongoid::Document',
|
|
19
|
+
'rails' => 'ActionController::Base',
|
|
20
|
+
'rails_api' => 'ActionController::API' }
|
|
16
21
|
|
|
17
22
|
# Allow the default configuration to be overwritten from initializers
|
|
18
23
|
def configure
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require 'action_controller/base'
|
|
2
1
|
require 'active_support/concern'
|
|
2
|
+
require 'devise'
|
|
3
3
|
|
|
4
4
|
require 'simple_token_authentication/entities_manager'
|
|
5
5
|
require 'simple_token_authentication/fallback_authentication_handler'
|
|
@@ -13,6 +13,7 @@ module SimpleTokenAuthentication
|
|
|
13
13
|
included do
|
|
14
14
|
private_class_method :define_token_authentication_helpers_for
|
|
15
15
|
private_class_method :set_token_authentication_hooks
|
|
16
|
+
private_class_method :entities_manager
|
|
16
17
|
private_class_method :fallback_authentication_handler
|
|
17
18
|
|
|
18
19
|
private :authenticate_entity_from_token!
|
|
@@ -22,6 +23,7 @@ module SimpleTokenAuthentication
|
|
|
22
23
|
private :token_comparator
|
|
23
24
|
private :sign_in_handler
|
|
24
25
|
private :find_record_from_identifier
|
|
26
|
+
private :integrate_with_devise_case_insensitive_keys
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
def authenticate_entity_from_token!(entity)
|
|
@@ -52,16 +54,32 @@ module SimpleTokenAuthentication
|
|
|
52
54
|
def find_record_from_identifier(entity)
|
|
53
55
|
email = entity.get_identifier_from_params_or_headers(self).presence
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
email = integrate_with_devise_case_insensitive_keys(email)
|
|
58
|
+
|
|
59
|
+
# The finder method should be compatible with all the model adapters,
|
|
60
|
+
# namely ActiveRecord and Mongoid in all their supported versions.
|
|
57
61
|
record = nil
|
|
58
62
|
record = email && entity.model.where(email: email).first
|
|
59
63
|
end
|
|
60
64
|
|
|
65
|
+
# Private: Take benefit from Devise case-insensitive keys
|
|
66
|
+
#
|
|
67
|
+
# See https://github.com/plataformatec/devise/blob/v3.4.1/lib/generators/templates/devise.rb#L45-L48
|
|
68
|
+
#
|
|
69
|
+
# email - the original email String
|
|
70
|
+
#
|
|
71
|
+
# Returns an email String which case follows the Devise case-insensitive keys policy
|
|
72
|
+
def integrate_with_devise_case_insensitive_keys(email)
|
|
73
|
+
email.downcase! if email && Devise.case_insensitive_keys.include?(:email)
|
|
74
|
+
email
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Private: Get one (always the same) object which behaves as a token comprator
|
|
61
78
|
def token_comparator
|
|
62
79
|
@@token_comparator ||= TokenComparator.new
|
|
63
80
|
end
|
|
64
81
|
|
|
82
|
+
# Private: Get one (always the same) object which behaves as a sign in handler
|
|
65
83
|
def sign_in_handler
|
|
66
84
|
@@sign_in_handler ||= SignInHandler.new
|
|
67
85
|
end
|
|
@@ -80,6 +98,7 @@ module SimpleTokenAuthentication
|
|
|
80
98
|
set_token_authentication_hooks(entity, options)
|
|
81
99
|
end
|
|
82
100
|
|
|
101
|
+
# Private: Get one (always the same) object which behaves as an entities manager
|
|
83
102
|
def entities_manager
|
|
84
103
|
if class_variable_defined?(:@@entities_manager)
|
|
85
104
|
class_variable_get(:@@entities_manager)
|
|
@@ -88,6 +107,7 @@ module SimpleTokenAuthentication
|
|
|
88
107
|
end
|
|
89
108
|
end
|
|
90
109
|
|
|
110
|
+
# Private: Get one (always the same) object which behaves as a fallback authentication handler
|
|
91
111
|
def fallback_authentication_handler
|
|
92
112
|
if class_variable_defined?(:@@fallback_authentication_handler)
|
|
93
113
|
class_variable_get(:@@fallback_authentication_handler)
|
|
@@ -2,6 +2,13 @@ require 'devise'
|
|
|
2
2
|
|
|
3
3
|
module SimpleTokenAuthentication
|
|
4
4
|
class TokenComparator
|
|
5
|
+
|
|
6
|
+
# Compare two String instances
|
|
7
|
+
#
|
|
8
|
+
# Important: this method is cryptographically critical and
|
|
9
|
+
# must be implemented with care when defining new token comparators.
|
|
10
|
+
#
|
|
11
|
+
# Returns true if String instances do match, false otherwise
|
|
5
12
|
def compare(a, b)
|
|
6
13
|
# Notice how we use Devise.secure_compare to compare tokens
|
|
7
14
|
# while mitigating timing attacks.
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
def skip_devise_case_insensitive_keys_integration!(controller)
|
|
4
|
+
allow(controller).to receive(:integrate_with_devise_case_insensitive_keys) do |email|
|
|
5
|
+
email # return the email without modification
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
3
9
|
describe 'Simple Token Authentication' do
|
|
4
10
|
|
|
5
11
|
describe ':header_names option', header_names_option: true do
|
|
@@ -36,6 +42,7 @@ describe 'Simple Token Authentication' do
|
|
|
36
42
|
|
|
37
43
|
@controller = @controller_class.new
|
|
38
44
|
allow(@controller).to receive(:sign_in_handler).and_return(:sign_in_handler)
|
|
45
|
+
skip_devise_case_insensitive_keys_integration!(@controller)
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
|
|
@@ -442,6 +449,8 @@ describe 'Simple Token Authentication' do
|
|
|
442
449
|
allow(SimpleTokenAuthentication).to receive(:header_names)
|
|
443
450
|
.and_return({ user: { email: 'X-UpdatedName-User-Email', authentication_token: 'X-UpdatedName-User-Token' }})
|
|
444
451
|
|
|
452
|
+
skip_devise_case_insensitive_keys_integration!(@controller)
|
|
453
|
+
|
|
445
454
|
# the option updated value is taken into account
|
|
446
455
|
# when token authentication is performed
|
|
447
456
|
expect(@controller.request.headers).to receive(:[]).with('X-UpdatedName-User-Email')
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'simple_token_authentication/adapters/rails_api_adapter'
|
|
3
|
+
|
|
4
|
+
describe 'SimpleTokenAuthentication::Adapters::RailsAPIAdapter' do
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
stub_const('ActionController', Module.new)
|
|
8
|
+
stub_const('ActionController::API', double())
|
|
9
|
+
|
|
10
|
+
@subject = SimpleTokenAuthentication::Adapters::RailsAPIAdapter
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it_behaves_like 'an adapter'
|
|
14
|
+
|
|
15
|
+
describe '.base_class' do
|
|
16
|
+
|
|
17
|
+
it 'is ActionController::API', private: true do
|
|
18
|
+
expect(@subject.base_class).to eq ActionController::API
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'When the "API" acronym is not defined' do
|
|
24
|
+
describe 'SimpleTokenAuthentication::Adapters::RailsApiAdapter' do
|
|
25
|
+
|
|
26
|
+
before(:each) do
|
|
27
|
+
stub_const('ActionController', Module.new)
|
|
28
|
+
stub_const('ActionController::API', double())
|
|
29
|
+
|
|
30
|
+
@subject = SimpleTokenAuthentication::Adapters::RailsApiAdapter
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it_behaves_like 'an adapter'
|
|
34
|
+
|
|
35
|
+
describe '.base_class' do
|
|
36
|
+
|
|
37
|
+
it 'is ActionController::API', private: true do
|
|
38
|
+
expect(@subject.base_class).to eq ActionController::API
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
@@ -20,8 +20,8 @@ describe SimpleTokenAuthentication::Configuration do
|
|
|
20
20
|
|
|
21
21
|
it_behaves_like 'a configuration option', 'controller_adapters'
|
|
22
22
|
|
|
23
|
-
it "defauts to ['rails']", private: true do
|
|
24
|
-
expect(@subject.controller_adapters).to eq ['rails']
|
|
23
|
+
it "defauts to ['rails', 'rails_api']", private: true do
|
|
24
|
+
expect(@subject.controller_adapters).to eq ['rails', 'rails_api']
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -34,6 +34,18 @@ describe SimpleTokenAuthentication::Configuration do
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
describe 'provides #adapters_dependencies which' do
|
|
38
|
+
|
|
39
|
+
it_behaves_like 'a configuration option', 'adapters_dependencies'
|
|
40
|
+
|
|
41
|
+
it 'lists the supported adapters dependencies by default', private: true do
|
|
42
|
+
expect(@subject.adapters_dependencies['active_record']).to eq 'ActiveRecord::Base'
|
|
43
|
+
expect(@subject.adapters_dependencies['mongoid']).to eq 'Mongoid::Document'
|
|
44
|
+
expect(@subject.adapters_dependencies['rails']).to eq 'ActionController::Base'
|
|
45
|
+
expect(@subject.adapters_dependencies['rails_api']).to eq 'ActionController::API'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
describe 'provides #header_names which', header_names_option: true do
|
|
38
50
|
|
|
39
51
|
it_behaves_like 'a configuration option', 'header_names'
|
|
@@ -135,6 +135,107 @@ describe 'Any class which includes SimpleTokenAuthentication::TokenAuthenticatio
|
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
+
describe '#find_record_from_identifier', private: true do
|
|
139
|
+
|
|
140
|
+
before(:each) do
|
|
141
|
+
@entity = double()
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context 'when the Devise config. does not defines the identifier as a case-insentitive key' do
|
|
145
|
+
|
|
146
|
+
before(:each) do
|
|
147
|
+
allow(Devise).to receive_message_chain(:case_insensitive_keys, :include?)
|
|
148
|
+
.with(:email).and_return(false)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context 'when a downcased identifier was provided' do
|
|
152
|
+
|
|
153
|
+
before(:each) do
|
|
154
|
+
allow(@entity).to receive(:get_identifier_from_params_or_headers)
|
|
155
|
+
.and_return('alice@example.com')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'returns the proper record if any' do
|
|
159
|
+
# let's say there is a record
|
|
160
|
+
record = double()
|
|
161
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'alice@example.com')
|
|
162
|
+
.and_return([record])
|
|
163
|
+
|
|
164
|
+
expect(subject.new.send(:find_record_from_identifier, @entity)).to eq record
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
context 'when a upcased identifier was provided' do
|
|
169
|
+
|
|
170
|
+
before(:each) do
|
|
171
|
+
allow(@entity).to receive(:get_identifier_from_params_or_headers)
|
|
172
|
+
.and_return('AliCe@ExampLe.Com')
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'does not return any record' do
|
|
176
|
+
# let's say there is a record...
|
|
177
|
+
record = double()
|
|
178
|
+
# ...whose identifier is downcased...
|
|
179
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'alice@example.com')
|
|
180
|
+
.and_return([record])
|
|
181
|
+
# ...not upcased
|
|
182
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'AliCe@ExampLe.Com')
|
|
183
|
+
.and_return([])
|
|
184
|
+
|
|
185
|
+
expect(subject.new.send(:find_record_from_identifier, @entity)).to be_nil
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
context 'when the Devise config. defines the identifier as a case-insentitive key' do
|
|
192
|
+
|
|
193
|
+
before(:each) do
|
|
194
|
+
allow(Devise).to receive_message_chain(:case_insensitive_keys, :include?)
|
|
195
|
+
.with(:email).and_return(true)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context 'and a downcased identifier was provided' do
|
|
199
|
+
|
|
200
|
+
before(:each) do
|
|
201
|
+
allow(@entity).to receive(:get_identifier_from_params_or_headers)
|
|
202
|
+
.and_return('alice@example.com')
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it 'returns the proper record if any' do
|
|
206
|
+
# let's say there is a record
|
|
207
|
+
record = double()
|
|
208
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'alice@example.com')
|
|
209
|
+
.and_return([record])
|
|
210
|
+
|
|
211
|
+
expect(subject.new.send(:find_record_from_identifier, @entity)).to eq record
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
context 'and a upcased identifier was provided' do
|
|
216
|
+
|
|
217
|
+
before(:each) do
|
|
218
|
+
allow(@entity).to receive(:get_identifier_from_params_or_headers)
|
|
219
|
+
.and_return('AliCe@ExampLe.Com')
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it 'returns the proper record if any' do
|
|
223
|
+
# let's say there is a record...
|
|
224
|
+
record = double()
|
|
225
|
+
# ...whose identifier is downcased...
|
|
226
|
+
allow(@entity).to receive_message_chain(:model, :where)
|
|
227
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'alice@example.com')
|
|
228
|
+
.and_return([record])
|
|
229
|
+
# ...not upcased
|
|
230
|
+
allow(@entity).to receive_message_chain(:model, :where).with(email: 'AliCe@ExampLe.Com')
|
|
231
|
+
.and_return([])
|
|
232
|
+
|
|
233
|
+
expect(subject.new.send(:find_record_from_identifier, @entity)).to eq record
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
138
239
|
describe 'and which supports the :before_filter hook' do
|
|
139
240
|
|
|
140
241
|
before(:each) do
|
|
@@ -142,4 +142,40 @@ describe SimpleTokenAuthentication do
|
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
144
|
end
|
|
145
|
+
|
|
146
|
+
context 'when ActionController::API is available' do
|
|
147
|
+
|
|
148
|
+
before(:each) do
|
|
149
|
+
stub_const('ActionController::API', Class.new)
|
|
150
|
+
|
|
151
|
+
# define a dummy ActionController::API (a.k.a 'Rails API') adapter
|
|
152
|
+
dummy_rails_adapter = double()
|
|
153
|
+
allow(dummy_rails_adapter).to receive(:base_class).and_return(ActionController::API)
|
|
154
|
+
stub_const('SimpleTokenAuthentication::Adapters::DummyRailsAPIAdapter', dummy_rails_adapter)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe '#ensure_controllers_can_act_as_token_authentication_handlers' do
|
|
158
|
+
|
|
159
|
+
before(:each) do
|
|
160
|
+
class SimpleTokenAuthentication::DummyController < ActionController::API; end
|
|
161
|
+
@dummy_controller = SimpleTokenAuthentication::DummyController
|
|
162
|
+
|
|
163
|
+
expect(@dummy_controller.new).to be_instance_of SimpleTokenAuthentication::DummyController
|
|
164
|
+
expect(@dummy_controller.new).to be_kind_of ActionController::API
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
after(:each) do
|
|
168
|
+
SimpleTokenAuthentication.send(:remove_const, :DummyController)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'allows any kind of ActionController::API to acts as token authentication handler', private: true do
|
|
172
|
+
expect(@dummy_controller).not_to respond_to :acts_as_token_authentication_handler_for
|
|
173
|
+
|
|
174
|
+
subject.ensure_controllers_can_act_as_token_authentication_handlers [
|
|
175
|
+
SimpleTokenAuthentication::Adapters::DummyRailsAPIAdapter]
|
|
176
|
+
|
|
177
|
+
expect(@dummy_controller).to respond_to :acts_as_token_authentication_handler_for
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
145
181
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_token_authentication
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gonzalo Bulnes Guilpain
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionmailer
|
|
@@ -150,6 +150,7 @@ files:
|
|
|
150
150
|
- lib/simple_token_authentication/adapters/active_record_adapter.rb
|
|
151
151
|
- lib/simple_token_authentication/adapters/mongoid_adapter.rb
|
|
152
152
|
- lib/simple_token_authentication/adapters/rails_adapter.rb
|
|
153
|
+
- lib/simple_token_authentication/adapters/rails_api_adapter.rb
|
|
153
154
|
- lib/simple_token_authentication/configuration.rb
|
|
154
155
|
- lib/simple_token_authentication/entities_manager.rb
|
|
155
156
|
- lib/simple_token_authentication/entity.rb
|
|
@@ -170,6 +171,7 @@ files:
|
|
|
170
171
|
- spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
|
|
171
172
|
- spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
|
|
172
173
|
- spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb
|
|
174
|
+
- spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
|
|
173
175
|
- spec/lib/simple_token_authentication/configuration_spec.rb
|
|
174
176
|
- spec/lib/simple_token_authentication/entities_manager_spec.rb
|
|
175
177
|
- spec/lib/simple_token_authentication/entity_spec.rb
|
|
@@ -210,39 +212,40 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
210
212
|
version: '0'
|
|
211
213
|
requirements: []
|
|
212
214
|
rubyforge_project:
|
|
213
|
-
rubygems_version: 2.4.
|
|
215
|
+
rubygems_version: 2.4.4
|
|
214
216
|
signing_key:
|
|
215
217
|
specification_version: 4
|
|
216
218
|
summary: Simple (but safe) token authentication for Rails apps or API with Devise.
|
|
217
219
|
test_files:
|
|
220
|
+
- spec/configuration/header_names_option_spec.rb
|
|
221
|
+
- spec/configuration/sign_in_token_option_spec.rb
|
|
222
|
+
- spec/configuration/action_controller_callbacks_options_spec.rb
|
|
223
|
+
- spec/configuration/fallback_to_devise_option_spec.rb
|
|
224
|
+
- spec/support/spec_for_configuration_option_interface.rb
|
|
225
|
+
- spec/support/spec_for_token_comparator_interface.rb
|
|
226
|
+
- spec/support/spec_for_authentication_handler_interface.rb
|
|
227
|
+
- spec/support/spec_for_entities_manager_interface.rb
|
|
228
|
+
- spec/support/dummy_classes_helper.rb
|
|
229
|
+
- spec/support/specs_for_token_authentication_handler_interface.rb
|
|
230
|
+
- spec/support/spec_for_token_generator_interface.rb
|
|
231
|
+
- spec/support/spec_for_adapter.rb
|
|
232
|
+
- spec/support/spec_for_sign_in_handler_interface.rb
|
|
218
233
|
- spec/lib/simple_token_authentication_spec.rb
|
|
219
|
-
- spec/lib/simple_token_authentication/entities_manager_spec.rb
|
|
220
|
-
- spec/lib/simple_token_authentication/sign_in_handler_spec.rb
|
|
221
234
|
- spec/lib/simple_token_authentication/fallback_authentication_handler_spec.rb
|
|
222
|
-
- spec/lib/simple_token_authentication/token_comparator_spec.rb
|
|
223
|
-
- spec/lib/simple_token_authentication/configuration_spec.rb
|
|
224
235
|
- spec/lib/simple_token_authentication/token_generator_spec.rb
|
|
225
|
-
- spec/lib/simple_token_authentication/
|
|
226
|
-
- spec/lib/simple_token_authentication/
|
|
227
|
-
- spec/lib/simple_token_authentication/
|
|
228
|
-
- spec/lib/simple_token_authentication/errors_spec.rb
|
|
236
|
+
- spec/lib/simple_token_authentication/adapter_spec.rb
|
|
237
|
+
- spec/lib/simple_token_authentication/configuration_spec.rb
|
|
238
|
+
- spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
|
|
229
239
|
- spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
|
|
230
240
|
- spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
|
|
231
241
|
- spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb
|
|
242
|
+
- spec/lib/simple_token_authentication/acts_as_token_authentication_handler_spec.rb
|
|
243
|
+
- spec/lib/simple_token_authentication/token_authentication_handler_spec.rb
|
|
244
|
+
- spec/lib/simple_token_authentication/sign_in_handler_spec.rb
|
|
245
|
+
- spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb
|
|
246
|
+
- spec/lib/simple_token_authentication/errors_spec.rb
|
|
247
|
+
- spec/lib/simple_token_authentication/entities_manager_spec.rb
|
|
248
|
+
- spec/lib/simple_token_authentication/token_comparator_spec.rb
|
|
232
249
|
- spec/lib/simple_token_authentication/entity_spec.rb
|
|
233
|
-
- spec/lib/simple_token_authentication/adapter_spec.rb
|
|
234
|
-
- spec/configuration/action_controller_callbacks_options_spec.rb
|
|
235
|
-
- spec/configuration/header_names_option_spec.rb
|
|
236
|
-
- spec/configuration/fallback_to_devise_option_spec.rb
|
|
237
|
-
- spec/configuration/sign_in_token_option_spec.rb
|
|
238
250
|
- spec/spec_helper.rb
|
|
239
|
-
- spec/support/spec_for_authentication_handler_interface.rb
|
|
240
|
-
- spec/support/spec_for_entities_manager_interface.rb
|
|
241
|
-
- spec/support/spec_for_adapter.rb
|
|
242
|
-
- spec/support/specs_for_token_authentication_handler_interface.rb
|
|
243
|
-
- spec/support/spec_for_token_comparator_interface.rb
|
|
244
|
-
- spec/support/spec_for_configuration_option_interface.rb
|
|
245
|
-
- spec/support/spec_for_sign_in_handler_interface.rb
|
|
246
|
-
- spec/support/dummy_classes_helper.rb
|
|
247
|
-
- spec/support/spec_for_token_generator_interface.rb
|
|
248
251
|
has_rdoc:
|