devise 3.5.10 → 4.7.3
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 +5 -5
- data/CHANGELOG.md +265 -1129
- data/MIT-LICENSE +2 -1
- data/README.md +291 -96
- data/app/controllers/devise/confirmations_controller.rb +3 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -6
- data/app/controllers/devise/passwords_controller.rb +7 -4
- data/app/controllers/devise/registrations_controller.rb +39 -18
- data/app/controllers/devise/sessions_controller.rb +9 -7
- data/app/controllers/devise/unlocks_controller.rb +4 -2
- data/app/controllers/devise_controller.rb +25 -12
- data/app/helpers/devise_helper.rb +23 -18
- data/app/mailers/devise/mailer.rb +10 -4
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +9 -5
- data/app/views/devise/registrations/new.html.erb +4 -4
- data/app/views/devise/sessions/new.html.erb +4 -4
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +7 -7
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +5 -2
- data/lib/devise/controllers/helpers.rb +30 -27
- data/lib/devise/controllers/rememberable.rb +3 -1
- data/lib/devise/controllers/scoped_views.rb +2 -0
- data/lib/devise/controllers/sign_in_out.rb +37 -14
- data/lib/devise/controllers/store_location.rb +25 -7
- data/lib/devise/controllers/url_helpers.rb +3 -1
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +6 -4
- data/lib/devise/failure_app.rb +75 -38
- data/lib/devise/hooks/activatable.rb +2 -0
- data/lib/devise/hooks/csrf_cleaner.rb +2 -0
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +6 -1
- data/lib/devise/hooks/proxy.rb +3 -1
- data/lib/devise/hooks/rememberable.rb +2 -0
- data/lib/devise/hooks/timeoutable.rb +4 -2
- data/lib/devise/hooks/trackable.rb +2 -0
- data/lib/devise/mailers/helpers.rb +7 -4
- data/lib/devise/mapping.rb +3 -1
- data/lib/devise/models/authenticatable.rb +57 -31
- data/lib/devise/models/confirmable.rb +90 -29
- data/lib/devise/models/database_authenticatable.rb +93 -22
- data/lib/devise/models/lockable.rb +11 -5
- data/lib/devise/models/omniauthable.rb +2 -0
- data/lib/devise/models/recoverable.rb +33 -21
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +6 -11
- data/lib/devise/models/timeoutable.rb +2 -0
- data/lib/devise/models/trackable.rb +15 -1
- data/lib/devise/models/validatable.rb +10 -3
- data/lib/devise/models.rb +3 -1
- data/lib/devise/modules.rb +2 -0
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +2 -0
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +139 -65
- data/lib/devise/rails/routes.rb +48 -37
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/rails.rb +7 -16
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +3 -1
- data/lib/devise/strategies/base.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +11 -4
- data/lib/devise/strategies/rememberable.rb +2 -0
- data/lib/devise/test/controller_helpers.rb +167 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +2 -0
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +57 -40
- data/lib/generators/active_record/devise_generator.rb +29 -10
- data/lib/generators/active_record/templates/migration.rb +4 -2
- data/lib/generators/active_record/templates/migration_existing.rb +4 -2
- data/lib/generators/devise/controllers_generator.rb +3 -1
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +18 -5
- data/lib/generators/devise/orm_helpers.rb +10 -21
- data/lib/generators/devise/views_generator.rb +8 -9
- data/lib/generators/mongoid/devise_generator.rb +7 -5
- data/lib/generators/templates/README +9 -8
- data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +3 -1
- data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +6 -4
- data/lib/generators/templates/controllers/sessions_controller.rb +4 -2
- data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
- data/lib/generators/templates/devise.rb +63 -21
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- data/lib/generators/templates/markerb/password_change.markerb +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
- metadata +15 -314
- data/.gitignore +0 -10
- data/.travis.yml +0 -44
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -16
- data/Gemfile +0 -30
- data/Gemfile.lock +0 -187
- data/Rakefile +0 -36
- data/devise.gemspec +0 -27
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +0 -29
- data/gemfiles/Gemfile.rails-3.2-stable.lock +0 -172
- data/gemfiles/Gemfile.rails-4.0-stable +0 -30
- data/gemfiles/Gemfile.rails-4.0-stable.lock +0 -166
- data/gemfiles/Gemfile.rails-4.1-stable +0 -30
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -30
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -193
- data/script/cached-bundle +0 -49
- data/script/s3-put +0 -71
- data/test/controllers/custom_registrations_controller_test.rb +0 -40
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helper_methods_test.rb +0 -21
- data/test/controllers/helpers_test.rb +0 -316
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -19
- data/test/controllers/passwords_controller_test.rb +0 -31
- data/test/controllers/sessions_controller_test.rb +0 -103
- data/test/controllers/url_helpers_test.rb +0 -65
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -107
- data/test/failure_app_test.rb +0 -315
- data/test/generators/active_record_generator_test.rb +0 -109
- data/test/generators/controllers_generator_test.rb +0 -48
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -103
- data/test/helpers/devise_helper_test.rb +0 -49
- data/test/integration/authenticatable_test.rb +0 -729
- data/test/integration/confirmable_test.rb +0 -324
- data/test/integration/database_authenticatable_test.rb +0 -95
- data/test/integration/http_authenticatable_test.rb +0 -105
- data/test/integration/lockable_test.rb +0 -239
- data/test/integration/omniauthable_test.rb +0 -135
- data/test/integration/recoverable_test.rb +0 -347
- data/test/integration/registerable_test.rb +0 -359
- data/test/integration/rememberable_test.rb +0 -214
- data/test/integration/timeoutable_test.rb +0 -184
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- data/test/mailers/reset_password_instructions_test.rb +0 -96
- data/test/mailers/unlock_instructions_test.rb +0 -91
- data/test/mapping_test.rb +0 -134
- data/test/models/authenticatable_test.rb +0 -23
- data/test/models/confirmable_test.rb +0 -511
- data/test/models/database_authenticatable_test.rb +0 -269
- data/test/models/lockable_test.rb +0 -350
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -251
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -169
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -41
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -153
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -81
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -6
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -7
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
- data/test/rails_app/app/active_record/user_without_email.rb +0 -8
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -6
- data/test/rails_app/app/controllers/application_controller.rb +0 -12
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -39
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -33
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -40
- data/test/rails_app/config/boot.rb +0 -14
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -30
- data/test/rails_app/config/environments/production.rb +0 -84
- data/test/rails_app/config/environments/test.rb +0 -41
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -180
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -125
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -17
- data/test/rails_app/lib/shared_user.rb +0 -29
- data/test/rails_app/lib/shared_user_without_email.rb +0 -26
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_test.rb +0 -9
- data/test/routes_test.rb +0 -264
- data/test/support/action_controller/record_identifier.rb +0 -10
- data/test/support/assertions.rb +0 -39
- data/test/support/helpers.rb +0 -77
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -34
- data/test/test_helpers_test.rb +0 -178
- data/test/test_models.rb +0 -33
- data/test/time_helpers.rb +0 -137
data/README.md
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-

