simple_token_authentication 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +10 -0
  3. data/CHANGELOG.md +273 -0
  4. data/README.md +10 -7
  5. data/gemfiles/rails_4_devise_3.gemfile +7 -0
  6. data/gemfiles/ruby_1.9.3_rails_3.2.gemfile +9 -0
  7. data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +1 -2
  8. data/lib/simple_token_authentication/devise_fallback_handler.rb +1 -0
  9. data/lib/simple_token_authentication/exception_fallback_handler.rb +3 -1
  10. data/lib/simple_token_authentication/sign_in_handler.rb +2 -0
  11. data/lib/simple_token_authentication/token_authentication_handler.rb +4 -6
  12. data/lib/simple_token_authentication/token_comparator.rb +1 -0
  13. data/lib/simple_token_authentication/token_generator.rb +2 -0
  14. data/lib/simple_token_authentication/version.rb +1 -1
  15. data/spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb +7 -5
  16. data/spec/lib/simple_token_authentication/devise_fallback_handler_spec.rb +6 -4
  17. data/spec/lib/simple_token_authentication/exception_fallback_handler_spec.rb +4 -2
  18. data/spec/lib/simple_token_authentication/sign_in_handler_spec.rb +7 -5
  19. data/spec/lib/simple_token_authentication/token_authentication_handler_spec.rb +5 -58
  20. data/spec/lib/simple_token_authentication/token_comparator_spec.rb +3 -1
  21. data/spec/lib/simple_token_authentication/token_generator_spec.rb +3 -1
  22. data/spec/support/spec_for_authentication_handler_interface.rb +1 -3
  23. data/spec/support/spec_for_fallback_handler_interface.rb +5 -1
  24. data/spec/support/spec_for_sign_in_handler_interface.rb +5 -1
  25. data/spec/support/spec_for_token_comparator_interface.rb +5 -1
  26. data/spec/support/spec_for_token_generator_interface.rb +6 -1
  27. metadata +50 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b03d7c4181d9b49529232f123b1808777ae5ec90
4
- data.tar.gz: 4353f4f11e3460fdcff2fcb347493a4f99aad30d
3
+ metadata.gz: 19bdc71bf599ca78fa43979491d19560223b0470
4
+ data.tar.gz: e27f8869c38ebfa7401e33106696cf235dc087d3
5
5
  SHA512:
