authenticate 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +14 -2
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -3
- data/README.md +103 -30
- data/app/controllers/authenticate/authenticate_controller.rb +2 -0
- data/app/controllers/authenticate/passwords_controller.rb +1 -1
- data/app/controllers/authenticate/sessions_controller.rb +1 -1
- data/app/controllers/authenticate/users_controller.rb +1 -1
- data/app/views/passwords/new.html.erb +4 -0
- data/authenticate.gemspec +8 -10
- data/config/locales/authenticate.en.yml +9 -1
- data/gemfiles/rails42.gemfile +12 -0
- data/lib/authenticate/callbacks/authenticatable.rb +4 -1
- data/lib/authenticate/callbacks/brute_force.rb +2 -1
- data/lib/authenticate/callbacks/lifetimed.rb +2 -2
- data/lib/authenticate/callbacks/timeoutable.rb +1 -1
- data/lib/authenticate/callbacks/trackable.rb +1 -1
- data/lib/authenticate/controller.rb +12 -3
- data/lib/authenticate/debug.rb +8 -3
- data/lib/authenticate/engine.rb +3 -0
- data/lib/authenticate/lifecycle.rb +25 -16
- data/lib/authenticate/model/brute_force.rb +7 -3
- data/lib/authenticate/model/db_password.rb +12 -14
- data/lib/authenticate/model/email.rb +1 -1
- data/lib/authenticate/model/lifetimed.rb +7 -8
- data/lib/authenticate/model/password_reset.rb +12 -5
- data/lib/authenticate/model/timeoutable.rb +9 -12
- data/lib/authenticate/model/trackable.rb +5 -2
- data/lib/authenticate/model/username.rb +0 -8
- data/lib/authenticate/modules.rb +3 -2
- data/lib/authenticate/session.rb +7 -7
- data/lib/authenticate/version.rb +1 -1
- data/spec/dummy/config/initializers/authenticate.rb +3 -2
- data/spec/factories/users.rb +11 -1
- data/spec/model/db_password_spec.rb +33 -0
- data/spec/model/email_spec.rb +25 -0
- data/spec/model/lifetimed_spec.rb +35 -0
- data/spec/model/password_reset_spec.rb +81 -0
- data/spec/model/session_spec.rb +0 -6
- data/spec/model/timeoutable_spec.rb +20 -0
- data/spec/model/trackable_spec.rb +56 -0
- data/spec/spec_helper.rb +6 -0
- metadata +18 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee7e6d853c9b5bbd628cff1a668915f044763ee2
|
4
|
+
data.tar.gz: eed8ffa17e581d9e78f7a9a1de4c7256f5aab006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e5a156bd35d223e8e513efe3224e76ccd9f11b1df4b4215c72ed88d34a53b0f00d2329beb29681981b4ba4f1c3c1625e5ca3e5ff5ee9966d8d3225cdb9bf23b
|
7
|
+
data.tar.gz: 21d14b3ceac3b4a6e99794ba9e5ee8adb36e2a9f513d75d9f156116a77400b252b869e10004181b9ca3de23fba12977031261fb28fcf91171866efa302f6f5c4
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
# Authenticate Changelog
|
2
2
|
|
3
3
|
|
4
|
+
## [0.2.1] - February 2, 2016
|
5
|
+
|
6
|
+
Fixed potential password_reset nil pointer.
|
7
|
+
Continued adding I18n support.
|
8
|
+
Minor documentation improvments.
|
9
|
+
|
10
|
+
[0.2.1]: https://github.com/tomichj/authenticate/compare/v0.2.0...v0.2.1
|
11
|
+
|
12
|
+
|
4
13
|
## [0.2.0] - February 2, 2016
|
5
14
|
|
6
15
|
Added app/ including controllers, views, routes, mailers.
|
7
16
|
|
17
|
+
[0.2.0]: https://github.com/tomichj/authenticate/compare/v0.1.0...v0.2.0
|
18
|
+
|
19
|
+
|
20
|
+
## 0.1.0 - January 23, 2016
|
8
21
|
|
9
|
-
|
22
|
+
Initial Release, barely functioning
|
10
23
|
|
11
|
-
Initial Release, barely functioning
|
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
gemspec
|
4
|
+
|
4
5
|
|
5
6
|
# Declare your gem's dependencies in authenticate.gemspec.
|
6
7
|
# Bundler will treat runtime dependencies like base dependencies, and
|
7
8
|
# development dependencies will be added by default to the :development group.
|
8
|
-
gemspec
|
9
9
|
|
10
10
|
# Declare any dependencies that are still in development here instead of in
|
11
11
|
# your gemspec. These might include edge Rails or gems from your path or
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
authenticate (0.1
|
4
|
+
authenticate (0.2.1)
|
5
5
|
bcrypt
|
6
6
|
email_validator (~> 1.6)
|
7
7
|
rails (>= 4.0, < 5.1)
|
@@ -124,7 +124,7 @@ GEM
|
|
124
124
|
sprockets (3.5.2)
|
125
125
|
concurrent-ruby (~> 1.0)
|
126
126
|
rack (> 1, < 3)
|
127
|
-
sprockets-rails (3.0.
|
127
|
+
sprockets-rails (3.0.1)
|
128
128
|
actionpack (>= 4.0)
|
129
129
|
activesupport (>= 4.0)
|
130
130
|
sprockets (>= 3.0.0)
|
@@ -141,7 +141,6 @@ DEPENDENCIES
|
|
141
141
|
authenticate!
|
142
142
|
factory_girl_rails
|
143
143
|
pry
|
144
|
-
rails
|
145
144
|
rspec-rails
|
146
145
|
sqlite3
|
147
146
|
|
data/README.md
CHANGED
@@ -11,13 +11,13 @@ Please use [GitHub Issues] to report bugs.
|
|
11
11
|
|
12
12
|
[GitHub Issues]: https://github.com/tomichj/authenticate/issues
|
13
13
|
|
14
|
-
|
14
|
+
 
|
15
15
|
|
16
16
|
## Philosophy
|
17
17
|
|
18
18
|
* simple - Authenticate's code is straightforward and easy to read.
|
19
19
|
* opinionated - set the "right" defaults, but let you control almost everything if you want
|
20
|
-
* small footprint - as few public methods and modules as possible
|
20
|
+
* small footprint - as few public methods and modules as possible. Methods only loaded into your user model if needed.
|
21
21
|
* configuration driven - almost all configuration is performed in the initializer
|
22
22
|
|
23
23
|
|
@@ -28,7 +28,7 @@ Authenticate:
|
|
28
28
|
* loads modules into your user model to provide authentication functionality
|
29
29
|
* loads `callbacks` that are triggered during authentication and access events. All authentication
|
30
30
|
decisions are performed in callbacks, e.g. do you have a valid session, has your session timed out, etc.
|
31
|
-
* loads a module into your controllers (typically application controller) to secure controller actions
|
31
|
+
* loads a module into your controllers (typically application controller) to secure controller actions
|
32
32
|
|
33
33
|
The callback architecture is based on the system used by devise and warden, but significantly simplified.
|
34
34
|
|
@@ -36,14 +36,10 @@ The callback architecture is based on the system used by devise and warden, but
|
|
36
36
|
### Session Token
|
37
37
|
|
38
38
|
Authenticate generates and clears a token (called a 'session token') to identify the user from a saved cookie.
|
39
|
-
When a user authenticates successfully, Authenticate generates and stores a 'session token' for your user in
|
40
|
-
your database. The session token is also stored in a cookie in the user's browser.
|
39
|
+
When a user authenticates successfully, Authenticate generates and stores a 'session token' for your user in
|
40
|
+
your database. The session token is also stored in a cookie in the user's browser.
|
41
41
|
The cookie is then presented upon each subsequent access attempt to your server.
|
42
42
|
|
43
|
-
### User Model
|
44
|
-
|
45
|
-
|
46
|
-
|
47
43
|
|
48
44
|
## Install
|
49
45
|
|
@@ -94,18 +90,40 @@ Authenticate.configure do |config|
|
|
94
90
|
config.cookie_domain = nil
|
95
91
|
config.cookie_path = '/
|
96
92
|
config.secure_cookie = false
|
97
|
-
config.
|
93
|
+
config.cookie_http_only = false
|
94
|
+
config.mailer_sender = 'reply@example.com'
|
98
95
|
config.crypto_provider = Bcrypt
|
99
96
|
config.timeout_in = nil # 45.minutes
|
100
97
|
config.max_session_lifetime = nil # 8.hours
|
101
98
|
config.max_consecutive_bad_logins_allowed = nil # 5
|
102
99
|
config.bad_login_lockout_period = nil # 5.minutes
|
103
100
|
config.authentication_strategy = :email
|
101
|
+
config.redirect_url = '/'
|
102
|
+
config.allow_sign_up = true
|
103
|
+
config.routes = true
|
104
|
+
config.reset_password_within = 2.days
|
105
|
+
end
|
104
106
|
```
|
105
107
|
|
106
108
|
Configuration parameters are described in detail here: [Configuration](lib/authenticate/configuration.rb)
|
107
109
|
|
108
110
|
|
111
|
+
### User Model
|
112
|
+
|
113
|
+
Authenticate assumes your user class is '::User' by default. You can elect to use another user class.
|
114
|
+
Set the user model class name using `user_model` in configuration. For example, if your user model
|
115
|
+
class is `Profile`:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Authenticate.configure do |config|
|
119
|
+
config.user_model = '::Profile'
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
Your user model will also need to `include Authenticate::User`. This is done automatically for you using
|
124
|
+
the Authenticate install generator, see [install](#install) above.
|
125
|
+
|
126
|
+
|
109
127
|
### timeout_in
|
110
128
|
|
111
129
|
* timeout_in: the interval to timeout the user session without activity.
|
@@ -131,7 +149,7 @@ authentication again.
|
|
131
149
|
|
132
150
|
To enable brute force protection, set max_consecutive_bad_logins_allowed to a non-nil positive integer.
|
133
151
|
The user's consecutive bad logins will be tracked, and if they exceed the allowed maximumm the user's account
|
134
|
-
will be locked. The lock will last `bad_login_lockout_period`, which can be any time period (e.g. `10.minutes`).
|
152
|
+
will be locked. The lock will last `bad_login_lockout_period`, which can be any time period (e.g. `10.minutes`).
|
135
153
|
|
136
154
|
|
137
155
|
### authentication_strategy
|
@@ -149,7 +167,7 @@ The strategy will also add username attribute validation, ensuring the username
|
|
149
167
|
|
150
168
|
### Authentication
|
151
169
|
|
152
|
-
Authenticate provides a session controller and views to authenticate users. After successful authentication,
|
170
|
+
Authenticate provides a session controller and views to authenticate users. After successful authentication,
|
153
171
|
the user is redirected to the path they attempted to access, or as specified by the `redirect_url` property
|
154
172
|
in your configuration. This defaults to '/' but can customized:
|
155
173
|
|
@@ -202,23 +220,34 @@ end
|
|
202
220
|
|
203
221
|
## Overriding Authenticate
|
204
222
|
|
205
|
-
###
|
223
|
+
### Routes
|
206
224
|
|
207
|
-
|
208
|
-
the default views. When you want to customize an Authenticate view, create your own copy of it in your app.
|
225
|
+
Authenticate adds routes. See [config/routes.rb](/config/routes.rb) for the default routes.
|
209
226
|
|
210
|
-
|
227
|
+
If you want to control and customize the routes, you can turn off the built-in routes in
|
228
|
+
the Authenticate configuration with `config.routes = false` and dump a copy of the default routes into your
|
229
|
+
application for modification.
|
230
|
+
|
231
|
+
To turn off Authenticate's built-in routes:
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
Authenticate.configure do |config|
|
235
|
+
config.routes = false
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
You can run a generator to dump a copy of the default routes into your application for modification.
|
211
240
|
|
212
241
|
```sh
|
213
|
-
$ rails generate authenticate:
|
242
|
+
$ rails generate authenticate:routes
|
214
243
|
```
|
215
244
|
|
216
245
|
|
217
246
|
### Controllers
|
218
247
|
|
219
248
|
If the customization at the views level is not enough, you can customize each controller, and the
|
220
|
-
authenticate mailer. See [app/controllers](/app/controllers) for the default controllers, and
|
221
|
-
[app/mailers](/app/mailers) for the default mailer.
|
249
|
+
authenticate mailer. See [app/controllers](/app/controllers) for the default controllers, and
|
250
|
+
[app/mailers](/app/mailers) for the default mailer.
|
222
251
|
|
223
252
|
You can use the Authenticate controller generator to copy the default controllers and mailer into your application:
|
224
253
|
|
@@ -227,20 +256,62 @@ $ rails generate authenticate:controllers
|
|
227
256
|
```
|
228
257
|
|
229
258
|
|
230
|
-
###
|
231
|
-
|
232
|
-
Authenticate adds routes. See [config/routes.rb](/config/routes.rb) for the default routes.
|
259
|
+
### Views
|
233
260
|
|
234
|
-
|
235
|
-
the Authenticate
|
261
|
+
You can quickly get started with a rails application using the built-in views. See [app/views](/app/views) for
|
262
|
+
the default views. When you want to customize an Authenticate view, create your own copy of it in your app.
|
236
263
|
|
237
|
-
You can
|
264
|
+
You can use the Authenticate view generator to copy the default views into your application:
|
238
265
|
|
239
266
|
```sh
|
240
|
-
$ rails generate authenticate:
|
267
|
+
$ rails generate authenticate:views
|
268
|
+
```
|
269
|
+
|
270
|
+
|
271
|
+
### Layout
|
272
|
+
|
273
|
+
Authenticate uses your application's default layout. If you would like to change the layout clearance uses when
|
274
|
+
rendering views, you can either deploy copies of the controllers and customize them, or you can specify
|
275
|
+
the layout in an initializer. This needs to be done in a to_prepare callback in `config/application.rb`
|
276
|
+
because it's executed once in production and before each request in development.
|
277
|
+
|
278
|
+
You can specify the layout per-controller:
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
config.to_prepare do
|
282
|
+
Authenticate::PasswordsController.layout 'my_passwords_layout'
|
283
|
+
Authenticate::SessionsController.layout 'my_sessions_layout'
|
284
|
+
Authenticate::UsersController.layout 'my_users_layout'
|
285
|
+
end
|
286
|
+
```
|
287
|
+
|
288
|
+
|
289
|
+
### Layout
|
290
|
+
|
291
|
+
Authenticate uses your application's default layout. If you would like to change the layout clearance uses when
|
292
|
+
rendering views, you can either deploy copies of the controllers and customize them, or you can specify
|
293
|
+
the layout in an initializer. This needs to be done in a to_prepare callback in `config/application.rb`
|
294
|
+
because it's executed once in production and before each request in development.
|
295
|
+
|
296
|
+
You can specify the layout per-controller:
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
config.to_prepare do
|
300
|
+
Authenticate::PasswordsController.layout 'my_passwords_layout'
|
301
|
+
Authenticate::SessionsController.layout 'my_sessions_layout'
|
302
|
+
Authenticate::UsersController.layout 'my_users_layout'
|
303
|
+
end
|
241
304
|
```
|
242
305
|
|
243
306
|
|
307
|
+
### Translations
|
308
|
+
|
309
|
+
All flash messages and email lines are stored in i18n translations. You can override them like any other translation.
|
310
|
+
|
311
|
+
See [config/locales/authenticate.en.yml](/config/locales/authenticate.en.yml) for the default messages.
|
312
|
+
|
313
|
+
|
314
|
+
|
244
315
|
## Extending Authenticate
|
245
316
|
|
246
317
|
Authenticate can be further extended with two mechanisms:
|
@@ -251,10 +322,10 @@ Authenticate can be further extended with two mechanisms:
|
|
251
322
|
|
252
323
|
### User Modules
|
253
324
|
|
254
|
-
Add behavior to your User model for your callbacks to use. You can, of course, incldue behavrio yourself directly
|
325
|
+
Add behavior to your User model for your callbacks to use. You can, of course, incldue behavrio yourself directly
|
255
326
|
in your User class, but you can also use the Authenticate module loading system.
|
256
327
|
|
257
|
-
To add a custom module to Authenticate, e.g. `MyUserModule`:
|
328
|
+
To add a custom module to Authenticate, e.g. `MyUserModule`:
|
258
329
|
|
259
330
|
```ruby
|
260
331
|
Authenticate.configuration do |config|
|
@@ -265,7 +336,7 @@ end
|
|
265
336
|
|
266
337
|
### Callbacks
|
267
338
|
|
268
|
-
Callbacks can be added to Authenticate. Use `Authenticate.lifecycle.after_set_user` or
|
339
|
+
Callbacks can be added to Authenticate. Use `Authenticate.lifecycle.after_set_user` or
|
269
340
|
`Authenticate.lifecycle.after_authentication`. See [Lifecycle](lib/authenticate/lifecycle.rb) for full details.
|
270
341
|
|
271
342
|
Callbacks can `throw(:failure, message)` to signal an authentication/authorization failure. Callbacks can also perform
|
@@ -279,7 +350,7 @@ set in the `included` block. The callback is then added to the User module via
|
|
279
350
|
module LoginCount
|
280
351
|
extend ActiveSupport::Concern
|
281
352
|
|
282
|
-
included do
|
353
|
+
included do
|
283
354
|
# Add a callback that is triggered after every authentication
|
284
355
|
Authenticate.lifecycle.after_authentication name:'login counter' do |user, session, options|
|
285
356
|
user.count_login if user
|
@@ -304,6 +375,8 @@ end
|
|
304
375
|
|
305
376
|
Authenticate has been tested with rails 4.2, other versions to follow.
|
306
377
|
|
378
|
+
|
379
|
+
|
307
380
|
## License
|
308
381
|
|
309
382
|
This project rocks and uses MIT-LICENSE.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Request password change via an emailed link with a unique token.
|
2
2
|
# Thanks to devise and Clearance.
|
3
|
-
class Authenticate::PasswordsController <
|
3
|
+
class Authenticate::PasswordsController < Authenticate::AuthenticateController
|
4
4
|
skip_before_action :require_authentication, only: [:create, :edit, :new, :update], raise: false
|
5
5
|
before_action :ensure_existing_user, only: [:edit, :update]
|
6
6
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Authenticate::SessionsController <
|
1
|
+
class Authenticate::SessionsController < Authenticate::AuthenticateController
|
2
2
|
before_action :redirect_signed_in_users, only: [:new]
|
3
3
|
skip_before_action :require_authentication, only: [:create, :new, :destroy], raise: false
|
4
4
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Authenticate::UsersController <
|
1
|
+
class Authenticate::UsersController < Authenticate::AuthenticateController
|
2
2
|
before_action :redirect_signed_in_users, only: [:create, :new]
|
3
3
|
skip_before_action :require_authentication, only: [:create, :new], raise: false
|
4
4
|
|
data/authenticate.gemspec
CHANGED
@@ -10,28 +10,26 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ['Justin Tomich']
|
11
11
|
s.email = ['justin@tomich.org']
|
12
12
|
s.homepage = 'http://github.com/tomichj/authenticate'
|
13
|
-
s.summary = '
|
14
|
-
s.description = '
|
13
|
+
s.summary = 'Authentication for Rails applications'
|
14
|
+
s.description = 'Authentication for Rails applications'
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
17
|
-
# s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
18
17
|
s.files = `git ls-files`.split("\n")
|
19
|
-
|
20
|
-
s.test_files = Dir['spec/**/*_spec.rb']
|
21
|
-
|
22
|
-
s.extra_rdoc_files = %w(LICENSE README.md)
|
23
|
-
s.rdoc_options = ['--charset=UTF-8']
|
18
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
24
19
|
|
25
20
|
s.require_paths = ['lib']
|
21
|
+
s.extra_rdoc_files = %w(LICENSE README.md CHANGELOG.md)
|
22
|
+
s.rdoc_options = ['--charset=UTF-8']
|
26
23
|
|
27
24
|
s.add_dependency 'bcrypt'
|
28
25
|
s.add_dependency 'email_validator', '~> 1.6'
|
29
26
|
s.add_dependency 'rails', '>= 4.0', '< 5.1'
|
30
|
-
|
31
|
-
s.add_development_dependency 'rspec-rails'
|
27
|
+
|
32
28
|
# s.add_development_dependency 'capybara'
|
33
29
|
s.add_development_dependency 'factory_girl_rails'
|
30
|
+
s.add_development_dependency 'rspec-rails'
|
34
31
|
s.add_development_dependency 'pry'
|
32
|
+
s.add_development_dependency 'sqlite3'
|
35
33
|
|
36
34
|
s.required_ruby_version = Gem::Requirement.new('>= 2.0')
|
37
35
|
end
|
@@ -10,7 +10,6 @@ en:
|
|
10
10
|
link_text: Change my password
|
11
11
|
opening: Someone has requested a link to change your password. You can do this through the link below.
|
12
12
|
flashes:
|
13
|
-
failure_after_create: Bad email or password.
|
14
13
|
failure_after_update: Password can't be blank.
|
15
14
|
failure_when_forbidden: Please double check the URL or try submitting the form again.
|
16
15
|
failure_when_not_signed_in: Please sign in to continue.
|
@@ -55,3 +54,12 @@ en:
|
|
55
54
|
new:
|
56
55
|
sign_in: Sign in
|
57
56
|
title: Sign up
|
57
|
+
callbacks:
|
58
|
+
authenticatable:
|
59
|
+
failure: Bad id or password
|
60
|
+
brute_force:
|
61
|
+
failure: "Your account is locked, will unlock in %{time_remaining}"
|
62
|
+
lifetimed:
|
63
|
+
failure: Your session has reached it's maximum allowed lifetime, you must log in again
|
64
|
+
timeoutable:
|
65
|
+
failure: Your session has expired
|