devise 4.6.2 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -4
- data/MIT-LICENSE +2 -1
- data/README.md +69 -62
- data/app/controllers/devise_controller.rb +2 -2
- data/app/helpers/devise_helper.rb +18 -6
- data/app/mailers/devise/mailer.rb +5 -5
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/shared/_links.html.erb +1 -1
- data/config/locales/en.yml +3 -3
- data/lib/devise.rb +1 -5
- data/lib/devise/controllers/helpers.rb +7 -7
- data/lib/devise/controllers/sign_in_out.rb +6 -4
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/failure_app.rb +5 -12
- data/lib/devise/hooks/lockable.rb +2 -5
- data/lib/devise/hooks/timeoutable.rb +2 -2
- data/lib/devise/mapping.rb +1 -1
- data/lib/devise/models/authenticatable.rb +12 -8
- data/lib/devise/models/confirmable.rb +14 -2
- data/lib/devise/models/database_authenticatable.rb +5 -1
- data/lib/devise/models/lockable.rb +10 -2
- data/lib/devise/models/recoverable.rb +2 -2
- data/lib/devise/models/rememberable.rb +1 -1
- data/lib/devise/models/trackable.rb +1 -1
- data/lib/devise/models/validatable.rb +1 -1
- data/lib/devise/omniauth.rb +2 -5
- data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
- data/lib/devise/rails/routes.rb +6 -6
- data/lib/devise/test/controller_helpers.rb +3 -1
- data/lib/devise/test/integration_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +17 -2
- data/lib/generators/devise/devise_generator.rb +1 -1
- data/lib/generators/devise/install_generator.rb +1 -5
- data/lib/generators/devise/views_generator.rb +1 -1
- data/lib/generators/templates/README +9 -1
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
- data/lib/generators/templates/devise.rb +15 -3
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -1
- metadata +9 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 197ce185bf22b8dc45c17a615895b60e6b788360113c37d99a116db868197309
|
4
|
+
data.tar.gz: 8e3fa67c5bcd6c05ac3011e0b35f0cda57596ae74c2affceab84cab1da3aeb58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d3f76d9e898d36dc6eb4db5d5b098b76d339aeadac014c772b7097dc6a730a7577049bd00ea7a073beead47454edb91d24fe73b50e90af3555cc5e83886902f
|
7
|
+
data.tar.gz: 84cbafa77c70de3c204dfdf19e4ce53ac05796eaf959bba4d4909d0c91686baa6da61f732e13bce0892d8932af375d2b81340f6bd1047384f15325f8a24011e0
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,59 @@
|
|
1
|
-
###
|
1
|
+
### unreleased
|
2
|
+
|
3
|
+
### 4.8.0 - 2021-04-29
|
4
|
+
|
5
|
+
* enhancements
|
6
|
+
* Devise now enables the upgrade of OmniAuth 2+. Previously Devise would raise an error if you'd try to upgrade. Please note that OmniAuth 2 is considered a security upgrade and recommended to everyone. You can read more about the details (and possible necessary changes to your app as part of the upgrade) in [their release notes](https://github.com/omniauth/omniauth/releases/tag/v2.0.0). [Devise's OmniAuth Overview wiki](https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview) was also updated to cover OmniAuth 2.0 requirements.
|
7
|
+
- Note that the upgrade required Devise shared links that initiate the OmniAuth flow to be changed to `method: :post`, which is now a requirement for OmniAuth, part of the security improvement. If you have copied and customized the Devise shared links partial to your app, or if you have other links in your app that initiate the OmniAuth flow, they will have to be updated to use `method: :post`, or changed to use buttons (e.g. `button_to`) to work with OmniAuth 2. (if you're using links with `method: :post`, make sure your app has `rails-ujs` or `jquery-ujs` included in order for these links to work properly.)
|
8
|
+
- As part of the OmniAuth 2.0 upgrade you might also need to add the [`omniauth-rails_csrf_protection`](https://github.com/cookpad/omniauth-rails_csrf_protection) gem to your app if you don't have it already. (and you don't want to roll your own code to verify requests.) Check the OmniAuth v2 release notes for more info.
|
9
|
+
* Introduce `Lockable#reset_failed_attempts!` model method to reset failed attempts counter to 0 after the user signs in.
|
10
|
+
- This logic existed inside the lockable warden hook and is triggered automatically after the user signs in. The new model method is an extraction to allow you to override it in the application to implement things like switching to a write database if you're using the new multi-DB infrastructure from Rails for example, similar to how it's already possible with `Trackable#update_tracked_fields!`.
|
11
|
+
* Add support for Ruby 3.
|
12
|
+
* Add support for Rails 6.1.
|
13
|
+
* Move CI to GitHub Actions.
|
14
|
+
|
15
|
+
* deprecations
|
16
|
+
* `Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION` is deprecated in favor of `Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION` (@hanachin)
|
17
|
+
|
18
|
+
### 4.7.3 - 2020-09-20
|
19
|
+
|
20
|
+
* bug fixes
|
21
|
+
* Do not modify `:except` option given to `#serializable_hash`. (by @dpep)
|
22
|
+
* Fix thor deprecation when running the devise generator. (by @deivid-rodriguez)
|
23
|
+
* Fix hanging tests for streaming controllers using Devise. (by @afn)
|
24
|
+
|
25
|
+
### 4.7.2 - 2020-06-10
|
26
|
+
|
27
|
+
* enhancements
|
28
|
+
* Increase default stretches to 12 (by @sergey-alekseev)
|
29
|
+
* Ruby 2.7 support (kwarg warnings removed)
|
30
|
+
|
31
|
+
* bug fixes
|
32
|
+
* Generate scoped views with proper scoped errors partial (by @shobhitic)
|
33
|
+
* Allow to set scoped `already_authenticated` error messages (by @gurgelrenan)
|
34
|
+
|
35
|
+
### 4.7.1 - 2019-09-06
|
36
|
+
|
37
|
+
* bug fixes
|
38
|
+
* Fix an edge case where records with a blank `confirmation_token` could be confirmed (by @tegon)
|
39
|
+
* Fix typo inside `update_needs_confirmation` i18n key (by @lslm)
|
40
|
+
|
41
|
+
### 4.7.0 - 2019-08-19
|
42
|
+
|
43
|
+
* enhancements
|
44
|
+
* Support Rails 6.0
|
45
|
+
* Update CI to rails 6.0.0.beta3 (by @tunnes)
|
46
|
+
* refactor method name to be more consistent (by @saiqulhaq)
|
47
|
+
* Fix rails 6.0.rc1 email uniqueness validation deprecation warning (by @Vasfed)
|
48
|
+
|
49
|
+
* bug fixes
|
50
|
+
* Add `autocomplete="new-password"` to `password_confirmation` fields (by @ferrl)
|
51
|
+
* Fix rails_51_and_up? method for Rails 6.rc1 (by @igorkasyanchuk)
|
2
52
|
|
3
53
|
### 4.6.2 - 2019-03-26
|
4
54
|
|
5
55
|
* bug fixes
|
6
|
-
* Revert "Set `encrypted_password` to `nil` when `password` is set to `nil`" since it broke backward compatibility with existing applications. See more on https://github.com/
|
56
|
+
* Revert "Set `encrypted_password` to `nil` when `password` is set to `nil`" since it broke backward compatibility with existing applications. See more on https://github.com/heartcombo/devise/issues/5033#issuecomment-476386275 (by @mracos)
|
7
57
|
|
8
58
|
### 4.6.1 - 2019-02-11
|
9
59
|
|
@@ -50,7 +100,7 @@
|
|
50
100
|
* Add `autocomplete="new-password"` to new password fields (by @gssbzn)
|
51
101
|
* Add `autocomplete="current-password"` to current password fields (by @gssbzn)
|
52
102
|
* Remove redundant `self` from `database_authenticatable` module (by @abhishekkanojia)
|
53
|
-
* Update `simple_form` templates with changes from https://github.com/
|
103
|
+
* Update `simple_form` templates with changes from https://github.com/heartcombo/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/heartcombo/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
|
54
104
|
* Remove `:trackable` from the default modules in the generators, to be more GDPR-friendly (by @fakenine)
|
55
105
|
|
56
106
|
* bug fixes
|
@@ -297,5 +347,5 @@ configured (by @joshpencheon)
|
|
297
347
|
You can check more examples and explanations on the [README section](README.md#strong-parameters)
|
298
348
|
and on the [ParameterSanitizer docs](lib/devise/parameter_sanitizer.rb).
|
299
349
|
|
300
|
-
Please check [3-stable](https://github.com/
|
350
|
+
Please check [3-stable](https://github.com/heartcombo/devise/blob/3-stable/CHANGELOG.md)
|
301
351
|
for previous changes.
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2020 Rafael França, Leonardo Tegon, Carlos Antônio da Silva.
|
2
|
+
Copyright 2009-2019 Plataformatec.
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,11 +1,6 @@
|
|
1
|
-
![Devise Logo](https://raw.github.com/
|
1
|
+
![Devise Logo](https://raw.github.com/heartcombo/devise/master/devise.png)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
[![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise)
|
7
|
-
|
8
|
-
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
3
|
+
[![Code Climate](https://codeclimate.com/github/heartcombo/devise.svg)](https://codeclimate.com/github/heartcombo/devise)
|
9
4
|
|
10
5
|
Devise is a flexible authentication solution for Rails based on Warden. It:
|
11
6
|
|
@@ -16,16 +11,16 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
|
16
11
|
|
17
12
|
It's composed of 10 modules:
|
18
13
|
|
19
|
-
* [Database Authenticatable](http://www.rubydoc.info/github/
|
20
|
-
* [Omniauthable](http://www.rubydoc.info/github/
|
21
|
-
* [Confirmable](http://www.rubydoc.info/github/
|
22
|
-
* [Recoverable](http://www.rubydoc.info/github/
|
23
|
-
* [Registerable](http://www.rubydoc.info/github/
|
24
|
-
* [Rememberable](http://www.rubydoc.info/github/
|
25
|
-
* [Trackable](http://www.rubydoc.info/github/
|
26
|
-
* [Timeoutable](http://www.rubydoc.info/github/
|
27
|
-
* [Validatable](http://www.rubydoc.info/github/
|
28
|
-
* [Lockable](http://www.rubydoc.info/github/
|
14
|
+
* [Database Authenticatable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
|
15
|
+
* [Omniauthable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
|
16
|
+
* [Confirmable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
|
17
|
+
* [Recoverable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
|
18
|
+
* [Registerable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
|
19
|
+
* [Rememberable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
|
20
|
+
* [Trackable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
|
21
|
+
* [Timeoutable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
|
22
|
+
* [Validatable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
|
23
|
+
* [Lockable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
|
29
24
|
|
30
25
|
## Table of Contents
|
31
26
|
|
@@ -58,7 +53,6 @@ It's composed of 10 modules:
|
|
58
53
|
- [Other ORMs](#other-orms)
|
59
54
|
- [Rails API mode](#rails-api-mode)
|
60
55
|
- [Additional information](#additional-information)
|
61
|
-
- [Heroku](#heroku)
|
62
56
|
- [Warden](#warden)
|
63
57
|
- [Contributors](#contributors)
|
64
58
|
- [License](#license)
|
@@ -73,15 +67,15 @@ It's composed of 10 modules:
|
|
73
67
|
|
74
68
|
The Devise Wiki has lots of additional information about Devise including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
|
75
69
|
|
76
|
-
https://github.com/
|
70
|
+
https://github.com/heartcombo/devise/wiki
|
77
71
|
|
78
72
|
### Bug reports
|
79
73
|
|
80
74
|
If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
|
81
75
|
|
82
|
-
https://github.com/
|
76
|
+
https://github.com/heartcombo/devise/wiki/Bug-reports
|
83
77
|
|
84
|
-
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to
|
78
|
+
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo@googlegroups.com.
|
85
79
|
|
86
80
|
### StackOverflow and Mailing List
|
87
81
|
|
@@ -97,7 +91,7 @@ https://groups.google.com/group/plataformatec-devise
|
|
97
91
|
|
98
92
|
You can view the Devise documentation in RDoc format here:
|
99
93
|
|
100
|
-
http://rubydoc.info/github/
|
94
|
+
http://rubydoc.info/github/heartcombo/devise/master/frames
|
101
95
|
|
102
96
|
If you need to use Devise with previous versions of Rails, you can always run "gem server" from the command line after you install the gem to access the old documentation.
|
103
97
|
|
@@ -105,26 +99,26 @@ If you need to use Devise with previous versions of Rails, you can always run "g
|
|
105
99
|
|
106
100
|
There are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:
|
107
101
|
|
108
|
-
https://github.com/
|
102
|
+
https://github.com/heartcombo/devise/wiki/Example-Applications
|
109
103
|
|
110
104
|
### Extensions
|
111
105
|
|
112
106
|
Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
|
113
107
|
|
114
|
-
https://github.com/
|
108
|
+
https://github.com/heartcombo/devise/wiki/Extensions
|
115
109
|
|
116
110
|
### Contributing
|
117
111
|
|
118
112
|
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
119
113
|
|
120
|
-
https://github.com/
|
114
|
+
https://github.com/heartcombo/devise/wiki/Contributing
|
121
115
|
|
122
116
|
You will usually want to write tests for your changes. To run the test suite, go into Devise's top-level directory and run `bundle install` and `bin/test`.
|
123
117
|
Devise works with multiple Ruby and Rails versions, and ActiveRecord and Mongoid ORMs, which means you can run the test suite with some modifiers: `DEVISE_ORM` and `BUNDLE_GEMFILE`.
|
124
118
|
|
125
119
|
### DEVISE_ORM
|
126
|
-
Since Devise
|
127
|
-
The default value of `DEVISE_ORM` is `active_record`. To run the tests for
|
120
|
+
Since Devise supports both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
|
121
|
+
The default value of `DEVISE_ORM` is `active_record`. To run the tests for Mongoid, you can pass `mongoid`:
|
128
122
|
```
|
129
123
|
DEVISE_ORM=mongoid bin/test
|
130
124
|
|
@@ -136,7 +130,7 @@ Please note that the command output will show the variable value being used.
|
|
136
130
|
|
137
131
|
### BUNDLE_GEMFILE
|
138
132
|
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
|
139
|
-
Inside the [gemfiles](https://github.com/
|
133
|
+
Inside the [gemfiles](https://github.com/heartcombo/devise/tree/master/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
|
140
134
|
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
|
141
135
|
```bash
|
142
136
|
rbenv shell 2.4.2 # or rvm use 2.4.2
|
@@ -170,11 +164,11 @@ bin/test test/models/trackable_test.rb:16
|
|
170
164
|
|
171
165
|
## Starting with Rails?
|
172
166
|
|
173
|
-
If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch.
|
167
|
+
If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Here's a few resources that should help you get started:
|
174
168
|
|
175
169
|
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
176
|
-
* Ryan Bates'
|
177
|
-
* Codecademy's Ruby on Rails: Authentication and Authorization:
|
170
|
+
* Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
|
171
|
+
* Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
|
178
172
|
|
179
173
|
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
180
174
|
|
@@ -270,16 +264,16 @@ member_session
|
|
270
264
|
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the hashing algorithm with:
|
271
265
|
|
272
266
|
```ruby
|
273
|
-
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches:
|
267
|
+
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
|
274
268
|
```
|
275
269
|
|
276
270
|
Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above. This file is usually located at `/config/initializers/devise.rb`.
|
277
271
|
|
278
272
|
### Strong Parameters
|
279
273
|
|
280
|
-
|
274
|
+
The Parameter Sanitizer API has changed for Devise 4 :warning:
|
281
275
|
|
282
|
-
*For previous Devise versions see https://github.com/
|
276
|
+
*For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
|
283
277
|
|
284
278
|
When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
|
285
279
|
|
@@ -289,7 +283,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
|
|
289
283
|
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
290
284
|
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
291
285
|
|
292
|
-
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before
|
286
|
+
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
|
293
287
|
|
294
288
|
```ruby
|
295
289
|
class ApplicationController < ActionController::Base
|
@@ -317,7 +311,7 @@ class ApplicationController < ActionController::Base
|
|
317
311
|
end
|
318
312
|
```
|
319
313
|
|
320
|
-
Devise allows you to completely change Devise defaults or invoke custom
|
314
|
+
Devise allows you to completely change Devise defaults or invoke custom behavior by passing a block:
|
321
315
|
|
322
316
|
To permit simple scalar values for username and email, use this
|
323
317
|
|
@@ -440,7 +434,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
440
434
|
end
|
441
435
|
```
|
442
436
|
|
443
|
-
Or you can simply add new
|
437
|
+
Or you can simply add new behavior to it:
|
444
438
|
|
445
439
|
```ruby
|
446
440
|
class Users::SessionsController < Devise::SessionsController
|
@@ -464,7 +458,7 @@ Devise also ships with default routes. If you need to customize them, you should
|
|
464
458
|
devise_for :users, path: 'auth', path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
|
465
459
|
```
|
466
460
|
|
467
|
-
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/
|
461
|
+
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/heartcombo/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
|
468
462
|
|
469
463
|
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:
|
470
464
|
|
@@ -520,7 +514,7 @@ en:
|
|
520
514
|
|
521
515
|
Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
|
522
516
|
|
523
|
-
https://github.com/
|
517
|
+
https://github.com/heartcombo/devise/wiki/I18n
|
524
518
|
|
525
519
|
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
|
526
520
|
|
@@ -532,15 +526,21 @@ cases/specs.
|
|
532
526
|
|
533
527
|
### Controller tests
|
534
528
|
|
535
|
-
Controller tests require that you include `Devise::Test::
|
529
|
+
Controller tests require that you include `Devise::Test::IntegrationHelpers` on
|
536
530
|
your test case or its parent `ActionController::TestCase` superclass.
|
537
|
-
For Rails 5, include `Devise::Test::
|
538
|
-
for controller tests
|
531
|
+
For Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass
|
532
|
+
for controller tests was changed to ActionDispatch::IntegrationTest
|
539
533
|
(for more details, see the [Integration tests](#integration-tests) section).
|
540
534
|
|
541
535
|
```ruby
|
542
536
|
class PostsControllerTest < ActionController::TestCase
|
543
|
-
include Devise::Test::
|
537
|
+
include Devise::Test::IntegrationHelpers # Rails >= 5
|
538
|
+
end
|
539
|
+
```
|
540
|
+
|
541
|
+
```ruby
|
542
|
+
class PostsControllerTest < ActionController::TestCase
|
543
|
+
include Devise::Test::ControllerHelpers # Rails < 5
|
544
544
|
end
|
545
545
|
```
|
546
546
|
|
@@ -620,7 +620,7 @@ are executed in your tests.
|
|
620
620
|
|
621
621
|
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
622
622
|
|
623
|
-
* https://github.com/
|
623
|
+
* https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
|
624
624
|
|
625
625
|
### OmniAuth
|
626
626
|
|
@@ -632,7 +632,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
|
632
632
|
|
633
633
|
You can read more about OmniAuth support in the wiki:
|
634
634
|
|
635
|
-
* https://github.com/
|
635
|
+
* https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
|
636
636
|
|
637
637
|
### Configuring multiple models
|
638
638
|
|
@@ -679,12 +679,12 @@ end
|
|
679
679
|
|
680
680
|
### Password reset tokens and Rails logs
|
681
681
|
|
682
|
-
If you enable the [Recoverable](http://rubydoc.info/github/
|
682
|
+
If you enable the [Recoverable](http://rubydoc.info/github/heartcombo/devise/master/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:
|
683
683
|
|
684
684
|
1. Action Mailer logs the entire contents of all outgoing emails to the DEBUG level. Password reset tokens delivered to users in email will be leaked.
|
685
685
|
2. Active Job logs all arguments to every enqueued job at the INFO level. If you configure Devise to use `deliver_later` to send password reset emails, password reset tokens will be leaked.
|
686
686
|
|
687
|
-
Rails sets the production logger level to
|
687
|
+
Rails sets the production logger level to INFO by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:
|
688
688
|
|
689
689
|
```ruby
|
690
690
|
config.log_level = :warn
|
@@ -697,41 +697,48 @@ Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simpl
|
|
697
697
|
|
698
698
|
### Rails API Mode
|
699
699
|
|
700
|
-
Rails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only).
|
700
|
+
Rails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only). Devise is _somewhat_ able to handle applications that are built in this mode without additional modifications in the sense that it should not raise exceptions and the like. But some issues may still arise during `development`/`testing`, as we still don't know the full extent of this compatibility. (For more information, see [issue #4947](https://github.com/heartcombo/devise/issues/4947/))
|
701
701
|
|
702
|
-
|
703
|
-
|
704
|
-
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
|
705
|
-
```
|
702
|
+
#### Supported Authentication Strategies
|
703
|
+
API-only applications don't support browser-based authentication via cookies, which is devise's default. Yet, devise can still provide authentication out of the box in those cases with the `http_authenticatable` strategy, which uses HTTP Basic Auth and authenticates the user on each request. (For more info, see this wiki article for [How To: Use HTTP Basic Authentication](https://github.com/heartcombo/devise/wiki/How-To:-Use-HTTP-Basic-Authentication))
|
706
704
|
|
707
|
-
|
705
|
+
The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
|
708
706
|
|
709
|
-
|
707
|
+
```ruby
|
708
|
+
config.http_authenticatable = [:database]
|
709
|
+
```
|
710
710
|
|
711
|
-
|
711
|
+
This restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.
|
712
|
+
A common authentication strategy for APIs is token-based authentication. For more information on extending devise to support this type of authentication and others, see the wiki article for [Simple Token Authentication Examples and alternatives](https://github.com/heartcombo/devise/wiki/How-To:-Simple-Token-Authentication-Example#alternatives) or this blog post on [Custom authentication methods with Devise](http://blog.plataformatec.com.br/2019/01/custom-authentication-methods-with-devise/).
|
712
713
|
|
713
|
-
|
714
|
+
#### Testing
|
715
|
+
API Mode changes the order of the middleware stack, and this can cause problems for `Devise::Test::IntegrationHelpers`. This problem usually surfaces as an ```undefined method `[]=' for nil:NilClass``` error when using integration test helpers, such as `#sign_in`. The solution is simply to reorder the middlewares by adding the following to test.rb:
|
714
716
|
|
715
717
|
```ruby
|
716
|
-
config.
|
718
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
|
719
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
|
717
720
|
```
|
718
721
|
|
719
|
-
|
722
|
+
For a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).
|
723
|
+
|
724
|
+
Additionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.
|
725
|
+
|
726
|
+
## Additional information
|
720
727
|
|
721
728
|
### Warden
|
722
729
|
|
723
730
|
Devise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
|
724
731
|
|
725
|
-
https://github.com/
|
732
|
+
https://github.com/wardencommunity/warden
|
726
733
|
|
727
734
|
### Contributors
|
728
735
|
|
729
736
|
We have a long list of valued contributors. Check them all at:
|
730
737
|
|
731
|
-
https://github.com/
|
738
|
+
https://github.com/heartcombo/devise/graphs/contributors
|
732
739
|
|
733
740
|
## License
|
734
741
|
|
735
|
-
MIT License. Copyright 2009-
|
742
|
+
MIT License. Copyright 2020 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
736
743
|
|
737
|
-
|
744
|
+
The Devise logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).
|
@@ -112,7 +112,7 @@ MESSAGE
|
|
112
112
|
end
|
113
113
|
|
114
114
|
if authenticated && resource = warden.user(resource_name)
|
115
|
-
|
115
|
+
set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
|
116
116
|
redirect_to after_sign_in_path_for(resource)
|
117
117
|
end
|
118
118
|
end
|
@@ -184,7 +184,7 @@ MESSAGE
|
|
184
184
|
options[:default] = Array(options[:default]).unshift(kind.to_sym)
|
185
185
|
options[:resource_name] = resource_name
|
186
186
|
options = devise_i18n_options(options)
|
187
|
-
I18n.t("#{options[:resource_name]}.#{kind}", options)
|
187
|
+
I18n.t("#{options[:resource_name]}.#{kind}", **options)
|
188
188
|
end
|
189
189
|
|
190
190
|
# Controllers inheriting DeviseController are advised to override this
|
@@ -1,14 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DeviseHelper
|
4
|
-
# Retain this method for backwards compatibility, deprecated in
|
5
|
-
# devise/shared/error_messages partial
|
4
|
+
# Retain this method for backwards compatibility, deprecated in favor of modifying the
|
5
|
+
# devise/shared/error_messages partial.
|
6
6
|
def devise_error_messages!
|
7
7
|
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
8
|
-
[Devise] `DeviseHelper
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
[Devise] `DeviseHelper#devise_error_messages!` is deprecated and will be
|
9
|
+
removed in the next major version.
|
10
|
+
|
11
|
+
Devise now uses a partial under "devise/shared/error_messages" to display
|
12
|
+
error messages by default, and make them easier to customize. Update your
|
13
|
+
views changing calls from:
|
14
|
+
|
15
|
+
<%= devise_error_messages! %>
|
16
|
+
|
17
|
+
to:
|
18
|
+
|
19
|
+
<%= render "devise/shared/error_messages", resource: resource %>
|
20
|
+
|
21
|
+
To start customizing how errors are displayed, you can copy the partial
|
22
|
+
from devise to your `app/views` folder. Alternatively, you can run
|
23
|
+
`rails g devise:views` which will copy all of them again to your app.
|
12
24
|
DEPRECATION
|
13
25
|
|
14
26
|
return "" if resource.errors.empty?
|