|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
[](http://travis-ci.org/plataformatec/devise)
|
6
|
-
[](https://codeclimate.com/github/plataformatec/devise)
|
7
|
-
[](https://hakiri.io/github/plataformatec/devise/master)
|
8
|
-
|
9
|
-
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
3
|
+
[](http://travis-ci.org/heartcombo/devise)
|
4
|
+
[](https://codeclimate.com/github/heartcombo/devise)
|
10
5
|
|
11
6
|
Devise is a flexible authentication solution for Rails based on Warden. It:
|
12
7
|
|
@@ -17,18 +12,55 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
|
17
12
|
|
18
13
|
It's composed of 10 modules:
|
19
14
|
|
20
|
-
* [Database Authenticatable](http://rubydoc.info/github/
|
21
|
-
* [Omniauthable](http://rubydoc.info/github/
|
22
|
-
* [Confirmable](http://rubydoc.info/github/
|
23
|
-
* [Recoverable](http://rubydoc.info/github/
|
24
|
-
* [Registerable](http://rubydoc.info/github/
|
25
|
-
* [Rememberable](http://rubydoc.info/github/
|
26
|
-
* [Trackable](http://rubydoc.info/github/
|
27
|
-
* [Timeoutable](http://rubydoc.info/github/
|
28
|
-
* [Validatable](http://rubydoc.info/github/
|
29
|
-
* [Lockable](http://rubydoc.info/github/
|
15
|
+
* [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.
|
16
|
+
* [Omniauthable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
|
17
|
+
* [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.
|
18
|
+
* [Recoverable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
|
19
|
+
* [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.
|
20
|
+
* [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.
|
21
|
+
* [Trackable](http://www.rubydoc.info/github/heartcombo/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
|
22
|
+
* [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.
|
23
|
+
* [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.
|
24
|
+
* [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.
|
25
|
+
|
26
|
+
## Table of Contents
|
27
|
+
|
28
|
+
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 orderedList:0 -->
|
29
|
+
|
30
|
+
- [Information](#information)
|
31
|
+
- [The Devise wiki](#the-devise-wiki)
|
32
|
+
- [Bug reports](#bug-reports)
|
33
|
+
- [StackOverflow and Mailing List](#stackoverflow-and-mailing-list)
|
34
|
+
- [RDocs](#rdocs)
|
35
|
+
- [Example applications](#example-applications)
|
36
|
+
- [Extensions](#extensions)
|
37
|
+
- [Contributing](#contributing)
|
38
|
+
- [Starting with Rails?](#starting-with-rails)
|
39
|
+
- [Getting started](#getting-started)
|
40
|
+
- [Controller filters and helpers](#controller-filters-and-helpers)
|
41
|
+
- [Configuring Models](#configuring-models)
|
42
|
+
- [Strong Parameters](#strong-parameters)
|
43
|
+
- [Configuring views](#configuring-views)
|
44
|
+
- [Configuring controllers](#configuring-controllers)
|
45
|
+
- [Configuring routes](#configuring-routes)
|
46
|
+
- [I18n](#i18n)
|
47
|
+
- [Test helpers](#test-helpers)
|
48
|
+
- [Controller tests](#controller-tests)
|
49
|
+
- [Integration tests](#integration-tests)
|
50
|
+
- [OmniAuth](#omniauth)
|
51
|
+
- [Configuring multiple models](#configuring-multiple-models)
|
52
|
+
- [ActiveJob Integration](#activejob-integration)
|
53
|
+
- [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
|
54
|
+
- [Other ORMs](#other-orms)
|
55
|
+
- [Rails API mode](#rails-api-mode)
|
56
|
+
- [Additional information](#additional-information)
|
57
|
+
- [Warden](#warden)
|
58
|
+
- [Contributors](#contributors)
|
59
|
+
- [License](#license)
|
60
|
+
|
61
|
+
<!-- /TOC -->
|
62
|
+
|
30
63
|
|
31
|
-
Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby is in progress.
|
32
64
|
|
33
65
|
## Information
|
34
66
|
|
@@ -36,19 +68,23 @@ Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby i
|
|
36
68
|
|
37
69
|
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:
|
38
70
|
|
39
|
-
https://github.com/
|
71
|
+
https://github.com/heartcombo/devise/wiki
|
40
72
|
|
41
73
|
### Bug reports
|
42
74
|
|
43
75
|
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:
|
44
76
|
|
45
|
-
https://github.com/
|
77
|
+
https://github.com/heartcombo/devise/wiki/Bug-reports
|
46
78
|
|
47
|
-
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to
|
79
|
+
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo@googlegroups.com.
|
48
80
|
|
49
|
-
### Mailing
|
81
|
+
### StackOverflow and Mailing List
|
50
82
|
|
51
|
-
If you have any questions, comments, or concerns, please use
|
83
|
+
If you have any questions, comments, or concerns, please use StackOverflow instead of the GitHub issue tracker:
|
84
|
+
|
85
|
+
http://stackoverflow.com/questions/tagged/devise
|
86
|
+
|
87
|
+
The deprecated mailing list can still be read on
|
52
88
|
|
53
89
|
https://groups.google.com/group/plataformatec-devise
|
54
90
|
|
@@ -56,7 +92,7 @@ https://groups.google.com/group/plataformatec-devise
|
|
56
92
|
|
57
93
|
You can view the Devise documentation in RDoc format here:
|
58
94
|
|
59
|
-
http://rubydoc.info/github/
|
95
|
+
http://rubydoc.info/github/heartcombo/devise/master/frames
|
60
96
|
|
61
97
|
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.
|
62
98
|
|
@@ -64,65 +100,115 @@ If you need to use Devise with previous versions of Rails, you can always run "g
|
|
64
100
|
|
65
101
|
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:
|
66
102
|
|
67
|
-
https://github.com/
|
103
|
+
https://github.com/heartcombo/devise/wiki/Example-Applications
|
68
104
|
|
69
105
|
### Extensions
|
70
106
|
|
71
107
|
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:
|
72
108
|
|
73
|
-
https://github.com/
|
109
|
+
https://github.com/heartcombo/devise/wiki/Extensions
|
74
110
|
|
75
111
|
### Contributing
|
76
112
|
|
77
113
|
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
78
114
|
|
79
|
-
https://github.com/
|
115
|
+
https://github.com/heartcombo/devise/wiki/Contributing
|
116
|
+
|
117
|
+
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`.
|
118
|
+
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`.
|
80
119
|
|
81
|
-
|
120
|
+
### DEVISE_ORM
|
121
|
+
Since Devise support both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
|
122
|
+
The default value of `DEVISE_ORM` is `active_record`. To run the tests for Mongoid, you can pass `mongoid`:
|
123
|
+
```
|
124
|
+
DEVISE_ORM=mongoid bin/test
|
125
|
+
|
126
|
+
==> Devise.orm = :mongoid
|
127
|
+
```
|
128
|
+
When running the tests for Mongoid, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
|
129
|
+
|
130
|
+
Please note that the command output will show the variable value being used.
|
131
|
+
|
132
|
+
### BUNDLE_GEMFILE
|
133
|
+
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
|
134
|
+
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 on Travis using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
|
135
|
+
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
|
136
|
+
```bash
|
137
|
+
rbenv shell 2.4.2 # or rvm use 2.4.2
|
138
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
|
139
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bin/test
|
140
|
+
```
|
141
|
+
|
142
|
+
You can also combine both of them if the tests broke for Mongoid:
|
143
|
+
```bash
|
144
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
|
145
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable DEVISE_ORM=mongoid bin/test
|
146
|
+
```
|
147
|
+
|
148
|
+
### Running tests
|
149
|
+
Devise uses [Mini Test](https://github.com/seattlerb/minitest) as test framework.
|
150
|
+
|
151
|
+
* Running all tests:
|
152
|
+
```bash
|
153
|
+
bin/test
|
154
|
+
```
|
155
|
+
|
156
|
+
* Running tests for an specific file:
|
157
|
+
```bash
|
158
|
+
bin/test test/models/trackable_test.rb
|
159
|
+
```
|
160
|
+
|
161
|
+
* Running a specific test given a regex:
|
162
|
+
```bash
|
163
|
+
bin/test test/models/trackable_test.rb:16
|
164
|
+
```
|
82
165
|
|
83
166
|
## Starting with Rails?
|
84
167
|
|
85
|
-
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.
|
168
|
+
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:
|
86
169
|
|
87
170
|
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
88
|
-
* Ryan Bates'
|
89
|
-
* Codecademy's Ruby on Rails: Authentication and Authorization:
|
171
|
+
* Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
|
172
|
+
* Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
|
90
173
|
|
91
174
|
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
92
175
|
|
93
176
|
## Getting started
|
94
177
|
|
95
|
-
Devise
|
178
|
+
Devise 4.0 works with Rails 4.1 onwards. Add the following line to your Gemfile:
|
96
179
|
|
97
180
|
```ruby
|
98
181
|
gem 'devise'
|
99
182
|
```
|
100
183
|
|
101
|
-
|
184
|
+
Then run `bundle install`
|
102
185
|
|
103
|
-
|
186
|
+
Next, you need to run the generator:
|
104
187
|
|
105
188
|
```console
|
106
|
-
rails generate devise:install
|
189
|
+
$ rails generate devise:install
|
107
190
|
```
|
108
191
|
|
109
|
-
|
192
|
+
At this point, a number of instructions will appear in the console. Among these instructions, you'll need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
110
193
|
|
111
|
-
```
|
112
|
-
|
194
|
+
```ruby
|
195
|
+
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
113
196
|
```
|
114
197
|
|
115
|
-
|
198
|
+
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.
|
116
199
|
|
117
|
-
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration. Then run `rake db:migrate`
|
118
200
|
|
119
|
-
|
201
|
+
In the following command you will replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
|
120
202
|
|
121
|
-
```
|
122
|
-
|
203
|
+
```console
|
204
|
+
$ rails generate devise MODEL
|
123
205
|
```
|
124
206
|
|
125
|
-
|
207
|
+
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
|
208
|
+
|
209
|
+
Then run `rails db:migrate`
|
210
|
+
|
211
|
+
You should restart your application after changing Devise's configuration options (this includes stopping spring). Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
|
126
212
|
|
127
213
|
### Controller filters and helpers
|
128
214
|
|
@@ -132,6 +218,8 @@ Devise will create some helpers to use inside your controllers and views. To set
|
|
132
218
|
before_action :authenticate_user!
|
133
219
|
```
|
134
220
|
|
221
|
+
For Rails 5, note that `protect_from_forgery` is no longer prepended to the `before_action` chain, so if you have set `authenticate_user` before `protect_from_forgery`, your request will result in "Can't verify CSRF token authenticity." To resolve this, either change the order in which you call them, or use `protect_from_forgery prepend: true`.
|
222
|
+
|
135
223
|
If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
|
136
224
|
|
137
225
|
To verify if a user is signed in, use the following helper:
|
@@ -155,7 +243,7 @@ user_session
|
|
155
243
|
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
|
156
244
|
|
157
245
|
```ruby
|
158
|
-
root to:
|
246
|
+
root to: 'home#index'
|
159
247
|
```
|
160
248
|
|
161
249
|
You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
|
@@ -174,25 +262,43 @@ member_session
|
|
174
262
|
|
175
263
|
### Configuring Models
|
176
264
|
|
177
|
-
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the
|
265
|
+
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:
|
178
266
|
|
179
267
|
```ruby
|
180
|
-
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches:
|
268
|
+
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
|
181
269
|
```
|
182
270
|
|
183
271
|
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`.
|
184
272
|
|
185
273
|
### Strong Parameters
|
186
274
|
|
275
|
+
The Parameter Sanitizer API has changed for Devise 4 :warning:
|
276
|
+
|
277
|
+
*For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
|
278
|
+
|
187
279
|
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.
|
188
280
|
|
189
|
-
There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and
|
281
|
+
There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and default permitted parameters are:
|
190
282
|
|
191
283
|
* `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
|
192
284
|
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
193
285
|
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
194
286
|
|
195
|
-
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before
|
287
|
+
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
class ApplicationController < ActionController::Base
|
291
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
292
|
+
|
293
|
+
protected
|
294
|
+
|
295
|
+
def configure_permitted_parameters
|
296
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
|
297
|
+
end
|
298
|
+
end
|
299
|
+
```
|
300
|
+
|
301
|
+
The above works for any additional fields where the parameters are simple scalar types. If you have nested attributes (say you're using `accepts_nested_attributes_for`), then you will need to tell devise about those nestings and types:
|
196
302
|
|
197
303
|
```ruby
|
198
304
|
class ApplicationController < ActionController::Base
|
@@ -201,18 +307,20 @@ class ApplicationController < ActionController::Base
|
|
201
307
|
protected
|
202
308
|
|
203
309
|
def configure_permitted_parameters
|
204
|
-
devise_parameter_sanitizer.
|
310
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, address_attributes: [:country, :state, :city, :area, :postal_code]])
|
205
311
|
end
|
206
312
|
end
|
207
313
|
```
|
208
314
|
|
209
|
-
|
315
|
+
Devise allows you to completely change Devise defaults or invoke custom behavior by passing a block:
|
210
316
|
|
211
317
|
To permit simple scalar values for username and email, use this
|
212
318
|
|
213
319
|
```ruby
|
214
320
|
def configure_permitted_parameters
|
215
|
-
devise_parameter_sanitizer.
|
321
|
+
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
|
322
|
+
user_params.permit(:username, :email)
|
323
|
+
end
|
216
324
|
end
|
217
325
|
```
|
218
326
|
|
@@ -220,7 +328,9 @@ If you have some checkboxes that express the roles a user may take on registrati
|
|
220
328
|
|
221
329
|
```ruby
|
222
330
|
def configure_permitted_parameters
|
223
|
-
devise_parameter_sanitizer.
|
331
|
+
devise_parameter_sanitizer.permit(:sign_up) do |user_params|
|
332
|
+
user_params.permit({ roles: [] }, :email, :password, :password_confirmation)
|
333
|
+
end
|
224
334
|
end
|
225
335
|
```
|
226
336
|
For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
|
@@ -231,8 +341,9 @@ If you have multiple Devise models, you may want to set up a different parameter
|
|
231
341
|
|
232
342
|
```ruby
|
233
343
|
class User::ParameterSanitizer < Devise::ParameterSanitizer
|
234
|
-
def
|
235
|
-
|
344
|
+
def initialize(*)
|
345
|
+
super
|
346
|
+
permit(:sign_up, keys: [:username, :email])
|
236
347
|
end
|
237
348
|
end
|
238
349
|
```
|
@@ -262,7 +373,7 @@ We built Devise to help you quickly develop an application that uses authenticat
|
|
262
373
|
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
|
263
374
|
|
264
375
|
```console
|
265
|
-
rails generate devise:views
|
376
|
+
$ rails generate devise:views
|
266
377
|
```
|
267
378
|
|
268
379
|
If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
|
@@ -270,14 +381,14 @@ If you have more than one Devise model in your application (such as `User` and `
|
|
270
381
|
After doing so, you will be able to have views based on the role like `users/sessions/new` and `admins/sessions/new`. If no view is found within the scope, Devise will use the default view at `devise/sessions/new`. You can also use the generator to generate scoped views:
|
271
382
|
|
272
383
|
```console
|
273
|
-
rails generate devise:views users
|
384
|
+
$ rails generate devise:views users
|
274
385
|
```
|
275
386
|
|
276
387
|
If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
|
277
388
|
you can pass a list of modules to the generator with the `-v` flag.
|
278
389
|
|
279
390
|
```console
|
280
|
-
rails generate devise:views -v registrations confirmations
|
391
|
+
$ rails generate devise:views -v registrations confirmations
|
281
392
|
```
|
282
393
|
|
283
394
|
### Configuring controllers
|
@@ -287,7 +398,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
287
398
|
1. Create your custom controllers using the generator which requires a scope:
|
288
399
|
|
289
400
|
```console
|
290
|
-
rails generate devise:controllers [scope]
|
401
|
+
$ rails generate devise:controllers [scope]
|
291
402
|
```
|
292
403
|
|
293
404
|
If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
|
@@ -302,11 +413,12 @@ If the customization at the views level is not enough, you can customize each co
|
|
302
413
|
...
|
303
414
|
end
|
304
415
|
```
|
416
|
+
(Use the -c flag to specify a controller, for example: `rails generate devise:controllers users -c=sessions`)
|
305
417
|
|
306
418
|
2. Tell the router to use this controller:
|
307
419
|
|
308
420
|
```ruby
|
309
|
-
devise_for :users, controllers: { sessions:
|
421
|
+
devise_for :users, controllers: { sessions: 'users/sessions' }
|
310
422
|
```
|
311
423
|
|
312
424
|
3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
|
@@ -323,7 +435,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
323
435
|
end
|
324
436
|
```
|
325
437
|
|
326
|
-
Or you can simply add new
|
438
|
+
Or you can simply add new behavior to it:
|
327
439
|
|
328
440
|
```ruby
|
329
441
|
class Users::SessionsController < Devise::SessionsController
|
@@ -344,21 +456,27 @@ Remember that Devise uses flash messages to let users know if sign in was succes
|
|
344
456
|
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
|
345
457
|
|
346
458
|
```ruby
|
347
|
-
devise_for :users, path:
|
459
|
+
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' }
|
348
460
|
```
|
349
461
|
|
350
|
-
Be sure to check `devise_for` documentation for details.
|
462
|
+
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/heartcombo/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
|
351
463
|
|
352
464
|
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:
|
353
465
|
|
354
466
|
```ruby
|
355
467
|
devise_scope :user do
|
356
|
-
get
|
468
|
+
get 'sign_in', to: 'devise/sessions#new'
|
357
469
|
end
|
358
470
|
```
|
359
471
|
|
360
472
|
This way, you tell Devise to use the scope `:user` when "/sign_in" is accessed. Notice `devise_scope` is also aliased as `as` in your router.
|
361
473
|
|
474
|
+
Please note: You will still need to add `devise_for` in your routes in order to use helper methods such as `current_user`.
|
475
|
+
|
476
|
+
```ruby
|
477
|
+
devise_for :users, skip: :all
|
478
|
+
```
|
479
|
+
|
362
480
|
### I18n
|
363
481
|
|
364
482
|
Devise uses flash messages with I18n, in conjunction with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
@@ -397,54 +515,113 @@ en:
|
|
397
515
|
|
398
516
|
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:
|
399
517
|
|
400
|
-
https://github.com/
|
518
|
+
https://github.com/heartcombo/devise/wiki/I18n
|
401
519
|
|
402
520
|
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
|
403
521
|
|
404
522
|
### Test helpers
|
405
523
|
|
406
|
-
Devise includes some test helpers for
|
524
|
+
Devise includes some test helpers for controller and integration tests.
|
525
|
+
In order to use them, you need to include the respective module in your test
|
526
|
+
cases/specs.
|
527
|
+
|
528
|
+
### Controller tests
|
529
|
+
|
530
|
+
Controller tests require that you include `Devise::Test::IntegrationHelpers` on
|
531
|
+
your test case or its parent `ActionController::TestCase` superclass.
|
532
|
+
For Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass
|
533
|
+
for controller tests was changed to ActionDispatch::IntegrationTest
|
534
|
+
(for more details, see the [Integration tests](#integration-tests) section).
|
535
|
+
|
536
|
+
```ruby
|
537
|
+
class PostsControllerTest < ActionController::TestCase
|
538
|
+
include Devise::Test::IntegrationHelpers # Rails >= 5
|
539
|
+
end
|
540
|
+
```
|
407
541
|
|
408
542
|
```ruby
|
409
|
-
class ActionController::TestCase
|
410
|
-
include Devise::
|
543
|
+
class PostsControllerTest < ActionController::TestCase
|
544
|
+
include Devise::Test::ControllerHelpers # Rails < 5
|
411
545
|
end
|
412
546
|
```
|
413
547
|
|
414
|
-
If you're using RSpec, you can put the following inside a file named
|
548
|
+
If you're using RSpec, you can put the following inside a file named
|
549
|
+
`spec/support/devise.rb` or in your `spec/spec_helper.rb` (or
|
550
|
+
`spec/rails_helper.rb` if you are using `rspec-rails`):
|
415
551
|
|
416
552
|
```ruby
|
417
553
|
RSpec.configure do |config|
|
418
|
-
config.include Devise::
|
554
|
+
config.include Devise::Test::ControllerHelpers, type: :controller
|
555
|
+
config.include Devise::Test::ControllerHelpers, type: :view
|
419
556
|
end
|
420
557
|
```
|
421
558
|
|
422
559
|
Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
|
423
560
|
|
424
|
-
Now you are ready to use the `sign_in` and `sign_out` methods
|
561
|
+
Now you are ready to use the `sign_in` and `sign_out` methods on your controller
|
562
|
+
tests:
|
425
563
|
|
426
564
|
```ruby
|
427
|
-
sign_in
|
428
|
-
sign_in @user
|
565
|
+
sign_in @user
|
566
|
+
sign_in @user, scope: :admin
|
567
|
+
```
|
568
|
+
|
569
|
+
If you are testing Devise internal controllers or a controller that inherits
|
570
|
+
from Devise's, you need to tell Devise which mapping should be used before a
|
571
|
+
request. This is necessary because Devise gets this information from the router,
|
572
|
+
but since controller tests do not pass through the router, it needs to be stated
|
573
|
+
explicitly. For example, if you are testing the user scope, simply use:
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
test 'GET new' do
|
577
|
+
# Mimic the router behavior of setting the Devise scope through the env.
|
578
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
579
|
+
|
580
|
+
# Use the sign_in helper to sign in a fixture `User` record.
|
581
|
+
sign_in users(:alice)
|
582
|
+
|
583
|
+
get :new
|
429
584
|
|
430
|
-
|
431
|
-
|
585
|
+
# assert something
|
586
|
+
end
|
432
587
|
```
|
433
588
|
|
434
|
-
|
589
|
+
### Integration tests
|
435
590
|
|
436
|
-
|
591
|
+
Integration test helpers are available by including the
|
592
|
+
`Devise::Test::IntegrationHelpers` module.
|
437
593
|
|
438
|
-
|
594
|
+
```ruby
|
595
|
+
class PostsTests < ActionDispatch::IntegrationTest
|
596
|
+
include Devise::Test::IntegrationHelpers
|
597
|
+
end
|
598
|
+
```
|
439
599
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
600
|
+
Now you can use the following `sign_in` and `sign_out` methods in your integration
|
601
|
+
tests:
|
602
|
+
|
603
|
+
```ruby
|
604
|
+
sign_in users(:bob)
|
605
|
+
sign_in users(:bob), scope: :admin
|
606
|
+
|
607
|
+
sign_out :user
|
608
|
+
```
|
609
|
+
|
610
|
+
RSpec users can include the `IntegrationHelpers` module on their `:feature` specs.
|
611
|
+
|
612
|
+
```ruby
|
613
|
+
RSpec.configure do |config|
|
614
|
+
config.include Devise::Test::IntegrationHelpers, type: :feature
|
615
|
+
end
|
616
|
+
```
|
617
|
+
|
618
|
+
Unlike controller tests, integration tests do not need to supply the
|
619
|
+
`devise.mapping` `env` value, as the mapping can be inferred by the routes that
|
620
|
+
are executed in your tests.
|
444
621
|
|
445
622
|
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
446
623
|
|
447
|
-
* https://github.com/
|
624
|
+
* https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
|
448
625
|
|
449
626
|
### OmniAuth
|
450
627
|
|
@@ -456,7 +633,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
|
456
633
|
|
457
634
|
You can read more about OmniAuth support in the wiki:
|
458
635
|
|
459
|
-
* https://github.com/
|
636
|
+
* https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
|
460
637
|
|
461
638
|
### Configuring multiple models
|
462
639
|
|
@@ -477,7 +654,7 @@ devise :database_authenticatable, :timeoutable
|
|
477
654
|
devise_for :admins
|
478
655
|
|
479
656
|
# Inside your protected controller
|
480
|
-
|
657
|
+
before_action :authenticate_admin!
|
481
658
|
|
482
659
|
# Inside your controllers and views
|
483
660
|
admin_signed_in?
|
@@ -503,7 +680,7 @@ end
|
|
503
680
|
|
504
681
|
### Password reset tokens and Rails logs
|
505
682
|
|
506
|
-
If you enable the [Recoverable](http://rubydoc.info/github/
|
683
|
+
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:
|
507
684
|
|
508
685
|
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.
|
509
686
|
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.
|
@@ -519,32 +696,50 @@ config.log_level = :warn
|
|
519
696
|
|
520
697
|
Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
|
521
698
|
|
522
|
-
|
699
|
+
### Rails API Mode
|
700
|
+
|
701
|
+
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/))
|
523
702
|
|
524
|
-
|
703
|
+
#### Supported Authentication Strategies
|
704
|
+
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))
|
525
705
|
|
526
|
-
|
706
|
+
The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
|
527
707
|
|
528
708
|
```ruby
|
529
|
-
config.
|
709
|
+
config.http_authenticatable = [:database]
|
530
710
|
```
|
531
711
|
|
532
|
-
|
712
|
+
This restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.
|
713
|
+
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/).
|
714
|
+
|
715
|
+
#### Testing
|
716
|
+
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:
|
717
|
+
|
718
|
+
```ruby
|
719
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
|
720
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
|
721
|
+
```
|
722
|
+
|
723
|
+
For a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).
|
724
|
+
|
725
|
+
Additionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.
|
726
|
+
|
727
|
+
## Additional information
|
533
728
|
|
534
729
|
### Warden
|
535
730
|
|
536
731
|
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:
|
537
732
|
|
538
|
-
https://github.com/
|
733
|
+
https://github.com/wardencommunity/warden
|
539
734
|
|
540
735
|
### Contributors
|
541
736
|
|
542
737
|
We have a long list of valued contributors. Check them all at:
|
543
738
|
|
544
|
-
https://github.com/
|
739
|
+
https://github.com/heartcombo/devise/graphs/contributors
|
545
740
|
|
546
741
|
## License
|
547
742
|
|
548
|
-
MIT License. Copyright 2009-
|
743
|
+
MIT License. Copyright 2020 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
549
744
|
|
550
|
-
|
745
|
+
The Devise logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).
|