devise_token_auth 0.1.1 → 1.3.0
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/LICENSE +13 -0
- data/README.md +97 -0
- data/Rakefile +12 -4
- data/app/controllers/devise_token_auth/application_controller.rb +89 -22
- data/app/controllers/devise_token_auth/concerns/resource_finder.rb +58 -0
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +199 -0
- data/app/controllers/devise_token_auth/confirmations_controller.rb +79 -14
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +284 -0
- data/app/controllers/devise_token_auth/passwords_controller.rb +196 -35
- data/app/controllers/devise_token_auth/registrations_controller.rb +191 -20
- data/app/controllers/devise_token_auth/sessions_controller.rb +130 -21
- data/app/controllers/devise_token_auth/token_validations_controller.rb +31 -0
- data/app/controllers/devise_token_auth/unlocks_controller.rb +94 -0
- data/app/models/devise_token_auth/concerns/active_record_support.rb +18 -0
- data/app/models/devise_token_auth/concerns/confirmable_support.rb +28 -0
- data/app/models/devise_token_auth/concerns/mongoid_support.rb +19 -0
- data/app/models/devise_token_auth/concerns/tokens_serialization.rb +31 -0
- data/app/models/devise_token_auth/concerns/user.rb +287 -0
- data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +35 -0
- data/app/validators/devise_token_auth_email_validator.rb +31 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise_token_auth/omniauth_external_window.html.erb +38 -0
- data/config/locales/da-DK.yml +52 -0
- data/config/locales/de.yml +51 -0
- data/config/locales/en.yml +60 -0
- data/config/locales/es.yml +51 -0
- data/config/locales/fa.yml +60 -0
- data/config/locales/fr.yml +51 -0
- data/config/locales/he.yml +52 -0
- data/config/locales/it.yml +48 -0
- data/config/locales/ja.yml +60 -0
- data/config/locales/ko.yml +51 -0
- data/config/locales/nl.yml +32 -0
- data/config/locales/pl.yml +51 -0
- data/config/locales/pt-BR.yml +48 -0
- data/config/locales/pt.yml +51 -0
- data/config/locales/ro.yml +48 -0
- data/config/locales/ru.yml +52 -0
- data/config/locales/sq.yml +48 -0
- data/config/locales/sv.yml +52 -0
- data/config/locales/uk.yml +61 -0
- data/config/locales/vi.yml +52 -0
- data/config/locales/zh-CN.yml +48 -0
- data/config/locales/zh-HK.yml +50 -0
- data/config/locales/zh-TW.yml +50 -0
- data/lib/devise_token_auth/blacklist.rb +6 -0
- data/lib/devise_token_auth/controllers/helpers.rb +157 -0
- data/lib/devise_token_auth/controllers/url_helpers.rb +10 -0
- data/lib/devise_token_auth/engine.rb +100 -0
- data/lib/devise_token_auth/errors.rb +8 -0
- data/lib/devise_token_auth/rails/routes.rb +135 -0
- data/lib/devise_token_auth/token_factory.rb +126 -0
- data/lib/devise_token_auth/url.rb +44 -0
- data/lib/devise_token_auth/version.rb +3 -1
- data/lib/devise_token_auth.rb +11 -2
- data/lib/generators/devise_token_auth/USAGE +27 -4
- data/lib/generators/devise_token_auth/install_generator.rb +91 -0
- data/lib/generators/devise_token_auth/install_generator_helpers.rb +98 -0
- data/lib/generators/devise_token_auth/install_mongoid_generator.rb +46 -0
- data/lib/generators/devise_token_auth/install_views_generator.rb +18 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +66 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +49 -0
- data/lib/generators/devise_token_auth/templates/user.rb.erb +9 -0
- data/lib/generators/devise_token_auth/templates/user_mongoid.rb.erb +56 -0
- data/lib/tasks/devise_token_auth_tasks.rake +2 -0
- data/test/controllers/custom/custom_confirmations_controller_test.rb +25 -0
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +33 -0
- data/test/controllers/custom/custom_passwords_controller_test.rb +79 -0
- data/test/controllers/custom/custom_registrations_controller_test.rb +63 -0
- data/test/controllers/custom/custom_sessions_controller_test.rb +39 -0
- data/test/controllers/custom/custom_token_validations_controller_test.rb +42 -0
- data/test/controllers/demo_group_controller_test.rb +151 -0
- data/test/controllers/demo_mang_controller_test.rb +313 -0
- data/test/controllers/demo_user_controller_test.rb +658 -0
- data/test/controllers/devise_token_auth/confirmations_controller_test.rb +275 -0
- data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +438 -0
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +893 -0
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +920 -0
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +605 -0
- data/test/controllers/devise_token_auth/token_validations_controller_test.rb +142 -0
- data/test/controllers/devise_token_auth/unlocks_controller_test.rb +235 -0
- data/test/controllers/overrides/confirmations_controller_test.rb +47 -0
- data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +53 -0
- data/test/controllers/overrides/passwords_controller_test.rb +64 -0
- data/test/controllers/overrides/registrations_controller_test.rb +46 -0
- data/test/controllers/overrides/sessions_controller_test.rb +35 -0
- data/test/controllers/overrides/token_validations_controller_test.rb +43 -0
- data/test/dummy/app/active_record/confirmable_user.rb +11 -0
- data/test/dummy/app/active_record/lockable_user.rb +7 -0
- data/test/dummy/app/active_record/mang.rb +5 -0
- data/test/dummy/app/active_record/only_email_user.rb +7 -0
- data/test/dummy/app/active_record/scoped_user.rb +9 -0
- data/test/dummy/app/active_record/unconfirmable_user.rb +9 -0
- data/test/dummy/app/active_record/unregisterable_user.rb +9 -0
- data/test/dummy/app/active_record/user.rb +6 -0
- data/test/dummy/app/controllers/application_controller.rb +12 -3
- data/test/dummy/app/controllers/auth_origin_controller.rb +7 -0
- data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/passwords_controller.rb +39 -0
- data/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
- data/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
- data/test/dummy/app/controllers/custom/token_validations_controller.rb +19 -0
- data/test/dummy/app/controllers/demo_group_controller.rb +15 -0
- data/test/dummy/app/controllers/demo_mang_controller.rb +14 -0
- data/test/dummy/app/controllers/demo_user_controller.rb +27 -0
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +29 -0
- data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +16 -0
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +36 -0
- data/test/dummy/app/controllers/overrides/registrations_controller.rb +29 -0
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
- data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
- data/test/dummy/app/helpers/application_helper.rb +1056 -0
- data/test/dummy/app/models/concerns/favorite_color.rb +19 -0
- data/test/dummy/app/mongoid/confirmable_user.rb +52 -0
- data/test/dummy/app/mongoid/lockable_user.rb +38 -0
- data/test/dummy/app/mongoid/mang.rb +46 -0
- data/test/dummy/app/mongoid/only_email_user.rb +33 -0
- data/test/dummy/app/mongoid/scoped_user.rb +50 -0
- data/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
- data/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
- data/test/dummy/app/mongoid/user.rb +49 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -2
- data/test/dummy/config/application.rb +25 -8
- data/test/dummy/config/application.yml.bk +0 -0
- data/test/dummy/config/boot.rb +8 -2
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/development.rb +10 -11
- data/test/dummy/config/environments/production.rb +3 -17
- data/test/dummy/config/environments/test.rb +25 -3
- data/test/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -1
- data/{config → test/dummy/config}/initializers/devise.rb +63 -31
- data/test/dummy/config/initializers/devise_token_auth.rb +55 -0
- data/test/dummy/config/initializers/figaro.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/test/dummy/config/initializers/inflections.rb +2 -0
- data/test/dummy/config/initializers/mime_types.rb +2 -0
- data/test/dummy/config/initializers/omniauth.rb +7 -1
- data/test/dummy/config/initializers/session_store.rb +2 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/test/dummy/config/routes.rb +55 -1
- data/test/dummy/config/spring.rb +3 -0
- data/test/dummy/config.ru +14 -0
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +58 -0
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +57 -0
- data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +8 -0
- data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +7 -0
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +55 -0
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +56 -0
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +56 -0
- data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +56 -0
- data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +56 -0
- data/test/dummy/db/migrate/20190924101113_devise_token_auth_create_confirmable_users.rb +49 -0
- data/test/dummy/db/schema.rb +180 -28
- data/test/dummy/lib/migration_database_helper.rb +43 -0
- data/test/dummy/tmp/generators/app/models/user.rb +11 -0
- data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +66 -0
- data/{db/migrate/20140628234942_devise_token_auth_create_users.rb → test/dummy/tmp/generators/db/migrate/20240519164408_devise_token_auth_create_users.rb} +16 -23
- data/test/factories/users.rb +41 -0
- data/test/lib/devise_token_auth/blacklist_test.rb +19 -0
- data/test/lib/devise_token_auth/rails/custom_routes_test.rb +30 -0
- data/test/lib/devise_token_auth/rails/routes_test.rb +87 -0
- data/test/lib/devise_token_auth/token_factory_test.rb +191 -0
- data/test/lib/devise_token_auth/url_test.rb +26 -0
- data/test/lib/generators/devise_token_auth/install_generator_test.rb +217 -0
- data/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +222 -0
- data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +25 -0
- data/test/models/concerns/mongoid_support_test.rb +31 -0
- data/test/models/concerns/tokens_serialization_test.rb +104 -0
- data/test/models/confirmable_user_test.rb +35 -0
- data/test/models/only_email_user_test.rb +29 -0
- data/test/models/user_test.rb +251 -0
- data/test/support/controllers/routes.rb +43 -0
- data/test/test_helper.rb +136 -10
- metadata +368 -80
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -3
- data/app/assets/javascripts/devise_token_auth/application.js +0 -13
- data/app/assets/stylesheets/devise_token_auth/application.css +0 -15
- data/app/controllers/devise_token_auth/auth_controller.rb +0 -62
- data/app/helpers/devise_token_auth/application_helper.rb +0 -4
- data/app/models/user.rb +0 -6
- data/app/views/devise_token_auth/omniauth_success.html.erb +0 -7
- data/app/views/layouts/omniauth_response.html.erb +0 -20
- data/config/locales/devise.en.yml +0 -59
- data/config/routes.rb +0 -14
- data/lib/generators/devise_token_auth/devise_token_auth_generator.rb +0 -3
- data/test/devise_token_auth_test.rb +0 -7
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/config/application.yml +0 -13
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/initializers/assets.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140629011345_devise_token_auth_create_users.devise_token_auth.rb +0 -57
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -3406
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +0 -10
- data/test/lib/generators/devise_token_auth/devise_token_auth_generator_test.rb +0 -16
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Use this hook to configure devise mailer, warden hooks and so forth.
|
|
2
4
|
# Many of these configuration options can be set straight in your model.
|
|
3
5
|
Devise.setup do |config|
|
|
4
6
|
# The secret key used by Devise. Devise uses this key to generate
|
|
5
7
|
# random tokens. Changing this key will render invalid all existing
|
|
6
8
|
# confirmation, reset password and unlock tokens in the database.
|
|
7
|
-
#
|
|
9
|
+
# Devise will use the `secret_key_base` as its `secret_key`
|
|
10
|
+
# by default. You can change it below and use your own secret key.
|
|
11
|
+
# config.secret_key = '981f041712ce247008f46fec55e5d3e7fea904bd1601412a5810c74af3f1d9c33399bc34405b85a78dac04c9fb017270e691305b3ddb073f93578df124538e89'
|
|
12
|
+
|
|
13
|
+
# ==> Controller configuration
|
|
14
|
+
# Configure the parent class to the devise controllers.
|
|
15
|
+
# config.parent_controller = 'DeviseController'
|
|
8
16
|
|
|
9
17
|
# ==> Mailer Configuration
|
|
10
18
|
# Configure the e-mail address which will be shown in Devise::Mailer,
|
|
@@ -15,11 +23,14 @@ Devise.setup do |config|
|
|
|
15
23
|
# Configure the class responsible to send e-mails.
|
|
16
24
|
# config.mailer = 'Devise::Mailer'
|
|
17
25
|
|
|
26
|
+
# Configure the parent class responsible to send e-mails.
|
|
27
|
+
# config.parent_mailer = 'ActionMailer::Base'
|
|
28
|
+
|
|
18
29
|
# ==> ORM configuration
|
|
19
30
|
# Load and configure the ORM. Supports :active_record (default) and
|
|
20
31
|
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
|
21
32
|
# available as additional gems.
|
|
22
|
-
require
|
|
33
|
+
require "devise/orm/#{DEVISE_TOKEN_AUTH_ORM}"
|
|
23
34
|
|
|
24
35
|
# ==> Configuration for any authentication mechanism
|
|
25
36
|
# Configure which keys are used when authenticating a user. The default is
|
|
@@ -29,7 +40,7 @@ Devise.setup do |config|
|
|
|
29
40
|
# session. If you need permissions, you should implement that in a before filter.
|
|
30
41
|
# You can also supply a hash where the value is a boolean determining whether
|
|
31
42
|
# or not authentication should be aborted when the value is not present.
|
|
32
|
-
|
|
43
|
+
config.authentication_keys = [:email, :nickname]
|
|
33
44
|
|
|
34
45
|
# Configure parameters from the request object used for authentication. Each entry
|
|
35
46
|
# given should be a request method and it will automatically be passed to the
|
|
@@ -41,12 +52,12 @@ Devise.setup do |config|
|
|
|
41
52
|
# Configure which authentication keys should be case-insensitive.
|
|
42
53
|
# These keys will be downcased upon creating or modifying a user and when used
|
|
43
54
|
# to authenticate or find a user. Default is :email.
|
|
44
|
-
config.case_insensitive_keys = [
|
|
55
|
+
config.case_insensitive_keys = [:email]
|
|
45
56
|
|
|
46
57
|
# Configure which authentication keys should have whitespace stripped.
|
|
47
58
|
# These keys will have whitespace before and after removed upon creating or
|
|
48
59
|
# modifying a user and when used to authenticate or find a user. Default is :email.
|
|
49
|
-
config.strip_whitespace_keys = [
|
|
60
|
+
config.strip_whitespace_keys = [:email]
|
|
50
61
|
|
|
51
62
|
# Tell if authentication through request.params is enabled. True by default.
|
|
52
63
|
# It can be set to an array that will enable params authentication only for the
|
|
@@ -61,7 +72,7 @@ Devise.setup do |config|
|
|
|
61
72
|
# :database = Support basic authentication with authentication key + password
|
|
62
73
|
# config.http_authenticatable = false
|
|
63
74
|
|
|
64
|
-
# If
|
|
75
|
+
# If 401 status code should be returned for AJAX requests. True by default.
|
|
65
76
|
# config.http_authenticatable_on_xhr = true
|
|
66
77
|
|
|
67
78
|
# The realm used in Http Basic Authentication. 'Application' by default.
|
|
@@ -85,19 +96,31 @@ Devise.setup do |config|
|
|
|
85
96
|
# from the server. You can disable this option at your own risk.
|
|
86
97
|
# config.clean_up_csrf_token_on_authentication = true
|
|
87
98
|
|
|
99
|
+
# When false, Devise will not attempt to reload routes on eager load.
|
|
100
|
+
# This can reduce the time taken to boot the app but if your application
|
|
101
|
+
# requires the Devise mappings to be loaded during boot time the application
|
|
102
|
+
# won't boot properly.
|
|
103
|
+
# config.reload_routes = true
|
|
104
|
+
|
|
88
105
|
# ==> Configuration for :database_authenticatable
|
|
89
|
-
# For bcrypt, this is the cost for hashing the password and defaults to
|
|
90
|
-
# using other
|
|
106
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
|
|
107
|
+
# using other algorithms, it sets how many times you want the password to be hashed.
|
|
91
108
|
#
|
|
92
109
|
# Limiting the stretches to just one in testing will increase the performance of
|
|
93
110
|
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
|
94
111
|
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
|
95
|
-
#
|
|
112
|
+
# algorithm), the cost increases exponentially with the number of stretches (e.g.
|
|
96
113
|
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
|
97
|
-
config.stretches = Rails.env.test? ? 1 :
|
|
114
|
+
config.stretches = Rails.env.test? ? 1 : 11
|
|
98
115
|
|
|
99
|
-
#
|
|
100
|
-
# config.pepper = '
|
|
116
|
+
# Set up a pepper to generate the hashed password.
|
|
117
|
+
# config.pepper = 'ced2d580bc6502ee4c7c70eb54499e72c04430932a791b1ec4694f7ebecafec05f487517c2f7337a4757e67bcc74fa957d23d89b1ea61cfb48a8ebe31c8dade1'
|
|
118
|
+
|
|
119
|
+
# Send a notification to the original email when the user's email is changed.
|
|
120
|
+
# config.send_email_changed_notification = false
|
|
121
|
+
|
|
122
|
+
# Send a notification email when the user's password is changed.
|
|
123
|
+
# config.send_password_change_notification = false
|
|
101
124
|
|
|
102
125
|
# ==> Configuration for :confirmable
|
|
103
126
|
# A period that the user is allowed to access the website even without
|
|
@@ -122,12 +145,15 @@ Devise.setup do |config|
|
|
|
122
145
|
config.reconfirmable = true
|
|
123
146
|
|
|
124
147
|
# Defines which key will be used when confirming an account
|
|
125
|
-
# config.confirmation_keys = [
|
|
148
|
+
# config.confirmation_keys = [:email]
|
|
126
149
|
|
|
127
150
|
# ==> Configuration for :rememberable
|
|
128
151
|
# The time the user will be remembered without asking for credentials again.
|
|
129
152
|
# config.remember_for = 2.weeks
|
|
130
153
|
|
|
154
|
+
# Invalidates all the remember me tokens when the user signs out.
|
|
155
|
+
config.expire_all_remember_me_on_sign_out = true
|
|
156
|
+
|
|
131
157
|
# If true, extends the user's remember period when remembered via cookie.
|
|
132
158
|
# config.extend_remember_period = false
|
|
133
159
|
|
|
@@ -137,21 +163,18 @@ Devise.setup do |config|
|
|
|
137
163
|
|
|
138
164
|
# ==> Configuration for :validatable
|
|
139
165
|
# Range for password length.
|
|
140
|
-
config.password_length =
|
|
166
|
+
config.password_length = 6..128
|
|
141
167
|
|
|
142
168
|
# Email regex used to validate email formats. It simply asserts that
|
|
143
169
|
# one (and only one) @ exists in the given string. This is mainly
|
|
144
170
|
# to give user feedback and not to assert the e-mail validity.
|
|
145
|
-
|
|
171
|
+
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
|
|
146
172
|
|
|
147
173
|
# ==> Configuration for :timeoutable
|
|
148
174
|
# The time you want to timeout the user session without activity. After this
|
|
149
175
|
# time the user will be asked for credentials again. Default is 30 minutes.
|
|
150
176
|
# config.timeout_in = 30.minutes
|
|
151
177
|
|
|
152
|
-
# If true, expires auth token on session timeout.
|
|
153
|
-
# config.expire_auth_token_on_timeout = false
|
|
154
|
-
|
|
155
178
|
# ==> Configuration for :lockable
|
|
156
179
|
# Defines which strategy will be used to lock an account.
|
|
157
180
|
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
|
@@ -159,7 +182,7 @@ Devise.setup do |config|
|
|
|
159
182
|
# config.lock_strategy = :failed_attempts
|
|
160
183
|
|
|
161
184
|
# Defines which key will be used when locking and unlocking an account
|
|
162
|
-
# config.unlock_keys = [
|
|
185
|
+
# config.unlock_keys = [:email]
|
|
163
186
|
|
|
164
187
|
# Defines which strategy will be used to unlock an account.
|
|
165
188
|
# :email = Sends an unlock link to the user email
|
|
@@ -176,24 +199,28 @@ Devise.setup do |config|
|
|
|
176
199
|
# config.unlock_in = 1.hour
|
|
177
200
|
|
|
178
201
|
# Warn on the last attempt before the account is locked.
|
|
179
|
-
# config.last_attempt_warning =
|
|
202
|
+
# config.last_attempt_warning = true
|
|
180
203
|
|
|
181
204
|
# ==> Configuration for :recoverable
|
|
182
205
|
#
|
|
183
206
|
# Defines which key will be used when recovering the password for an account
|
|
184
|
-
# config.reset_password_keys = [
|
|
207
|
+
# config.reset_password_keys = [:email]
|
|
185
208
|
|
|
186
209
|
# Time interval you can reset your password with a reset password key.
|
|
187
210
|
# Don't put a too small interval or your users won't have the time to
|
|
188
211
|
# change their passwords.
|
|
189
212
|
config.reset_password_within = 6.hours
|
|
190
213
|
|
|
214
|
+
# When set to false, does not sign a user in automatically after their password is
|
|
215
|
+
# reset. Defaults to true, so a user is signed in automatically after a reset.
|
|
216
|
+
# config.sign_in_after_reset_password = true
|
|
217
|
+
|
|
191
218
|
# ==> Configuration for :encryptable
|
|
192
|
-
# Allow you to use another encryption algorithm besides bcrypt (default).
|
|
193
|
-
# :sha1, :sha512 or
|
|
194
|
-
# :authlogic_sha512 (then you should set stretches above to 20
|
|
195
|
-
# and :restful_authentication_sha1 (then you should set
|
|
196
|
-
# REST_AUTH_SITE_KEY to pepper).
|
|
219
|
+
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
|
|
220
|
+
# You can use :sha1, :sha512 or algorithms from others authentication tools as
|
|
221
|
+
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
|
|
222
|
+
# for default behavior) and :restful_authentication_sha1 (then you should set
|
|
223
|
+
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
|
|
197
224
|
#
|
|
198
225
|
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
|
199
226
|
# config.encryptor = :sha512
|
|
@@ -248,11 +275,16 @@ Devise.setup do |config|
|
|
|
248
275
|
# mount MyEngine, at: '/my_engine'
|
|
249
276
|
#
|
|
250
277
|
# The router that invoked `devise_for`, in the example above, would be:
|
|
251
|
-
config.router_name = :
|
|
252
|
-
config.parent_controller = "DeviseTokenAuth::ApplicationController"
|
|
253
|
-
|
|
278
|
+
# config.router_name = :my_engine
|
|
254
279
|
#
|
|
255
|
-
# When using
|
|
280
|
+
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
|
256
281
|
# so you need to do it manually. For the users scope, it would be:
|
|
257
|
-
#config.omniauth_path_prefix = ''
|
|
282
|
+
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
|
283
|
+
|
|
284
|
+
# ==> Turbolinks configuration
|
|
285
|
+
# If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
|
|
286
|
+
#
|
|
287
|
+
# ActiveSupport.on_load(:devise_failure_app) do
|
|
288
|
+
# include Turbolinks::Controller
|
|
289
|
+
# end
|
|
258
290
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
DeviseTokenAuth.setup do |config|
|
|
4
|
+
# By default the authorization headers will change after each request. The
|
|
5
|
+
# client is responsible for keeping track of the changing tokens. Change
|
|
6
|
+
# this to false to prevent the Authorization header from changing after
|
|
7
|
+
# each request.
|
|
8
|
+
# config.change_headers_on_each_request = true
|
|
9
|
+
|
|
10
|
+
# By default, users will need to re-authenticate after 2 weeks. This setting
|
|
11
|
+
# determines how long tokens will remain valid after they are issued.
|
|
12
|
+
# config.token_lifespan = 2.weeks
|
|
13
|
+
|
|
14
|
+
# Limiting the token_cost to just 4 in testing will increase the performance of
|
|
15
|
+
# your test suite dramatically. The possible cost value is within range from 4
|
|
16
|
+
# to 31. It is recommended to not use a value more than 10 in other environments.
|
|
17
|
+
config.token_cost = Rails.env.test? ? 4 : 10
|
|
18
|
+
|
|
19
|
+
# Sets the max number of concurrent devices per user, which is 10 by default.
|
|
20
|
+
# After this limit is reached, the oldest tokens will be removed.
|
|
21
|
+
# config.max_number_of_devices = 10
|
|
22
|
+
|
|
23
|
+
# Sometimes it's necessary to make several requests to the API at the same
|
|
24
|
+
# time. In this case, each request in the batch will need to share the same
|
|
25
|
+
# auth token. This setting determines how far apart the requests can be while
|
|
26
|
+
# still using the same auth token.
|
|
27
|
+
# config.batch_request_buffer_throttle = 5.seconds
|
|
28
|
+
|
|
29
|
+
# This route will be the prefix for all oauth2 redirect callbacks. For
|
|
30
|
+
# example, using the default '/omniauth', the github oauth2 provider will
|
|
31
|
+
# redirect successful authentications to '/omniauth/github/callback'
|
|
32
|
+
# config.omniauth_prefix = "/omniauth"
|
|
33
|
+
|
|
34
|
+
# By default sending current password is not needed for the password update.
|
|
35
|
+
# Uncomment to enforce current_password param to be checked before all
|
|
36
|
+
# attribute updates. Set it to :password if you want it to be checked only if
|
|
37
|
+
# password is updated.
|
|
38
|
+
# config.check_current_password_before_update = :attributes
|
|
39
|
+
|
|
40
|
+
# By default we will use callbacks for single omniauth.
|
|
41
|
+
# It depends on fields like email, provider and uid.
|
|
42
|
+
# config.default_callbacks = true
|
|
43
|
+
|
|
44
|
+
# Makes it possible to change the headers names
|
|
45
|
+
# config.headers_names = {:'access-token' => 'access-token',
|
|
46
|
+
# :'client' => 'client',
|
|
47
|
+
# :'expiry' => 'expiry',
|
|
48
|
+
# :'uid' => 'uid',
|
|
49
|
+
# :'token-type' => 'token-type' }
|
|
50
|
+
|
|
51
|
+
# By default, only Bearer Token authentication is implemented out of the box.
|
|
52
|
+
# If, however, you wish to integrate with legacy Devise authentication, you can
|
|
53
|
+
# do so by enabling this flag. NOTE: This feature is highly experimental!
|
|
54
|
+
# config.enable_standard_devise_support = false
|
|
55
|
+
end
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Rails.application.config.middleware.use OmniAuth::Builder do |b|
|
|
2
4
|
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: 'email,profile'
|
|
3
5
|
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
|
|
4
6
|
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
|
|
7
|
+
provider :apple, ENV['APPLE_CLIENT_ID'], '', { scope: 'email name', team_id: ENV['APPLE_TEAM_ID'], key_id: ENV['APPLE_KEY'], pem: ENV['APPLE_PEM'] }
|
|
8
|
+
provider :developer,
|
|
9
|
+
fields: [:first_name, :last_name],
|
|
10
|
+
uid_field: :last_name
|
|
5
11
|
end
|
data/test/dummy/config/routes.rb
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
Rails.application.routes.draw do
|
|
2
|
-
|
|
4
|
+
# when using multiple models, controllers will default to the first available
|
|
5
|
+
# devise mapping. routes for subsequent devise mappings will need to defined
|
|
6
|
+
# within a `devise_scope` block
|
|
7
|
+
|
|
8
|
+
# define :users as the first devise mapping:
|
|
9
|
+
mount_devise_token_auth_for 'User', at: 'auth'
|
|
10
|
+
|
|
11
|
+
# define :mangs as the second devise mapping. routes using this class will
|
|
12
|
+
# need to be defined within a devise_scope as shown below
|
|
13
|
+
mount_devise_token_auth_for 'Mang', at: 'mangs'
|
|
14
|
+
|
|
15
|
+
mount_devise_token_auth_for 'OnlyEmailUser', at: 'only_email_auth', skip: [:omniauth_callbacks]
|
|
16
|
+
|
|
17
|
+
mount_devise_token_auth_for 'UnregisterableUser', at: 'unregisterable_user_auth', skip: [:registrations]
|
|
18
|
+
|
|
19
|
+
mount_devise_token_auth_for 'UnconfirmableUser', at: 'unconfirmable_user_auth'
|
|
20
|
+
|
|
21
|
+
mount_devise_token_auth_for 'LockableUser', at: 'lockable_user_auth'
|
|
22
|
+
|
|
23
|
+
mount_devise_token_auth_for 'ConfirmableUser', at: 'confirmable_user_auth'
|
|
24
|
+
|
|
25
|
+
# test namespacing
|
|
26
|
+
namespace :api do
|
|
27
|
+
scope :v1 do
|
|
28
|
+
mount_devise_token_auth_for 'User', at: 'auth'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# test namespacing with not created devise mapping
|
|
33
|
+
namespace :api_v2, defaults: { format: :json } do
|
|
34
|
+
mount_devise_token_auth_for 'ScopedUser',
|
|
35
|
+
at: 'auth',
|
|
36
|
+
controllers: {
|
|
37
|
+
omniauth_callbacks: 'api_v2/omniauth_callbacks',
|
|
38
|
+
sessions: 'api_v2/sessions',
|
|
39
|
+
registrations: 'api_v2/registrations',
|
|
40
|
+
confirmations: 'api_v2/confirmations',
|
|
41
|
+
passwords: 'api_v2/passwords'
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# this route will authorize visitors using the User class
|
|
46
|
+
get 'demo/members_only', to: 'demo_user#members_only'
|
|
47
|
+
get 'demo/members_only_remove_token', to: 'demo_user#members_only_remove_token'
|
|
48
|
+
|
|
49
|
+
# routes within this block will authorize visitors using the Mang class
|
|
50
|
+
get 'demo/members_only_mang', to: 'demo_mang#members_only'
|
|
51
|
+
|
|
52
|
+
# routes within this block will authorize visitors using the Mang or User class
|
|
53
|
+
get 'demo/members_only_group', to: 'demo_group#members_only'
|
|
54
|
+
|
|
55
|
+
# we need a route for omniauth_callback_controller to redirect to in sameWindow case
|
|
56
|
+
get 'auth_origin', to: 'auth_origin#redirected'
|
|
3
57
|
end
|
data/test/dummy/config.ru
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# This file is used by Rack-based servers to start the application.
|
|
2
4
|
|
|
3
5
|
require ::File.expand_path('../config/environment', __FILE__)
|
|
4
6
|
run Rails.application
|
|
7
|
+
|
|
8
|
+
# allow cross origin requests
|
|
9
|
+
require 'rack/cors'
|
|
10
|
+
use Rack::Cors do
|
|
11
|
+
allow do
|
|
12
|
+
origins '*'
|
|
13
|
+
resource '*',
|
|
14
|
+
headers: :any,
|
|
15
|
+
expose: ['access-token', 'expiry', 'token-type', 'uid', 'client'],
|
|
16
|
+
methods: %i[get post options delete put]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
include MigrationDatabaseHelper
|
|
4
|
+
|
|
5
|
+
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[4.2]
|
|
6
|
+
def change
|
|
7
|
+
create_table(:users) do |t|
|
|
8
|
+
## Database authenticatable
|
|
9
|
+
t.string :email
|
|
10
|
+
t.string :encrypted_password, null: false, default: ''
|
|
11
|
+
|
|
12
|
+
## Recoverable
|
|
13
|
+
t.string :reset_password_token
|
|
14
|
+
t.datetime :reset_password_sent_at
|
|
15
|
+
t.string :reset_password_redirect_url
|
|
16
|
+
t.boolean :allow_password_change, default: false
|
|
17
|
+
|
|
18
|
+
## Rememberable
|
|
19
|
+
t.datetime :remember_created_at
|
|
20
|
+
|
|
21
|
+
## Confirmable
|
|
22
|
+
t.string :confirmation_token
|
|
23
|
+
t.datetime :confirmed_at
|
|
24
|
+
t.datetime :confirmation_sent_at
|
|
25
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
|
26
|
+
|
|
27
|
+
## Lockable
|
|
28
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
|
29
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
30
|
+
# t.datetime :locked_at
|
|
31
|
+
|
|
32
|
+
## User Info
|
|
33
|
+
t.string :name
|
|
34
|
+
t.string :nickname
|
|
35
|
+
t.string :image
|
|
36
|
+
|
|
37
|
+
## unique oauth id
|
|
38
|
+
t.string :provider
|
|
39
|
+
t.string :uid, null: false, default: ''
|
|
40
|
+
|
|
41
|
+
## Tokens
|
|
42
|
+
if json_supported_database?
|
|
43
|
+
t.json :tokens
|
|
44
|
+
else
|
|
45
|
+
t.text :tokens
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
t.timestamps
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
add_index :users, :email
|
|
52
|
+
add_index :users, [:uid, :provider], unique: true
|
|
53
|
+
add_index :users, :reset_password_token, unique: true
|
|
54
|
+
add_index :users, :confirmation_token, unique: true
|
|
55
|
+
add_index :users, :nickname, unique: true
|
|
56
|
+
# add_index :users, :unlock_token, :unique => true
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
include MigrationDatabaseHelper
|
|
4
|
+
|
|
5
|
+
class DeviseTokenAuthCreateMangs < ActiveRecord::Migration[4.2]
|
|
6
|
+
def change
|
|
7
|
+
create_table(:mangs) do |t|
|
|
8
|
+
## Database authenticatable
|
|
9
|
+
t.string :email
|
|
10
|
+
t.string :encrypted_password, null: false, default: ''
|
|
11
|
+
|
|
12
|
+
## Recoverable
|
|
13
|
+
t.string :reset_password_token
|
|
14
|
+
t.datetime :reset_password_sent_at
|
|
15
|
+
t.string :reset_password_redirect_url
|
|
16
|
+
t.boolean :allow_password_change, default: false
|
|
17
|
+
|
|
18
|
+
## Rememberable
|
|
19
|
+
t.datetime :remember_created_at
|
|
20
|
+
|
|
21
|
+
## Confirmable
|
|
22
|
+
t.string :confirmation_token
|
|
23
|
+
t.datetime :confirmed_at
|
|
24
|
+
t.datetime :confirmation_sent_at
|
|
25
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
|
26
|
+
|
|
27
|
+
## Lockable
|
|
28
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
|
29
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
30
|
+
# t.datetime :locked_at
|
|
31
|
+
|
|
32
|
+
## User Info
|
|
33
|
+
t.string :name
|
|
34
|
+
t.string :nickname
|
|
35
|
+
t.string :image
|
|
36
|
+
|
|
37
|
+
## unique oauth id
|
|
38
|
+
t.string :provider
|
|
39
|
+
t.string :uid, null: false, default: ''
|
|
40
|
+
|
|
41
|
+
## Tokens
|
|
42
|
+
if json_supported_database?
|
|
43
|
+
t.json :tokens
|
|
44
|
+
else
|
|
45
|
+
t.text :tokens
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
t.timestamps
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
add_index :mangs, :email
|
|
52
|
+
add_index :mangs, [:uid, :provider], unique: true
|
|
53
|
+
add_index :mangs, :reset_password_token, unique: true
|
|
54
|
+
add_index :mangs, :confirmation_token, unique: true
|
|
55
|
+
# add_index :mangs, :unlock_token, :unique => true
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
include MigrationDatabaseHelper
|
|
4
|
+
|
|
5
|
+
class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration[4.2]
|
|
6
|
+
def change
|
|
7
|
+
create_table(:only_email_users) do |t|
|
|
8
|
+
## Required
|
|
9
|
+
t.string :provider, null: false
|
|
10
|
+
t.string :uid, null: false, default: ''
|
|
11
|
+
|
|
12
|
+
## Database authenticatable
|
|
13
|
+
t.string :encrypted_password, null: false, default: ''
|
|
14
|
+
|
|
15
|
+
## Recoverable
|
|
16
|
+
#t.string :reset_password_token
|
|
17
|
+
#t.datetime :reset_password_sent_at
|
|
18
|
+
|
|
19
|
+
## Rememberable
|
|
20
|
+
#t.datetime :remember_created_at
|
|
21
|
+
|
|
22
|
+
## Confirmable
|
|
23
|
+
#t.string :confirmation_token
|
|
24
|
+
#t.datetime :confirmed_at
|
|
25
|
+
#t.datetime :confirmation_sent_at
|
|
26
|
+
#t.string :unconfirmed_email # Only if using reconfirmable
|
|
27
|
+
|
|
28
|
+
## Lockable
|
|
29
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
|
30
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
31
|
+
# t.datetime :locked_at
|
|
32
|
+
|
|
33
|
+
## User Info
|
|
34
|
+
t.string :name
|
|
35
|
+
t.string :nickname
|
|
36
|
+
t.string :image
|
|
37
|
+
t.string :email
|
|
38
|
+
|
|
39
|
+
## Tokens
|
|
40
|
+
if json_supported_database?
|
|
41
|
+
t.json :tokens
|
|
42
|
+
else
|
|
43
|
+
t.text :tokens
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
t.timestamps
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
add_index :only_email_users, :email
|
|
50
|
+
add_index :only_email_users, [:uid, :provider], unique: true
|
|
51
|
+
#add_index :only_email_users, :reset_password_token, :unique => true
|
|
52
|
+
# add_index :only_email_users, :confirmation_token, :unique => true
|
|
53
|
+
# add_index :only_email_users, :unlock_token, :unique => true
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
include MigrationDatabaseHelper
|
|
4
|
+
|
|
5
|
+
class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration[4.2]
|
|
6
|
+
def change
|
|
7
|
+
create_table(:unregisterable_users) do |t|
|
|
8
|
+
## Required
|
|
9
|
+
t.string :provider, null: false
|
|
10
|
+
t.string :uid, null: false, default: ''
|
|
11
|
+
|
|
12
|
+
## Database authenticatable
|
|
13
|
+
t.string :encrypted_password, null: false, default: ''
|
|
14
|
+
|
|
15
|
+
## Recoverable
|
|
16
|
+
t.string :reset_password_token
|
|
17
|
+
t.datetime :reset_password_sent_at
|
|
18
|
+
t.boolean :allow_password_change, default: false
|
|
19
|
+
|
|
20
|
+
## Rememberable
|
|
21
|
+
t.datetime :remember_created_at
|
|
22
|
+
|
|
23
|
+
## Confirmable
|
|
24
|
+
t.string :confirmation_token
|
|
25
|
+
t.datetime :confirmed_at
|
|
26
|
+
t.datetime :confirmation_sent_at
|
|
27
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
|
28
|
+
|
|
29
|
+
## Lockable
|
|
30
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
|
31
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
32
|
+
# t.datetime :locked_at
|
|
33
|
+
|
|
34
|
+
## User Info
|
|
35
|
+
t.string :name
|
|
36
|
+
t.string :nickname
|
|
37
|
+
t.string :image
|
|
38
|
+
t.string :email
|
|
39
|
+
|
|
40
|
+
## Tokens
|
|
41
|
+
if json_supported_database?
|
|
42
|
+
t.json :tokens
|
|
43
|
+
else
|
|
44
|
+
t.text :tokens
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
t.timestamps
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
add_index :unregisterable_users, :email
|
|
51
|
+
add_index :unregisterable_users, [:uid, :provider], unique: true
|
|
52
|
+
add_index :unregisterable_users, :reset_password_token, unique: true
|
|
53
|
+
# add_index :unregisterable_users, :confirmation_token, :unique => true
|
|
54
|
+
# add_index :unregisterable_users, :unlock_token, :unique => true
|
|
55
|
+
end
|
|
56
|
+
end
|