6
- metadata.gz: aa498468bc95566d8ca4617a224c46cff942c8a3b5aa1c017491ccf8acf2559b5658b4f1ca1b3ce0103c08078aa1cf7284f3f79f693e6c2b63753bc7f7688d38
7
- data.tar.gz: d5daa1bd3f516d6be6fe97c78d9898f24c7ec6f22558d3c908db3690ef0e15be4c444ee990f0b14288849e0fd4ab780b5375db56844b897c24edf22ffd5841c9
6
+ metadata.gz: ffb75249d436ef31b3979e5e704f086d8d7b4bdf42459a6bd3744a9e6528123030172e0d2cee85edd60de380a0a9fccb2a537d1cf30904ff4f5138820e777173
7
+ data.tar.gz: aa3d0ec11b451b69a0e486783ef4dda9ca97322b2bf5e7521c3f5456b3ddb492855b5f011fb72c9e31adb2b9dd10ae5797285770e5afe0306c44cbd187639927
data/Appraisals ADDED
@@ -0,0 +1,10 @@
1
+ appraise 'rails_4_devise_3' do
2
+ gem 'devise', '~> 3.2'
3
+ end
4
+
5
+ appraise 'ruby_1.9.3_rails_3.2' do
6
+ gem 'actionmailer', '>= 3.2.6', '< 4'
7
+ gem 'mime-types', '< 3'
8
+ gem 'tins', '< 1.7.0'
9
+ end
10
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,273 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [1.13.0] - 2016-04-20
7
+
8
+ ### Added
9
+
10
+ - Support for Devise 4
11
+ - This change log : )
12
+
13
+ ### Changed
14
+
15
+ - The [Travis CI build matrix][matrix] to improve the regression testing coverage
16
+ - The migration suggestion to make it safer - by @halilim
17
+
18
+ [matrix]: https://github.com/gonzalo-bulnes/simple_token_authentication/blob/v1.13.0/.travis.yml
19
+
20
+ ## [1.12.0] - 2016-01-06
21
+
22
+ ### Added
23
+
24
+ - [Rails Metal][rails-metal] support, using the public adapter interface : ) - @singfoom
25
+
26
+ [rails-metal]: http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal
27
+
28
+ ## [1.11.0] - 2015-12-14
29
+
30
+ ### Added
31
+
32
+ - Support for the [Devise custom finders][devise-custom-finders], _Simple Token Authentication_ now uses the customizable [`find_for_authentication`][find-for-authentication] method to retrieve records. - @lowjoel
33
+
34
+ ### Changed
35
+
36
+ - The license identifier format to match the [SPDX][spdx] guidelines
37
+
38
+ [devise-custom-finders]: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address#tell-devise-to-use-username-in-the-authentication_keys
39
+ [find-for-authentication]: https://github.com/plataformatec/devise/blob/v3.2/lib/devise/models/authenticatable.rb#L222-L243
40
+ [spdx]: https://spdx.org/licenses
41
+
42
+ ## [1.10.1] - 2015-11-10
43
+
44
+ ### Added
45
+
46
+ - The `NoAdapterAvailableError` now provides details about its cause and hints to solve it.
47
+ - A **Testing** section to the [`README`][testing] - John Mosesman
48
+
49
+ [testing]: https://github.com/gonzalo-bulnes/simple_token_authentication/tree/v1.12.0#testing
50
+
51
+ ### Fixed
52
+
53
+ - An unnecessary Ruby 2.0 requirement caused by an indirect dependency, let's keep backward compatibility as long as possible
54
+ - A couple of typos - @eliotsykes and @jtperreault
55
+
56
+ ## [1.10.0] - 2015-06-03
57
+
58
+ ### Added
59
+
60
+ - The **fallback** option, and support for the `fallback: :exception` which mimics the Devise behaviour when authentication fails
61
+
62
+ ### Changed
63
+
64
+ - The **fallback_to_devise** option to `fallback: :devise` and `fallback: :none` to get more flexibility and be able to support `fallback: :exception`. The older syntax is not officially deprecated, but using the **fallback** option is completely equivalent, and recommended.
65
+
66
+ ## [1.9.1] - 2015-04-28
67
+
68
+ ### Fixed
69
+
70
+ - The Mongoid adapter loading (which I did break when refactoring **v1.9.0**) - fixed with help from @krsyoung
71
+
72
+ ## [1.9.0] - 2015-04-24
73
+
74
+ ### Added
75
+
76
+ - More filters to scope `acts_as_token_authentication_handler_for`: `:if` and `:unless`, expected to be used with a Proc.
77
+ - Alias names for _token authenticatable_ classes can now be defined (in the token authentication handlers declarations): e.g. `acts_as_token_authentication_handler_for Vehicle::User, as: pilot`
78
+
79
+ ### Fixed
80
+
81
+ - Errors defining namespaced classes as _token authenticatable_, by allowing _aliases_ to be defined for them - with help from @joshblour, @jessesandford, @ivan-kolmychek and @bbuchalter
82
+
83
+ ## [1.8.0] - 2015-02-21
84
+
85
+ ### Added
86
+
87
+ - Custom **identifiers** option, using other fileds than `:email` to identify records is now possible. When this option is in use, the default _header names_ are updated acordingly. - @nicolo
88
+ - The **skip_devise_trackable** option - @nMustaki
89
+
90
+ ### Fixed
91
+
92
+ - A typo - @joelparkerhenderson
93
+
94
+ ## [1.7.0] - 2014-11-27
95
+
96
+ ### Added
97
+
98
+ - [Rails API][rails-api] support, controllers which inherit from `ActionController::API` can now be _token Authentication handlers_! - with help from @DeepAnchor
99
+ - Integration with [Devise case-insensitive keys][case], keys configured to be case insensitive in Devise are now automatically case insensitive in _Simple Token Authentication_ as well - @munkius
100
+ - Some important inline documentation
101
+
102
+ [case]: https://github.com/plataformatec/devise/blob/v3.4.1/lib/generators/templates/devise.rb#L45-L48
103
+ [rails-api]: https://github.com/rails-api/rails-api
104
+
105
+ ## [1.6.0] - 2014-10-24
106
+
107
+ ### Added
108
+
109
+ - Mongoid support, using the adapter interface : )
110
+
111
+ ## [1.5.2] - 2014-10-21
112
+
113
+ ### Added
114
+
115
+ - Public specification of the adapter interface
116
+ - Documentation about the new specs and how to contribute
117
+
118
+ ### Fixed
119
+
120
+ - The option **header_names** can now also be used to set a single custom header, either for the identifier (e.g. `user_email`) or the token (e.g. `user_token`). Previously, setting both at once was required.
121
+ - Memoization implementation error in several class methods. The bug didn't modify the public behaviour of the gem, but did create bunches of instances of `EntityManager` and `FallbackAuthenticationHandler` without necessity.
122
+
123
+ ### Removed
124
+
125
+ - The Cucumber features, in favor of faster and more flexible RSpec specs
126
+
127
+ ### Changed
128
+
129
+ - The internal syntax for the **fallabck_to_devise** option is now `fallback: :devise` and `fallback: :none` for added flexibility. The change is transparent for end users, and will only be made official if new fallback mechanisms are introduced.
130
+ - Refactored heavily the code base to allow the introduction of the RSpec test suite, contributing should now be a lot easier
131
+ - Optional dependencies (e.g. ActiveRecord, ActionController) are now encapsulated into independent adapters
132
+
133
+ ## [1.5.1] - 2014-09-18
134
+
135
+ ### Added
136
+
137
+ - Support for Devise 3.3 - @prabode
138
+
139
+ ## [1.5.0] - 2014-05-31
140
+
141
+ ### Added
142
+
143
+ - Support for multiple Devise scopes per _token authentication handler_, a single controller can now independently handle token authentication for `User` and `AdminUser` for example - @donbobka
144
+
145
+ ## [1.4.0] - 2014-05-24
146
+
147
+ ### Added
148
+
149
+ - Filters to scope `acts_as_token_authentication_handler_for`: `:only` and `:except`, so token authentication handling can be restricted to a set of controller actions - @donbobka
150
+
151
+ ### Changed
152
+
153
+ - The authentication token condition of existence for improved readability - @lenart
154
+
155
+ ## [1.3.0] - 2014-05-17
156
+
157
+ ### Added
158
+
159
+ - The **fallback_to_devise** option allows to disable the default fallback to Devise authentication when token authentication fails - @donbobka
160
+
161
+ ### Security
162
+
163
+ - Add documentation: the fallback to Devise MUST be disabled when CSRF protection is disabled (often the case for API controllers)
164
+
165
+ ## [1.2.1] - 2014-04-26
166
+
167
+ ### Fixed
168
+
169
+ - The integration with Devise trackable, the sign in count is no longer increased when token authentication succeeds - @adamniedzielski
170
+ - A typo - @nickveys
171
+
172
+ ## [1.2.0] - 2014-02-24
173
+
174
+ ### Added
175
+
176
+ - Configuration framework, allows _Simple Token Authentication_ to be configured using an initializer - @krsyoung and @joel
177
+ - The **sign_in_token** option allows to create persistent sessions when token authentiation succeeds (can be used to sign in users from a link in an e-mail, for example) - @krsyoung
178
+ - The **header_names** option allows to define custom names for HTTP headers, e.g. `X-User-Authentication-Token`
179
+
180
+ ## [1.1.1] - 2014-02-20
181
+
182
+ ### Fixed
183
+
184
+ - The Travis CI build is now testing the correct release, I did make a mistake when releasing **v1.1.0**
185
+
186
+ ## [1.1.0] - 2014-02-20
187
+
188
+ ### Added
189
+
190
+ - Add support for multiple _token authenticatable_ classes, any model known to Devise can now be made _token authenticatable_, not only `User` - @invernizzi
191
+
192
+
193
+ ## [1.0.1] - 2014-01-26
194
+
195
+ ### Changed
196
+
197
+ - Nothing, this is a replacement for **v1.0.0** (because I messed up with Rubygems)
198
+
199
+ ## [1.0.0] - 2014-01-26 [YANKED]
200
+
201
+ ### Added
202
+
203
+ - A test suite, using Cucumber : )
204
+
205
+ ## [1.0.0.pre.5] - 2014-01-09
206
+
207
+ ### Fixed
208
+
209
+ - Authentication was required as soon as the gem was loaded - reported by @pdobb and @AhmedAttyah
210
+
211
+ ## Changed
212
+
213
+ - Use the Bundler-friendly format for version numbers instead of follwing strictly the Semantic Versionning specification
214
+
215
+ ## [1.0.0-beta.4] - 2013-12-26
216
+
217
+ ### Fixed
218
+
219
+ - The user record is now fetched using `find_by_email` when `find_by` is not present (Rails 3.2) - with help from @AhmedAttyah
220
+
221
+ ## [1.0.0-beta.3] - 2013-12-17
222
+
223
+ ### Fixed
224
+
225
+ - Redundant dependencies: _Simple Token Authentication_ only depends on ActionMailer and ActiveRecord, not Rails
226
+
227
+ ## [1.0.0-beta.2] - 2013-12-16
228
+
229
+ ### Added
230
+
231
+ - Explicit dependency on Devise
232
+
233
+ ## 1.0.0-beta - 2013-12-16
234
+
235
+ ### Added
236
+
237
+ - Documentation
238
+
239
+ ## Previously
240
+
241
+ This [gist][gist] did refactor the Jose Valim's code into an `ActiveSupport::Concern`.
242
+
243
+ [gist]: https://gist.github.com/gonzalo-bulnes/7659739
244
+ [1.13.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.12.0...v1.13.0
245
+ [1.12.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.11.0...v1.12.0
246
+ [1.11.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.10.1...v1.11.0
247
+ [1.10.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.10.0...v1.10.1
248
+ [1.10.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.9.1...v1.10.0
249
+ [1.9.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.9.0...v1.9.1
250
+ [1.9.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.8.0...v1.9.0
251
+ [1.8.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.7.0...v1.8.0
252
+ [1.7.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.6.0...v1.7.0
253
+ [1.6.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.5.2...v1.6.0
254
+ [1.5.2]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.5.1...v1.5.2
255
+ [1.5.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.5.0...v1.5.1
256
+ [1.5.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.4.0...v1.5.0
257
+ [1.4.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.3.0...v1.4.0
258
+ [1.3.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.2.1...v1.3.0
259
+ [1.2.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.2.0...v1.2.1
260
+ [1.2.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.1.1...v1.2.0
261
+ [1.1.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.1.0...v1.1.1
262
+ [1.1.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.1...v1.1.0
263
+ [1.0.1]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0...v1.0.1
264
+ [1.0.0]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0.pre.5...v1.0.0
265
+ [1.0.0.pre.5]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0-beta.4...v1.0.0.pre.5
266
+ [1.0.0-beta.4]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0-beta.3...v1.0.0-beta.4
267
+ [1.0.0-beta.3]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0-beta.2...v1.0.0-beta.3
268
+ [1.0.0-beta.2]: https://github.com/gonzalo-bulnes/simple_token_authentication/compare/v1.0.0-beta...v1.0.0-beta.2
269
+
270
+ ## Inspiration
271
+
272
+ Thanks to @nTraum for pointing me at http://keepachangelog.com and to @olivierlacan for writing it in the first place!
273
+
data/README.md CHANGED
@@ -10,7 +10,7 @@ Simple Token Authentication
10
10
 
11
11
  Token authentication support has been removed from [Devise][devise] for security reasons. In [this gist][original-gist], Devise's [José Valim][josevalim] explains how token authentication should be performed in order to remain safe.
12
12
 
13
- This gem packages the content of the gist.
13
+ This gem packages the content of the gist and provides a set of convenient options for increased flexibility.
14
14
 
15
15
  [devise]: https://github.com/plataformatec/devise
16
16
  [original-gist]: https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
@@ -58,10 +58,10 @@ class User < ActiveRecord::Base
58
58
  end
59
59
  ```
60
60
 
61
- If the model or models you chose have no `:authentication_token` attribute, add them one (with an index):
61
+ If the model or models you chose have no `:authentication_token` attribute, add them one (with a unique index):
62
62
 
63
63
  ```bash
64
- rails g migration add_authentication_token_to_users authentication_token:string:index
64
+ rails g migration add_authentication_token_to_users "authentication_token:string{30}:uniq"
65
65
  rake db:migrate
66
66
  ```
67
67
 
@@ -284,18 +284,19 @@ Any question? Please don't hesitate to open a new issue to get help. I keep ques
284
284
  [open-questions]: https://github.com/gonzalo-bulnes/simple_token_authentication/issues?labels=question&page=1&state=open
285
285
  [faq]: https://github.com/gonzalo-bulnes/simple_token_authentication/issues?direction=desc&labels=question&page=1&sort=comments&state=closed
286
286
 
287
- ### Changelog
287
+ ### Change Log
288
288
 
289
- Releases are commented to provide a brief [changelog][changelog].
289
+ Releases are commented to provide a [brief change log][releases], details can be found in the [`CHANGELOG`][changelog] file.
290
290
 
291
- [changelog]: https://github.com/gonzalo-bulnes/simple_token_authentication/releases
291
+ [releases]: https://github.com/gonzalo-bulnes/simple_token_authentication/releases
292
+ [changelog]: ./CHANGELOG.md
292
293
 
293
294
  Development
294
295
  -----------
295
296
 
296
297
  ### Testing and documentation
297
298
 
298
- This gem development has been test-driven since `v1.0.0`. Until `v1.5.1`, the gem behaviour was described using [Cucumber][cucumber] and [RSpec][rspec] in a dummy app generated by [Aruba][aruba]. Since `v1.5.2` it is described using Rspec alone.
299
+ This gem development has been test-driven since `v1.0.0`. Until `v1.5.1`, the gem behaviour was described using [Cucumber][cucumber] and [RSpec][rspec] in a dummy app generated by [Aruba][aruba]. Since `v1.5.2` it is described using Rspec alone and [Appraisal][appraisal] is used since `v1.13.0` for [regression testing][regression].
299
300
 
300
301
  RSpec [tags][tags] are used to categorize the spec examples.
301
302
 
@@ -305,8 +306,10 @@ The `private` or `protected` specs are written for development purpose only. Bec
305
306
 
306
307
  Run `rake spec:public` to print the gem public documentation.
307
308
 
309
+ [appraisal]: https://github.com/thoughtbot/appraisal
308
310
  [aruba]: https://github.com/cucumber/aruba
309
311
  [cucumber]: https://github.com/cucumber/cucumber-rails
312
+ [regression]: https://github.com/gonzalo-bulnes/simple_token_authentication/wiki/Regression-Testing
310
313
  [rspec]: https://www.relishapp.com/rspec/rspec-rails/docs
311
314
  [tags]: https://www.relishapp.com/rspec/rspec-core/v/3-1/docs/command-line/tag-option
312
315
  [travis]: https://travis-ci.org/gonzalo-bulnes/simple_token_authentication/builds
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "devise", "~> 3.2"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionmailer", ">= 3.2.6", "< 4"
6
+ gem "mime-types", "< 3"
7
+ gem "tins", "< 1.7.0"
8
+
9
+ gemspec :path => "../"
@@ -35,9 +35,8 @@ module SimpleTokenAuthentication
35
35
  self.class.where(authentication_token: token).count == 0
36
36
  end
37
37
 
38
- # Private: Get one (always the same) object which behaves as a token generator
39
38
  def token_generator
40
- @token_generator ||= TokenGenerator.new
39
+ TokenGenerator.instance
41
40
  end
42
41
 
43
42
  module ClassMethods
@@ -1,5 +1,6 @@
1
1
  module SimpleTokenAuthentication
2
2
  class DeviseFallbackHandler
3
+ include Singleton
3
4
 
4
5
  # Fallback to the Devise authentication strategies.
5
6
  def fallback!(controller, entity)
@@ -1,6 +1,8 @@
1
1
  module SimpleTokenAuthentication
2
2
  class ExceptionFallbackHandler
3
- # Notifies the failure of authentication to Warden in the same DEvise does.
3
+ include Singleton
4
+
5
+ # Notifies the failure of authentication to Warden in the same Devise does.
4
6
  # Does result in an HTTP 401 response in a Devise context.
5
7
  def fallback!(controller, entity)
6
8
  throw(:warden, scope: entity.name_underscore.to_sym) if controller.send("current_#{entity.name_underscore}").nil?
@@ -1,5 +1,7 @@
1
1
  module SimpleTokenAuthentication
2
2
  class SignInHandler
3
+ include Singleton
4
+
3
5
  # Devise sign in is performed through a controller
4
6
  # which includes Devise::Controllers::SignInOut
5
7
  def sign_in(controller, record, *args)
@@ -74,14 +74,12 @@ module SimpleTokenAuthentication
74
74
  identifier_value
75
75
  end
76
76
 
77
- # Private: Get one (always the same) object which behaves as a token comprator
78
77
  def token_comparator
79
- @@token_comparator ||= TokenComparator.new
78
+ TokenComparator.instance
80
79
  end
81
80
 
82
- # Private: Get one (always the same) object which behaves as a sign in handler
83
81
  def sign_in_handler
84
- @@sign_in_handler ||= SignInHandler.new
82
+ SignInHandler.instance
85
83
  end
86
84
 
87
85
  module ClassMethods
@@ -114,9 +112,9 @@ module SimpleTokenAuthentication
114
112
  class_variable_get(:@@fallback_authentication_handler)
115
113
  else
116
114
  if options[:fallback] == :exception
117
- class_variable_set(:@@fallback_authentication_handler, ExceptionFallbackHandler.new)
115
+ class_variable_set(:@@fallback_authentication_handler, ExceptionFallbackHandler.instance)
118
116
  else
119
- class_variable_set(:@@fallback_authentication_handler, DeviseFallbackHandler.new)
117
+ class_variable_set(:@@fallback_authentication_handler, DeviseFallbackHandler.instance)
120
118
  end
121
119
  end
122
120
  end
@@ -2,6 +2,7 @@ require 'devise'
2
2
 
3
3
  module SimpleTokenAuthentication
4
4
  class TokenComparator
5
+ include Singleton
5
6
 
6
7
  # Compare two String instances
7
8
  #
@@ -2,6 +2,8 @@ require 'devise'
2
2
 
3
3
  module SimpleTokenAuthentication
4
4
  class TokenGenerator
5
+ include Singleton
6
+
5
7
  def generate_token
6
8
  Devise.friendly_token
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleTokenAuthentication
2
- VERSION = "1.12.0"
2
+ VERSION = "1.13.0"
3
3
  end
@@ -2,8 +2,10 @@ require 'spec_helper'
2
2
 
3
3
 
4
4
  class DummyTokenGenerator
5
- def initialize(args={})
6
- @tokens_to_be_generated = args[:tokens_to_be_generated]
5
+ include Singleton
6
+
7
+ def tokens_to_be_generated=(tokens)
8
+ @tokens_to_be_generated = tokens
7
9
  end
8
10
 
9
11
  def generate_token
@@ -69,8 +71,6 @@ describe 'A token authenticatable class (or one of its children)' do
69
71
 
70
72
  def initialize(args={})
71
73
  @authentication_token = args[:authentication_token]
72
- @token_generator = DummyTokenGenerator.new(
73
- tokens_to_be_generated: TOKENS_IN_USE + ['Dist1nCt-Tok3N'])
74
74
  end
75
75
 
76
76
  def authentication_token=(value)
@@ -87,7 +87,9 @@ describe 'A token authenticatable class (or one of its children)' do
87
87
  end
88
88
 
89
89
  def token_generator
90
- @token_generator
90
+ token_generator = DummyTokenGenerator.instance
91
+ token_generator.tokens_to_be_generated = TOKENS_IN_USE + ['Dist1nCt-Tok3N']
92
+ token_generator
91
93
  end
92
94
  end
93
95
  end
@@ -2,7 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe SimpleTokenAuthentication::DeviseFallbackHandler do
4
4
 
5
- it_behaves_like 'an authentication handler'
5
+ let(:devise_fallback_handler) { SimpleTokenAuthentication::DeviseFallbackHandler.instance }
6
+
7
+ it_behaves_like 'an authentication handler', SimpleTokenAuthentication::DeviseFallbackHandler.instance
6
8
 
7
9
  it_behaves_like 'a fallback handler'
8
10
 
@@ -17,7 +19,7 @@ describe SimpleTokenAuthentication::DeviseFallbackHandler do
17
19
 
18
20
  # delegating consists in sending the message
19
21
  expect(controller).to receive(:authenticate_user!)
20
- response = subject.authenticate_entity!(controller, entity)
22
+ response = devise_fallback_handler.authenticate_entity!(controller, entity)
21
23
 
22
24
  # and returning the response
23
25
  expect(response).to eq 'Devise response.'
@@ -31,9 +33,9 @@ describe SimpleTokenAuthentication::DeviseFallbackHandler do
31
33
  allow(@entity).to receive_message_chain(:name_underscore).and_return('entity')
32
34
  controller = double()
33
35
 
34
- expect(subject).to receive(:authenticate_entity!).with(controller, entity)
36
+ expect(devise_fallback_handler).to receive(:authenticate_entity!).with(controller, entity)
35
37
 
36
- subject.send(:fallback!, controller, entity)
38
+ devise_fallback_handler.send(:fallback!, controller, entity)
37
39
  end
38
40
  end
39
41
  end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe SimpleTokenAuthentication::ExceptionFallbackHandler do
4
4
 
5
+ let(:exception_fallback_handler) { SimpleTokenAuthentication::ExceptionFallbackHandler.instance }
6
+
5
7
  it_behaves_like 'a fallback handler'
6
8
 
7
9
  describe '#fallback!' do
@@ -17,7 +19,7 @@ describe SimpleTokenAuthentication::ExceptionFallbackHandler do
17
19
  end
18
20
 
19
21
  it 'delegates exception throwing to Warden', private: true do
20
- expect{ subject.fallback!(@controller, @entity) }.to throw_symbol(:warden, scope: :entity)
22
+ expect{ exception_fallback_handler.fallback!(@controller, @entity) }.to throw_symbol(:warden, scope: :entity)
21
23
  end
22
24
  end
23
25
 
@@ -32,7 +34,7 @@ describe SimpleTokenAuthentication::ExceptionFallbackHandler do
32
34
  end
33
35
 
34
36
  it 'does not throw any exception', private: true do
35
- expect{ subject.fallback!(@controller, @entity) }.not_to throw_symbol(:warden, scope: :entity)
37
+ expect{ exception_fallback_handler.fallback!(@controller, @entity) }.not_to throw_symbol(:warden, scope: :entity)
36
38
  end
37
39
  end
38
40
  end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe SimpleTokenAuthentication::SignInHandler do
4
4
 
5
+ let(:sign_in_handler) { SimpleTokenAuthentication::SignInHandler.instance }
6
+
5
7
  it_behaves_like 'a sign in handler'
6
8
 
7
9
  describe '#sign_in' do
@@ -13,7 +15,7 @@ describe SimpleTokenAuthentication::SignInHandler do
13
15
 
14
16
  # delegating consists in sending the message
15
17
  expect(controller).to receive(:sign_in)
16
- response = subject.sign_in(controller, :record, option: 'some_value')
18
+ response = sign_in_handler.sign_in(controller, :record, option: 'some_value')
17
19
 
18
20
  # and returning the response
19
21
  expect(response).to eq 'Devise response.'
@@ -24,8 +26,8 @@ describe SimpleTokenAuthentication::SignInHandler do
24
26
  allow(controller).to receive(:sign_in).with(:record)
25
27
  allow(controller).to receive(:integrate_with_devise_trackable!)
26
28
 
27
- expect(subject).to receive(:integrate_with_devise_trackable!).with(controller)
28
- subject.sign_in(controller, :record)
29
+ expect(sign_in_handler).to receive(:integrate_with_devise_trackable!).with(controller)
30
+ sign_in_handler.sign_in(controller, :record)
29
31
  end
30
32
  end
31
33
 
@@ -43,7 +45,7 @@ describe SimpleTokenAuthentication::SignInHandler do
43
45
  allow(controller).to receive(:env).and_return(env)
44
46
  expect(env).to receive(:[]=).with('devise.skip_trackable', true)
45
47
 
46
- subject.send :integrate_with_devise_trackable!, controller
48
+ sign_in_handler.send :integrate_with_devise_trackable!, controller
47
49
  end
48
50
  end
49
51
 
@@ -60,7 +62,7 @@ describe SimpleTokenAuthentication::SignInHandler do
60
62
  allow(controller).to receive(:env).and_return(env)
61
63
  expect(env).to receive(:[]=).with('devise.skip_trackable', false)
62
64
 
63
- subject.send :integrate_with_devise_trackable!, controller
65
+ sign_in_handler.send :integrate_with_devise_trackable!, controller
64
66
  end
65
67
  end
66
68
  end
@@ -11,7 +11,7 @@ describe 'Any class which includes SimpleTokenAuthentication::TokenAuthenticatio
11
11
  SimpleTokenAuthentication.send(:remove_const, :SomeClass)
12
12
  end
13
13
 
14
- it_behaves_like 'a token authentication handler'
14
+ it_behaves_like 'a token authentication handler', lambda { described_class.new }
15
15
 
16
16
  let(:subject) { described_class }
17
17
 
@@ -112,44 +112,14 @@ describe 'Any class which includes SimpleTokenAuthentication::TokenAuthenticatio
112
112
 
113
113
  describe '.fallback_handler' do
114
114
 
115
- before(:each) do
116
- allow(SimpleTokenAuthentication::DeviseFallbackHandler).to receive(:new)
117
- .and_return('a DeviseFallbackHandler instance')
118
- allow(SimpleTokenAuthentication::ExceptionFallbackHandler).to receive(:new)
119
- .and_return('an ExceptionFallbackHandler instance')
120
- end
121
-
122
115
  context 'when the Devise fallback is enabled', fallback_option: true do
123
116
 
124
117
  before(:each) do
125
118
  @options = { fallback: :devise }
126
119
  end
127
120
 
128
- context 'when called for the first time' do
129
-
130
- it 'creates a new DeviseFallbackHandler instance', private: true do
131
- expect(SimpleTokenAuthentication::DeviseFallbackHandler).to receive(:new)
132
- expect(subject.send(:fallback_handler, @options)).to eq 'a DeviseFallbackHandler instance'
133
- end
134
- end
135
-
136
- context 'when a DeviseFallbackHandler instance was already created' do
137
-
138
- before(:each) do
139
- subject.send(:fallback_handler, @options)
140
- # let's make any new DeviseFallbackHandler distinct from the first
141
- allow(SimpleTokenAuthentication::DeviseFallbackHandler).to receive(:new)
142
- .and_return('another DeviseFallbackHandler instance')
143
- end
144
-
145
- it 'returns that instance', private: true do
146
- expect(subject.send(:fallback_handler, @options)).to eq 'a DeviseFallbackHandler instance'
147
- end
148
-
149
- it 'does not create a new DeviseFallbackHandler instance', private: true do
150
- expect(SimpleTokenAuthentication::DeviseFallbackHandler).not_to receive(:new)
151
- expect(subject.send(:fallback_handler, @options)).not_to eq 'another DeviseFallbackHandler instance'
152
- end
121
+ it 'returns a DeviseFallbackHandler instance', private: true do
122
+ expect(subject.send(:fallback_handler, @options)).to be_kind_of SimpleTokenAuthentication::DeviseFallbackHandler
153
123
  end
154
124
  end
155
125
 
@@ -159,31 +129,8 @@ describe 'Any class which includes SimpleTokenAuthentication::TokenAuthenticatio
159
129
  @options = { fallback: :exception }
160
130
  end
161
131
 
162
- context 'when called for the first time' do
163
-
164
- it 'creates a new ExceptionFallbackHandler instance', private: true do
165
- expect(SimpleTokenAuthentication::ExceptionFallbackHandler).to receive(:new)
166
- expect(subject.send(:fallback_handler, @options)).to eq 'an ExceptionFallbackHandler instance'
167
- end
168
- end
169
-
170
- context 'when a ExceptionFallbackHandler instance was already created' do
171
-
172
- before(:each) do
173
- subject.send(:fallback_handler, @options)
174
- # let's make any new ExceptionFallbackHandler distinct from the first
175
- allow(SimpleTokenAuthentication::ExceptionFallbackHandler).to receive(:new)
176
- .and_return('another ExceptionFallbackHandler instance')
177
- end
178
-
179
- it 'returns that instance', private: true do
180
- expect(subject.send(:fallback_handler, @options)).to eq 'an ExceptionFallbackHandler instance'
181
- end
182
-
183
- it 'does not create a new ExceptionFallbackHandler instance', private: true do
184
- expect(SimpleTokenAuthentication::ExceptionFallbackHandler).not_to receive(:new)
185
- expect(subject.send(:fallback_handler, @options)).not_to eq 'another ExceptionFallbackHandler instance'
186
- end
132
+ it 'returns a ExceptionFallbackHandler instance', private: true do
133
+ expect(subject.send(:fallback_handler, @options)).to be_kind_of SimpleTokenAuthentication::ExceptionFallbackHandler
187
134
  end
188
135
  end
189
136
  end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe SimpleTokenAuthentication::TokenComparator do
4
4
 
5
+ let(:token_comparator) { described_class.instance }
6
+
5
7
  it_behaves_like 'a token comparator'
6
8
 
7
9
  it 'delegates token comparison to Devise.secure_compare', private: true do
@@ -11,7 +13,7 @@ describe SimpleTokenAuthentication::TokenComparator do
11
13
 
12
14
  # delegating consists in sending the message
13
15
  expect(Devise).to receive(:secure_compare)
14
- response = subject.compare('A_raNd0MtoKeN', 'ano4heR-Tok3n')
16
+ response = token_comparator.compare('A_raNd0MtoKeN', 'ano4heR-Tok3n')
15
17
 
16
18
  # and returning the response
17
19
  expect(response).to eq 'Devise.secure_compare response.'
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe SimpleTokenAuthentication::TokenGenerator do
4
4
 
5
+ let(:token_generator) { SimpleTokenAuthentication::TokenGenerator.instance }
6
+
5
7
  it_behaves_like 'a token generator'
6
8
 
7
9
  it 'delegates token generation to Devise.friendly_token', private: true do
@@ -11,7 +13,7 @@ describe SimpleTokenAuthentication::TokenGenerator do
11
13
 
12
14
  # delegating consists in sending the message
13
15
  expect(Devise).to receive(:friendly_token)
14
- response = subject.generate_token
16
+ response = token_generator.generate_token
15
17
 
16
18
  # and returning the response
17
19
  expect(response).to eq 'FRi3ndlY_TokeN'
@@ -1,6 +1,4 @@
1
- RSpec.shared_examples 'an authentication handler' do
2
-
3
- let(:authentication_handler) { described_class.new() }
1
+ RSpec.shared_examples 'an authentication handler' do |authentication_handler|
4
2
 
5
3
  it 'responds to :authenticate_entity!', private: true do
6
4
  expect(authentication_handler).to respond_to :authenticate_entity!
@@ -1,8 +1,12 @@
1
1
  RSpec.shared_examples 'a fallback handler' do
2
2
 
3
- let(:fallback_handler) { described_class.new() }
3
+ let(:fallback_handler) { described_class.instance }
4
4
 
5
5
  it 'responds to :fallback!', private: true do
6
6
  expect(fallback_handler).to respond_to :fallback!
7
7
  end
8
+
9
+ it 'is a kind of Singleton', private: true do
10
+ expect(fallback_handler).to be_kind_of(Singleton)
11
+ end
8
12
  end
@@ -1,8 +1,12 @@
1
1
  RSpec.shared_examples 'a sign in handler' do
2
2
 
3
- let(:sign_in_handler) { described_class.new() }
3
+ let(:sign_in_handler) { described_class.instance }
4
4
 
5
5
  it 'responds to :sign_in', private: true do
6
6
  expect(sign_in_handler).to respond_to :sign_in
7
7
  end
8
+
9
+ it 'is a kind of Singleton', private: true do
10
+ expect(sign_in_handler).to be_kind_of(Singleton)
11
+ end
8
12
  end
@@ -1,8 +1,12 @@
1
1
  RSpec.shared_examples 'a token comparator' do
2
2
 
3
- let(:token_comparator) { described_class.new() }
3
+ let(:token_comparator) { described_class.instance }
4
4
 
5
5
  it 'responds to :compare', public: true do
6
6
  expect(token_comparator).to respond_to :compare
7
7
  end
8
+
9
+ it 'is a kind of Singleton', private: true do
10
+ expect(token_comparator).to be_kind_of(Singleton)
11
+ end
8
12
  end
@@ -1,8 +1,13 @@
1
1
  RSpec.shared_examples 'a token generator' do
2
2
 
3
- let(:token_generator) { described_class.new() }
3
+ let(:token_generator) { described_class.instance }
4
4
 
5
5
  it 'responds to :generate_token', public: true do
6
6
  expect(token_generator).to respond_to :generate_token
7
7
  end
8
+
9
+ it 'is a kind of Singleton', public: true do
10
+ expect(token_generator).to be_kind_of(Singleton)
11
+ end
8
12
  end
13
+
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.12.0
4
+ version: 1.13.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: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -54,16 +54,22 @@ dependencies:
54
54
  name: devise
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: '3.2'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '5'
60
63
  type: :runtime
61
64
  prerelease: false
62
65
  version_requirements: !ruby/object:Gem::Requirement
63
66
  requirements:
64
- - - "~>"
67
+ - - ">="
65
68
  - !ruby/object:Gem::Version
66
69
  version: '3.2'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '5'
67
73
  - !ruby/object:Gem::Dependency
68
74
  name: rspec
69
75
  requirement: !ruby/object:Gem::Requirement
@@ -133,19 +139,19 @@ dependencies:
133
139
  - !ruby/object:Gem::Version
134
140
  version: '5'
135
141
  - !ruby/object:Gem::Dependency
136
- name: tins
142
+ name: appraisal
137
143
  requirement: !ruby/object:Gem::Requirement
138
144
  requirements:
139
- - - "<"
145
+ - - "~>"
140
146
  - !ruby/object:Gem::Version
141
- version: 1.7.0
147
+ version: '2.0'
142
148
  type: :development
143
149
  prerelease: false
144
150
  version_requirements: !ruby/object:Gem::Requirement
145
151
  requirements:
146
- - - "<"
152
+ - - "~>"
147
153
  - !ruby/object:Gem::Version
148
- version: 1.7.0
154
+ version: '2.0'
149
155
  description:
150
156
  email:
151
157
  - gon.bulnes@gmail.com
@@ -153,10 +159,14 @@ executables: []
153
159
  extensions: []
154
160
  extra_rdoc_files: []
155
161
  files:
162
+ - Appraisals
163
+ - CHANGELOG.md
156
164
  - LICENSE
157
165
  - README.md
158
166
  - Rakefile
159
167
  - doc/README.md
168
+ - gemfiles/rails_4_devise_3.gemfile
169
+ - gemfiles/ruby_1.9.3_rails_3.2.gemfile
160
170
  - lib/simple_token_authentication.rb
161
171
  - lib/simple_token_authentication/acts_as_token_authenticatable.rb
162
172
  - lib/simple_token_authentication/acts_as_token_authentication_handler.rb
@@ -237,39 +247,42 @@ signing_key:
237
247
  specification_version: 4
238
248
  summary: Simple (but safe) token authentication for Rails apps or API with Devise.
239
249
  test_files:
240
- - spec/spec_helper.rb
241
- - spec/support/spec_for_authentication_handler_interface.rb
242
- - spec/support/spec_for_token_comparator_interface.rb
243
- - spec/support/spec_for_token_generator_interface.rb
244
- - spec/support/specs_for_token_authentication_handler_interface.rb
245
- - spec/support/spec_for_entities_manager_interface.rb
246
- - spec/support/spec_for_configuration_option_interface.rb
247
- - spec/support/spec_for_adapter.rb
248
- - spec/support/dummy_classes_helper.rb
249
- - spec/support/spec_for_fallback_handler_interface.rb
250
- - spec/support/spec_for_sign_in_handler_interface.rb
251
- - spec/configuration/skip_devise_trackable_option_spec.rb
252
- - spec/configuration/sign_in_token_option_spec.rb
250
+ - spec/configuration/action_controller_callbacks_options_spec.rb
253
251
  - spec/configuration/fallback_to_devise_option_spec.rb
254
252
  - spec/configuration/header_names_option_spec.rb
255
- - spec/configuration/action_controller_callbacks_options_spec.rb
256
- - spec/lib/simple_token_authentication_spec.rb
257
- - spec/lib/simple_token_authentication/devise_fallback_handler_spec.rb
258
- - spec/lib/simple_token_authentication/entities_manager_spec.rb
259
- - spec/lib/simple_token_authentication/sign_in_handler_spec.rb
260
- - spec/lib/simple_token_authentication/adapter_spec.rb
261
- - spec/lib/simple_token_authentication/token_generator_spec.rb
262
- - spec/lib/simple_token_authentication/exception_fallback_handler_spec.rb
253
+ - spec/configuration/sign_in_token_option_spec.rb
254
+ - spec/configuration/skip_devise_trackable_option_spec.rb
255
+ - spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb
263
256
  - spec/lib/simple_token_authentication/acts_as_token_authentication_handler_spec.rb
264
- - spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
257
+ - spec/lib/simple_token_authentication/adapter_spec.rb
258
+ - spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
259
+ - spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
265
260
  - spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb
261
+ - spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
266
262
  - spec/lib/simple_token_authentication/adapters/rails_metal_adapter_spec.rb
267
- - spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
268
- - spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
269
- - spec/lib/simple_token_authentication/errors_spec.rb
270
- - spec/lib/simple_token_authentication/token_comparator_spec.rb
271
- - spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb
272
- - spec/lib/simple_token_authentication/entity_spec.rb
273
263
  - spec/lib/simple_token_authentication/configuration_spec.rb
264
+ - spec/lib/simple_token_authentication/devise_fallback_handler_spec.rb
265
+ - spec/lib/simple_token_authentication/entities_manager_spec.rb
266
+ - spec/lib/simple_token_authentication/entity_spec.rb
267
+ - spec/lib/simple_token_authentication/errors_spec.rb
268
+ - spec/lib/simple_token_authentication/exception_fallback_handler_spec.rb
269
+ - spec/lib/simple_token_authentication/sign_in_handler_spec.rb
274
270
  - spec/lib/simple_token_authentication/token_authentication_handler_spec.rb
271
+ - spec/lib/simple_token_authentication/token_comparator_spec.rb
272
+ - spec/lib/simple_token_authentication/token_generator_spec.rb
273
+ - spec/lib/simple_token_authentication_spec.rb
274
+ - spec/spec_helper.rb
275
+ - spec/support/dummy_classes_helper.rb
276
+ - spec/support/spec_for_adapter.rb
277
+ - spec/support/spec_for_authentication_handler_interface.rb
278
+ - spec/support/spec_for_configuration_option_interface.rb
279
+ - spec/support/spec_for_entities_manager_interface.rb
280
+ - spec/support/spec_for_fallback_handler_interface.rb
281
+ - spec/support/spec_for_sign_in_handler_interface.rb
282
+ - spec/support/spec_for_token_comparator_interface.rb
283
+ - spec/support/spec_for_token_generator_interface.rb
284
+ - spec/support/specs_for_token_authentication_handler_interface.rb
285
+ - gemfiles/rails_4_devise_3.gemfile
286
+ - gemfiles/ruby_1.9.3_rails_3.2.gemfile
287
+ - Appraisals
275
288
  has_rdoc: