devise 4.6.1 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +58 -3
- data/MIT-LICENSE +2 -1
- data/README.md +75 -56
- 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 +7 -4
- 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/strategies/authenticatable.rb +1 -1
- 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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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,4 +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)
|
52
|
+
|
53
|
+
### 4.6.2 - 2019-03-26
|
54
|
+
|
55
|
+
* bug fixes
|
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)
|
2
57
|
|
3
58
|
### 4.6.1 - 2019-02-11
|
4
59
|
|
@@ -45,7 +100,7 @@
|
|
45
100
|
* Add `autocomplete="new-password"` to new password fields (by @gssbzn)
|
46
101
|
* Add `autocomplete="current-password"` to current password fields (by @gssbzn)
|
47
102
|
* Remove redundant `self` from `database_authenticatable` module (by @abhishekkanojia)
|
48
|
-
* 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)
|
49
104
|
* Remove `:trackable` from the default modules in the generators, to be more GDPR-friendly (by @fakenine)
|
50
105
|
|
51
106
|
* bug fixes
|
@@ -292,5 +347,5 @@ configured (by @joshpencheon)
|
|
292
347
|
You can check more examples and explanations on the [README section](README.md#strong-parameters)
|
293
348
|
and on the [ParameterSanitizer docs](lib/devise/parameter_sanitizer.rb).
|
294
349
|
|
295
|
-
Please check [3-stable](https://github.com/
|
350
|
+
Please check [3-stable](https://github.com/heartcombo/devise/blob/3-stable/CHANGELOG.md)
|
296
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
|
|
@@ -56,8 +51,8 @@ It's composed of 10 modules:
|
|
56
51
|
- [ActiveJob Integration](#activejob-integration)
|
57
52
|
- [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
|
58
53
|
- [Other ORMs](#other-orms)
|
54
|
+
- [Rails API mode](#rails-api-mode)
|
59
55
|
- [Additional information](#additional-information)
|
60
|
-
- [Heroku](#heroku)
|
61
56
|
- [Warden](#warden)
|
62
57
|
- [Contributors](#contributors)
|
63
58
|
- [License](#license)
|
@@ -72,15 +67,15 @@ It's composed of 10 modules:
|
|
72
67
|
|
73
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:
|
74
69
|
|
75
|
-
https://github.com/
|
70
|
+
https://github.com/heartcombo/devise/wiki
|
76
71
|
|
77
72
|
### Bug reports
|
78
73
|
|
79
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:
|
80
75
|
|
81
|
-
https://github.com/
|
76
|
+
https://github.com/heartcombo/devise/wiki/Bug-reports
|
82
77
|
|
83
|
-
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.
|
84
79
|
|
85
80
|
### StackOverflow and Mailing List
|
86
81
|
|
@@ -96,7 +91,7 @@ https://groups.google.com/group/plataformatec-devise
|
|
96
91
|
|
97
92
|
You can view the Devise documentation in RDoc format here:
|
98
93
|
|
99
|
-
http://rubydoc.info/github/
|
94
|
+
http://rubydoc.info/github/heartcombo/devise/master/frames
|
100
95
|
|
101
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.
|
102
97
|
|
@@ -104,26 +99,26 @@ If you need to use Devise with previous versions of Rails, you can always run "g
|
|
104
99
|
|
105
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:
|
106
101
|
|
107
|
-
https://github.com/
|
102
|
+
https://github.com/heartcombo/devise/wiki/Example-Applications
|
108
103
|
|
109
104
|
### Extensions
|
110
105
|
|
111
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:
|
112
107
|
|
113
|
-
https://github.com/
|
108
|
+
https://github.com/heartcombo/devise/wiki/Extensions
|
114
109
|
|
115
110
|
### Contributing
|
116
111
|
|
117
112
|
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
118
113
|
|
119
|
-
https://github.com/
|
114
|
+
https://github.com/heartcombo/devise/wiki/Contributing
|
120
115
|
|
121
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`.
|
122
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`.
|
123
118
|
|
124
119
|
### DEVISE_ORM
|
125
|
-
Since Devise
|
126
|
-
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`:
|
127
122
|
```
|
128
123
|
DEVISE_ORM=mongoid bin/test
|
129
124
|
|
@@ -135,7 +130,7 @@ Please note that the command output will show the variable value being used.
|
|
135
130
|
|
136
131
|
### BUNDLE_GEMFILE
|
137
132
|
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
|
138
|
-
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.
|
139
134
|
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
|
140
135
|
```bash
|
141
136
|
rbenv shell 2.4.2 # or rvm use 2.4.2
|
@@ -169,11 +164,11 @@ bin/test test/models/trackable_test.rb:16
|
|
169
164
|
|
170
165
|
## Starting with Rails?
|
171
166
|
|
172
|
-
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:
|
173
168
|
|
174
169
|
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
175
|
-
* Ryan Bates'
|
176
|
-
* 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
|
177
172
|
|
178
173
|
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
179
174
|
|
@@ -269,16 +264,16 @@ member_session
|
|
269
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:
|
270
265
|
|
271
266
|
```ruby
|
272
|
-
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches:
|
267
|
+
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
|
273
268
|
```
|
274
269
|
|
275
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`.
|
276
271
|
|
277
272
|
### Strong Parameters
|
278
273
|
|
279
|
-
|
274
|
+
The Parameter Sanitizer API has changed for Devise 4 :warning:
|
280
275
|
|
281
|
-
*For previous Devise versions see https://github.com/
|
276
|
+
*For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
|
282
277
|
|
283
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.
|
284
279
|
|
@@ -288,7 +283,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
|
|
288
283
|
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
289
284
|
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
290
285
|
|
291
|
-
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`:
|
292
287
|
|
293
288
|
```ruby
|
294
289
|
class ApplicationController < ActionController::Base
|
@@ -316,7 +311,7 @@ class ApplicationController < ActionController::Base
|
|
316
311
|
end
|
317
312
|
```
|
318
313
|
|
319
|
-
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:
|
320
315
|
|
321
316
|
To permit simple scalar values for username and email, use this
|
322
317
|
|
@@ -439,7 +434,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
439
434
|
end
|
440
435
|
```
|
441
436
|
|
442
|
-
Or you can simply add new
|
437
|
+
Or you can simply add new behavior to it:
|
443
438
|
|
444
439
|
```ruby
|
445
440
|
class Users::SessionsController < Devise::SessionsController
|
@@ -463,7 +458,7 @@ Devise also ships with default routes. If you need to customize them, you should
|
|
463
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' }
|
464
459
|
```
|
465
460
|
|
466
|
-
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.
|
467
462
|
|
468
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:
|
469
464
|
|
@@ -519,7 +514,7 @@ en:
|
|
519
514
|
|
520
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:
|
521
516
|
|
522
|
-
https://github.com/
|
517
|
+
https://github.com/heartcombo/devise/wiki/I18n
|
523
518
|
|
524
519
|
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
|
525
520
|
|
@@ -531,15 +526,21 @@ cases/specs.
|
|
531
526
|
|
532
527
|
### Controller tests
|
533
528
|
|
534
|
-
Controller tests require that you include `Devise::Test::
|
529
|
+
Controller tests require that you include `Devise::Test::IntegrationHelpers` on
|
535
530
|
your test case or its parent `ActionController::TestCase` superclass.
|
536
|
-
For Rails 5, include `Devise::Test::
|
537
|
-
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
|
538
533
|
(for more details, see the [Integration tests](#integration-tests) section).
|
539
534
|
|
540
535
|
```ruby
|
541
536
|
class PostsControllerTest < ActionController::TestCase
|
542
|
-
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
|
543
544
|
end
|
544
545
|
```
|
545
546
|
|
@@ -619,7 +620,7 @@ are executed in your tests.
|
|
619
620
|
|
620
621
|
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
621
622
|
|
622
|
-
* https://github.com/
|
623
|
+
* https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
|
623
624
|
|
624
625
|
### OmniAuth
|
625
626
|
|
@@ -631,7 +632,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
|
631
632
|
|
632
633
|
You can read more about OmniAuth support in the wiki:
|
633
634
|
|
634
|
-
* https://github.com/
|
635
|
+
* https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
|
635
636
|
|
636
637
|
### Configuring multiple models
|
637
638
|
|
@@ -678,12 +679,12 @@ end
|
|
678
679
|
|
679
680
|
### Password reset tokens and Rails logs
|
680
681
|
|
681
|
-
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:
|
682
683
|
|
683
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.
|
684
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.
|
685
686
|
|
686
|
-
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`:
|
687
688
|
|
688
689
|
```ruby
|
689
690
|
config.log_level = :warn
|
@@ -694,32 +695,50 @@ config.log_level = :warn
|
|
694
695
|
|
695
696
|
Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
|
696
697
|
|
697
|
-
|
698
|
+
### Rails API Mode
|
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). 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/))
|
698
701
|
|
699
|
-
|
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))
|
700
704
|
|
701
|
-
|
705
|
+
The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
|
702
706
|
|
703
707
|
```ruby
|
704
|
-
config.
|
708
|
+
config.http_authenticatable = [:database]
|
705
709
|
```
|
706
710
|
|
707
|
-
|
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/).
|
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:
|
716
|
+
|
717
|
+
```ruby
|
718
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
|
719
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
|
720
|
+
```
|
721
|
+
|
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
|
708
727
|
|
709
728
|
### Warden
|
710
729
|
|
711
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:
|
712
731
|
|
713
|
-
https://github.com/
|
732
|
+
https://github.com/wardencommunity/warden
|
714
733
|
|
715
734
|
### Contributors
|
716
735
|
|
717
736
|
We have a long list of valued contributors. Check them all at:
|
718
737
|
|
719
|
-
https://github.com/
|
738
|
+
https://github.com/heartcombo/devise/graphs/contributors
|
720
739
|
|
721
740
|
## License
|
722
741
|
|
723
|
-
MIT License. Copyright 2009-
|
742
|
+
MIT License. Copyright 2020 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
724
743
|
|
725
|
-
|
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?
|