groovestack-auth 0.1.5 → 0.1.6

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -1
  3. data/Gemfile.lock +120 -20
  4. data/{lib/groovestack/auth/action_cable.rb → app/channels/groovestack/auth/action_cable/connection.rb} +2 -2
  5. data/app/controllers/concerns/groovestack/auth/graphql/controllers/auth_helpers.rb +69 -0
  6. data/app/controllers/concerns/groovestack/auth/graphql/controllers/authed_execute.rb +16 -0
  7. data/app/controllers/groovestack/auth/authenticated_api_controller.rb +10 -0
  8. data/app/controllers/groovestack/auth/omniauth_callbacks_controller.rb +138 -0
  9. data/app/controllers/groovestack/auth/passwordless/magic_links_controller.rb +58 -0
  10. data/app/controllers/groovestack/auth/passwordless/sessions_controller.rb +75 -0
  11. data/app/graphql/graphql/identity_extensions.rb +11 -0
  12. data/app/graphql/graphql/user_extensions.rb +14 -0
  13. data/app/models/concerns/groovestack/auth/authorized_fields_for_serialization.rb +21 -0
  14. data/app/models/concerns/groovestack/auth/identity.rb +39 -0
  15. data/app/models/concerns/groovestack/auth/user.rb +14 -0
  16. data/app/views/devise/mailer/magic_link.html.erb +9 -0
  17. data/config/initializers/core_config.rb +0 -6
  18. data/config/initializers/devise.rb +387 -302
  19. data/config/initializers/omniauth.rb +0 -19
  20. data/config/locales/devise.en.yml +71 -0
  21. data/db/migrate/20231103174050_add_devise_to_users_and_identities.rb +59 -0
  22. data/groovestack-auth.gemspec +7 -7
  23. data/lib/groovestack/auth/{railtie.rb → engine.rb} +13 -2
  24. data/lib/groovestack/auth/graphql/authorized_field.rb +19 -0
  25. data/lib/groovestack/auth/graphql/authorized_object.rb +11 -0
  26. data/lib/groovestack/auth/graphql/schema_visibility.rb +40 -0
  27. data/lib/groovestack/auth/graphql/visible_field.rb +21 -0
  28. data/lib/groovestack/auth/graphql/visible_object.rb +17 -0
  29. data/lib/groovestack/auth/passwordless/t_otp_tokenizer.rb +89 -0
  30. data/lib/groovestack/auth/provider.rb +7 -0
  31. data/lib/groovestack/auth/providers/apple.rb +5 -5
  32. data/lib/groovestack/auth/providers/facebook.rb +17 -0
  33. data/lib/groovestack/auth/providers/google.rb +1 -1
  34. data/lib/groovestack/auth/providers/omni_auth.rb +2 -2
  35. data/lib/groovestack/auth/routes.rb +26 -0
  36. data/lib/groovestack/auth/settings.rb +43 -0
  37. data/lib/groovestack/auth/version.rb +1 -1
  38. data/lib/groovestack/auth.rb +33 -83
  39. metadata +55 -50
  40. data/config/initializers/devise_token_auth.rb +0 -72
  41. data/config/initializers/graphql_devise.rb +0 -58
  42. data/config/routes.rb +0 -11
  43. data/db/migrate/20231103172517_create_users.rb +0 -54
  44. data/db/migrate/20231103174037_create_identities.rb +0 -19
  45. data/lib/fabricators/user_fabricator.rb +0 -17
  46. data/lib/graphql/identity/filter.rb +0 -13
  47. data/lib/graphql/identity/mutations.rb +0 -27
  48. data/lib/graphql/identity/queries.rb +0 -25
  49. data/lib/graphql/identity/type.rb +0 -22
  50. data/lib/graphql/user/filter.rb +0 -15
  51. data/lib/graphql/user/mutations.rb +0 -63
  52. data/lib/graphql/user/queries.rb +0 -40
  53. data/lib/graphql/user/type.rb +0 -30
  54. data/lib/groovestack/auth/authenticated_api_controller.rb +0 -13
  55. data/lib/groovestack/auth/omniauth_callbacks_controller.rb +0 -111
  56. data/lib/groovestack/auth/schema_plugin.rb +0 -19
  57. data/lib/identity.rb +0 -31
  58. data/lib/user.rb +0 -53
  59. data/lib/users/roles.rb +0 -42
@@ -8,307 +8,392 @@
8
8
  #
9
9
  # Use this hook to configure devise mailer, warden hooks and so forth.
10
10
  # Many of these configuration options can be set straight in your model.
11
- if defined?(Devise)
12
- Devise.setup do |config|
13
- # The secret key used by Devise. Devise uses this key to generate
14
- # random tokens. Changing this key will render invalid all existing
15
- # confirmation, reset password and unlock tokens in the database.
16
- # Devise will use the `secret_key_base` as its `secret_key`
17
- # by default. You can change it below and use your own secret key.
18
- # config.secret_key = 'KEY_HERE'
19
-
20
- # ==> Controller configuration
21
- # Configure the parent class to the devise controllers.
22
- # config.parent_controller = 'DeviseController'
23
-
24
- # ==> Mailer Configuration
25
- # Configure the e-mail address which will be shown in Devise::Mailer,
26
- # note that it will be overwritten if you use your own mailer class
27
- # with default "from" parameter.
28
- config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
29
-
30
- # Configure the class responsible to send e-mails.
31
- # config.mailer = 'Devise::Mailer'
32
-
33
- # Configure the parent class responsible to send e-mails.
34
- # config.parent_mailer = 'ActionMailer::Base'
35
-
36
- # ==> ORM configuration
37
- # Load and configure the ORM. Supports :active_record (default) and
38
- # :mongoid (bson_ext recommended) by default. Other ORMs may be
39
- # available as additional gems.
40
- require 'devise/orm/active_record'
41
-
42
- # ==> Configuration for any authentication mechanism
43
- # Configure which keys are used when authenticating a user. The default is
44
- # just :email. You can configure it to use [:username, :subdomain], so for
45
- # authenticating a user, both parameters are required. Remember that those
46
- # parameters are used only when authenticating and not when retrieving from
47
- # session. If you need permissions, you should implement that in a before filter.
48
- # You can also supply a hash where the value is a boolean determining whether
49
- # or not authentication should be aborted when the value is not present.
50
- # config.authentication_keys = [:email]
51
-
52
- # Configure parameters from the request object used for authentication. Each entry
53
- # given should be a request method and it will automatically be passed to the
54
- # find_for_authentication method and considered in your model lookup. For instance,
55
- # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
56
- # The same considerations mentioned for authentication_keys also apply to request_keys.
57
- # config.request_keys = []
58
-
59
- # Configure which authentication keys should be case-insensitive.
60
- # These keys will be downcased upon creating or modifying a user and when used
61
- # to authenticate or find a user. Default is :email.
62
- config.case_insensitive_keys = [:email]
63
-
64
- # Configure which authentication keys should have whitespace stripped.
65
- # These keys will have whitespace before and after removed upon creating or
66
- # modifying a user and when used to authenticate or find a user. Default is :email.
67
- config.strip_whitespace_keys = [:email]
68
-
69
- # Tell if authentication through request.params is enabled. True by default.
70
- # It can be set to an array that will enable params authentication only for the
71
- # given strategies, for example, `config.params_authenticatable = [:database]` will
72
- # enable it only for database (email + password) authentication.
73
- # config.params_authenticatable = true
74
-
75
- # Tell if authentication through HTTP Auth is enabled. False by default.
76
- # It can be set to an array that will enable http authentication only for the
77
- # given strategies, for example, `config.http_authenticatable = [:database]` will
78
- # enable it only for database authentication.
79
- # For API-only applications to support authentication "out-of-the-box", you will likely want to
80
- # enable this with :database unless you are using a custom strategy.
81
- # The supported strategies are:
82
- # :database = Support basic authentication with authentication key + password
83
- # config.http_authenticatable = false
84
-
85
- # If 401 status code should be returned for AJAX requests. True by default.
86
- # config.http_authenticatable_on_xhr = true
87
-
88
- # The realm used in Http Basic Authentication. 'Application' by default.
89
- # config.http_authentication_realm = 'Application'
90
-
91
- # It will change confirmation, password recovery and other workflows
92
- # to behave the same regardless if the e-mail provided was right or wrong.
93
- # Does not affect registerable.
94
- # config.paranoid = true
95
-
96
- # By default Devise will store the user in session. You can skip storage for
97
- # particular strategies by setting this option.
98
- # Notice that if you are skipping storage for all authentication paths, you
99
- # may want to disable generating routes to Devise's sessions controller by
100
- # passing skip: :sessions to `devise_for` in your config/routes.rb
101
- config.skip_session_storage = [:http_auth]
102
-
103
- # By default, Devise cleans up the CSRF token on authentication to
104
- # avoid CSRF token fixation attacks. This means that, when using AJAX
105
- # requests for sign in and sign up, you need to get a new CSRF token
106
- # from the server. You can disable this option at your own risk.
107
- # config.clean_up_csrf_token_on_authentication = true
108
-
109
- # When false, Devise will not attempt to reload routes on eager load.
110
- # This can reduce the time taken to boot the app but if your application
111
- # requires the Devise mappings to be loaded during boot time the application
112
- # won't boot properly.
113
- # config.reload_routes = true
114
-
115
- # ==> Configuration for :database_authenticatable
116
- # For bcrypt, this is the cost for hashing the password and defaults to 12. If
117
- # using other algorithms, it sets how many times you want the password to be hashed.
118
- # The number of stretches used for generating the hashed password are stored
119
- # with the hashed password. This allows you to change the stretches without
120
- # invalidating existing passwords.
121
- #
122
- # Limiting the stretches to just one in testing will increase the performance of
123
- # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
124
- # a value less than 10 in other environments. Note that, for bcrypt (the default
125
- # algorithm), the cost increases exponentially with the number of stretches (e.g.
126
- # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
127
- config.stretches = Rails.env.test? ? 1 : 12
128
-
129
- # Set up a pepper to generate the hashed password.
130
- # config.pepper = 'TODO'
131
-
132
- # Send a notification to the original email when the user's email is changed.
133
- # config.send_email_changed_notification = false
134
-
135
- # Send a notification email when the user's password is changed.
136
- # config.send_password_change_notification = false
137
-
138
- # ==> Configuration for :confirmable
139
- # A period that the user is allowed to access the website even without
140
- # confirming their account. For instance, if set to 2.days, the user will be
141
- # able to access the website for two days without confirming their account,
142
- # access will be blocked just in the third day.
143
- # You can also set it to nil, which will allow the user to access the website
144
- # without confirming their account.
145
- # Default is 0.days, meaning the user cannot access the website without
146
- # confirming their account.
147
- # config.allow_unconfirmed_access_for = 2.days
148
-
149
- # A period that the user is allowed to confirm their account before their
150
- # token becomes invalid. For example, if set to 3.days, the user can confirm
151
- # their account within 3 days after the mail was sent, but on the fourth day
152
- # their account can't be confirmed with the token any more.
153
- # Default is nil, meaning there is no restriction on how long a user can take
154
- # before confirming their account.
155
- # config.confirm_within = 3.days
156
-
157
- # If true, requires any email changes to be confirmed (exactly the same way as
158
- # initial account confirmation) to be applied. Requires additional unconfirmed_email
159
- # db field (see migrations). Until confirmed, new email is stored in
160
- # unconfirmed_email column, and copied to email column on successful confirmation.
161
- config.reconfirmable = true
162
-
163
- # Defines which key will be used when confirming an account
164
- # config.confirmation_keys = [:email]
165
-
166
- # ==> Configuration for :rememberable
167
- # The time the user will be remembered without asking for credentials again.
168
- # config.remember_for = 2.weeks
169
-
170
- # Invalidates all the remember me tokens when the user signs out.
171
- config.expire_all_remember_me_on_sign_out = true
172
-
173
- # If true, extends the user's remember period when remembered via cookie.
174
- # config.extend_remember_period = false
175
-
176
- # Options to be passed to the created cookie. For instance, you can set
177
- # secure: true in order to force SSL only cookies.
178
- # config.rememberable_options = {}
179
-
180
- # ==> Configuration for :validatable
181
- # Range for password length.
182
- config.password_length = 6..128
183
-
184
- # Email regex used to validate email formats. It simply asserts that
185
- # one (and only one) @ exists in the given string. This is mainly
186
- # to give user feedback and not to assert the e-mail validity.
187
- config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
188
-
189
- # ==> Configuration for :timeoutable
190
- # The time you want to timeout the user session without activity. After this
191
- # time the user will be asked for credentials again. Default is 30 minutes.
192
- # config.timeout_in = 30.minutes
193
-
194
- # ==> Configuration for :lockable
195
- # Defines which strategy will be used to lock an account.
196
- # :failed_attempts = Locks an account after a number of failed attempts to sign in.
197
- # :none = No lock strategy. You should handle locking by yourself.
198
- # config.lock_strategy = :failed_attempts
199
-
200
- # Defines which key will be used when locking and unlocking an account
201
- # config.unlock_keys = [:email]
202
-
203
- # Defines which strategy will be used to unlock an account.
204
- # :email = Sends an unlock link to the user email
205
- # :time = Re-enables login after a certain amount of time (see :unlock_in below)
206
- # :both = Enables both strategies
207
- # :none = No unlock strategy. You should handle unlocking by yourself.
208
- # config.unlock_strategy = :both
209
-
210
- # Number of authentication tries before locking an account if lock_strategy
211
- # is failed attempts.
212
- # config.maximum_attempts = 20
213
-
214
- # Time interval to unlock the account if :time is enabled as unlock_strategy.
215
- # config.unlock_in = 1.hour
216
-
217
- # Warn on the last attempt before the account is locked.
218
- # config.last_attempt_warning = true
219
-
220
- # ==> Configuration for :recoverable
221
- #
222
- # Defines which key will be used when recovering the password for an account
223
- # config.reset_password_keys = [:email]
224
-
225
- # Time interval you can reset your password with a reset password key.
226
- # Don't put a too small interval or your users won't have the time to
227
- # change their passwords.
228
- config.reset_password_within = 6.hours
229
-
230
- # When set to false, does not sign a user in automatically after their password is
231
- # reset. Defaults to true, so a user is signed in automatically after a reset.
232
- # config.sign_in_after_reset_password = true
233
-
234
- # ==> Configuration for :encryptable
235
- # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
236
- # You can use :sha1, :sha512 or algorithms from others authentication tools as
237
- # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
238
- # for default behavior) and :restful_authentication_sha1 (then you should set
239
- # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
240
- #
241
- # Require the `devise-encryptable` gem when using anything other than bcrypt
242
- # config.encryptor = :sha512
243
-
244
- # ==> Scopes configuration
245
- # Turn scoped views on. Before rendering "sessions/new", it will first check for
246
- # "users/sessions/new". It's turned off by default because it's slower if you
247
- # are using only default views.
248
- # config.scoped_views = false
249
-
250
- # Configure the default scope given to Warden. By default it's the first
251
- # devise role declared in your routes (usually :user).
252
- # config.default_scope = :user
253
-
254
- # Set this configuration to false if you want /users/sign_out to sign out
255
- # only the current scope. By default, Devise signs out all scopes.
256
- # config.sign_out_all_scopes = true
257
-
258
- # ==> Navigation configuration
259
- # Lists the formats that should be treated as navigational. Formats like
260
- # :html should redirect to the sign in page when the user does not have
261
- # access, but formats like :xml or :json, should return 401.
262
- #
263
- # If you have any extra navigational formats, like :iphone or :mobile, you
264
- # should add them to the navigational formats lists.
265
- #
266
- # The "*/*" below is required to match Internet Explorer requests.
267
- # config.navigational_formats = ['*/*', :html, :turbo_stream]
268
-
269
- # The default HTTP method used to sign out a resource. Default is :delete.
270
- config.sign_out_via = :delete
271
-
272
- # ==> OmniAuth
273
- # Add a new OmniAuth provider. Check the wiki for more information on setting
274
- # up on your models and hooks.
275
-
276
- # ==> Warden configuration
277
- # If you want to use other strategies, that are not supported by Devise, or
278
- # change the failure app, you can configure them inside the config.warden block.
279
- #
280
- # config.warden do |manager|
281
- # manager.intercept_401 = false
282
- # manager.default_strategies(scope: :user).unshift :some_external_strategy
283
- # end
284
-
285
- # ==> Mountable engine configurations
286
- # When using Devise inside an engine, let's call it `MyEngine`, and this engine
287
- # is mountable, there are some extra configurations to be taken into account.
288
- # The following options are available, assuming the engine is mounted as:
289
- #
290
- # mount MyEngine, at: '/my_engine'
291
- #
292
- # The router that invoked `devise_for`, in the example above, would be:
293
- # config.router_name = :my_engine
294
- #
295
- # When using OmniAuth, Devise cannot automatically set OmniAuth path,
296
- # so you need to do it manually. For the users scope, it would be:
297
- # config.omniauth_path_prefix = '/users/auth'
298
-
299
- # ==> Hotwire/Turbo configuration
300
- # When using Devise with Hotwire/Turbo, the http status for error responses
301
- # and some redirects must match the following. The default in Devise for existing
302
- # apps is `200 OK` and `302 Found` respectively, but new apps are generated with
303
- # these new defaults that match Hotwire/Turbo behavior.
304
- # Note: These might become the new default in future versions of Devise.
305
- config.responder.error_status = :unprocessable_entity
306
- config.responder.redirect_status = :see_other
307
-
308
- # ==> Configuration for :registerable
309
-
310
- # When set to false, does not sign a user in automatically after their password is
311
- # changed. Defaults to true, so a user is signed in automatically after changing a password.
312
- # config.sign_in_after_change_password = true
11
+ Devise.setup do |config|
12
+ # The secret key used by Devise. Devise uses this key to generate
13
+ # random tokens. Changing this key will render invalid all existing
14
+ # confirmation, reset password and unlock tokens in the database.
15
+ # Devise will use the `secret_key_base` as its `secret_key`
16
+ # by default. You can change it below and use your own secret key.
17
+ # config.secret_key = '6d879cdbe0630c1b39310196d5bd8e02e5294765b033b532fe2dedf1cb1e82cb057d536a98916bc7ac2e79b5b73b6c28095734334b183b37deb7c9bafe98720b'
18
+
19
+ # ==> Controller configuration
20
+ # Configure the parent class to the devise controllers.
21
+ # config.parent_controller = 'DeviseController'
22
+
23
+ # ==> Mailer Configuration
24
+ # Configure the e-mail address which will be shown in Devise::Mailer,
25
+ # note that it will be overwritten if you use your own mailer class
26
+ # with default "from" parameter.
27
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
28
+
29
+ # Configure the class responsible to send e-mails.
30
+ # config.mailer = 'Devise::Mailer'
31
+
32
+ # Configure the parent class responsible to send e-mails.
33
+ # config.parent_mailer = 'ActionMailer::Base'
34
+
35
+ # ==> ORM configuration
36
+ # Load and configure the ORM. Supports :active_record (default) and
37
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
38
+ # available as additional gems.
39
+ require 'devise/orm/active_record'
40
+
41
+ # ==> Configuration for any authentication mechanism
42
+ # Configure which keys are used when authenticating a user. The default is
43
+ # just :email. You can configure it to use [:username, :subdomain], so for
44
+ # authenticating a user, both parameters are required. Remember that those
45
+ # parameters are used only when authenticating and not when retrieving from
46
+ # session. If you need permissions, you should implement that in a before filter.
47
+ # You can also supply a hash where the value is a boolean determining whether
48
+ # or not authentication should be aborted when the value is not present.
49
+ # config.authentication_keys = [:email]
50
+
51
+ # Configure parameters from the request object used for authentication. Each entry
52
+ # given should be a request method and it will automatically be passed to the
53
+ # find_for_authentication method and considered in your model lookup. For instance,
54
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
56
+ # config.request_keys = []
57
+
58
+ # Configure which authentication keys should be case-insensitive.
59
+ # These keys will be downcased upon creating or modifying a user and when used
60
+ # to authenticate or find a user. Default is :email.
61
+ config.case_insensitive_keys = [:email]
62
+
63
+ # Configure which authentication keys should have whitespace stripped.
64
+ # These keys will have whitespace before and after removed upon creating or
65
+ # modifying a user and when used to authenticate or find a user. Default is :email.
66
+ config.strip_whitespace_keys = [:email]
67
+
68
+ # Tell if authentication through request.params is enabled. True by default.
69
+ # It can be set to an array that will enable params authentication only for the
70
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
71
+ # enable it only for database (email + password) authentication.
72
+ # config.params_authenticatable = true
73
+
74
+ # Tell if authentication through HTTP Auth is enabled. False by default.
75
+ # It can be set to an array that will enable http authentication only for the
76
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
77
+ # enable it only for database authentication.
78
+ # For API-only applications to support authentication "out-of-the-box", you will likely want to
79
+ # enable this with :database unless you are using a custom strategy.
80
+ # The supported strategies are:
81
+ # :database = Support basic authentication with authentication key + password
82
+ # config.http_authenticatable = false
83
+
84
+ # If 401 status code should be returned for AJAX requests. True by default.
85
+ # config.http_authenticatable_on_xhr = true
86
+
87
+ # The realm used in Http Basic Authentication. 'Application' by default.
88
+ # config.http_authentication_realm = 'Application'
89
+
90
+ # It will change confirmation, password recovery and other workflows
91
+ # to behave the same regardless if the e-mail provided was right or wrong.
92
+ # Does not affect registerable.
93
+ # config.paranoid = true
94
+
95
+ # By default Devise will store the user in session. You can skip storage for
96
+ # particular strategies by setting this option.
97
+ # Notice that if you are skipping storage for all authentication paths, you
98
+ # may want to disable generating routes to Devise's sessions controller by
99
+ # passing skip: :sessions to `devise_for` in your config/routes.rb
100
+ config.skip_session_storage = [:http_auth]
101
+
102
+ # By default, Devise cleans up the CSRF token on authentication to
103
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
104
+ # requests for sign in and sign up, you need to get a new CSRF token
105
+ # from the server. You can disable this option at your own risk.
106
+ # config.clean_up_csrf_token_on_authentication = true
107
+
108
+ # When false, Devise will not attempt to reload routes on eager load.
109
+ # This can reduce the time taken to boot the app but if your application
110
+ # requires the Devise mappings to be loaded during boot time the application
111
+ # won't boot properly.
112
+ # config.reload_routes = true
113
+
114
+ # ==> Configuration for :database_authenticatable
115
+ # For bcrypt, this is the cost for hashing the password and defaults to 12. If
116
+ # using other algorithms, it sets how many times you want the password to be hashed.
117
+ # The number of stretches used for generating the hashed password are stored
118
+ # with the hashed password. This allows you to change the stretches without
119
+ # invalidating existing passwords.
120
+ #
121
+ # Limiting the stretches to just one in testing will increase the performance of
122
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
123
+ # a value less than 10 in other environments. Note that, for bcrypt (the default
124
+ # algorithm), the cost increases exponentially with the number of stretches (e.g.
125
+ # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
126
+ config.stretches = Rails.env.test? ? 1 : 12
127
+
128
+ # Set up a pepper to generate the hashed password.
129
+ # config.pepper = 'cba69c8e3859c3f48f690734984e6e4ee3cb455797c292538654b6a995b8c90ec8df6bf0af35c3490cdaa1fccc68273fb9caf191da14b987c364b3c3235b7359'
130
+
131
+ # Send a notification to the original email when the user's email is changed.
132
+ # config.send_email_changed_notification = false
133
+
134
+ # Send a notification email when the user's password is changed.
135
+ # config.send_password_change_notification = false
136
+
137
+ # ==> Configuration for :confirmable
138
+ # A period that the user is allowed to access the website even without
139
+ # confirming their account. For instance, if set to 2.days, the user will be
140
+ # able to access the website for two days without confirming their account,
141
+ # access will be blocked just in the third day.
142
+ # You can also set it to nil, which will allow the user to access the website
143
+ # without confirming their account.
144
+ # Default is 0.days, meaning the user cannot access the website without
145
+ # confirming their account.
146
+ config.allow_unconfirmed_access_for = 2.days
147
+
148
+ # A period that the user is allowed to confirm their account before their
149
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
150
+ # their account within 3 days after the mail was sent, but on the fourth day
151
+ # their account can't be confirmed with the token any more.
152
+ # Default is nil, meaning there is no restriction on how long a user can take
153
+ # before confirming their account.
154
+ # config.confirm_within = 3.days
155
+
156
+ # If true, requires any email changes to be confirmed (exactly the same way as
157
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
158
+ # db field (see migrations). Until confirmed, new email is stored in
159
+ # unconfirmed_email column, and copied to email column on successful confirmation.
160
+ config.reconfirmable = true
161
+
162
+ # Defines which key will be used when confirming an account
163
+ # config.confirmation_keys = [:email]
164
+
165
+ # ==> Configuration for :rememberable
166
+ # The time the user will be remembered without asking for credentials again.
167
+ # config.remember_for = 2.weeks
168
+
169
+ # Invalidates all the remember me tokens when the user signs out.
170
+ config.expire_all_remember_me_on_sign_out = true
171
+
172
+ # If true, extends the user's remember period when remembered via cookie.
173
+ # config.extend_remember_period = false
174
+
175
+ # Options to be passed to the created cookie. For instance, you can set
176
+ # secure: true in order to force SSL only cookies.
177
+ # config.rememberable_options = {}
178
+
179
+ # ==> Configuration for :validatable
180
+ # Range for password length.
181
+ config.password_length = 6..128
182
+
183
+ # Email regex used to validate email formats. It simply asserts that
184
+ # one (and only one) @ exists in the given string. This is mainly
185
+ # to give user feedback and not to assert the e-mail validity.
186
+ config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
187
+
188
+ # ==> Configuration for :timeoutable
189
+ # The time you want to timeout the user session without activity. After this
190
+ # time the user will be asked for credentials again. Default is 30 minutes.
191
+ # config.timeout_in = 30.minutes
192
+
193
+ # ==> Configuration for :lockable
194
+ # Defines which strategy will be used to lock an account.
195
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
196
+ # :none = No lock strategy. You should handle locking by yourself.
197
+ # config.lock_strategy = :failed_attempts
198
+
199
+ # Defines which key will be used when locking and unlocking an account
200
+ # config.unlock_keys = [:email]
201
+
202
+ # Defines which strategy will be used to unlock an account.
203
+ # :email = Sends an unlock link to the user email
204
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
205
+ # :both = Enables both strategies
206
+ # :none = No unlock strategy. You should handle unlocking by yourself.
207
+ # config.unlock_strategy = :both
208
+
209
+ # Number of authentication tries before locking an account if lock_strategy
210
+ # is failed attempts.
211
+ # config.maximum_attempts = 20
212
+
213
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
214
+ # config.unlock_in = 1.hour
215
+
216
+ # Warn on the last attempt before the account is locked.
217
+ # config.last_attempt_warning = true
218
+
219
+ # ==> Configuration for :recoverable
220
+ #
221
+ # Defines which key will be used when recovering the password for an account
222
+ # config.reset_password_keys = [:email]
223
+
224
+ # Time interval you can reset your password with a reset password key.
225
+ # Don't put a too small interval or your users won't have the time to
226
+ # change their passwords.
227
+ config.reset_password_within = 6.hours
228
+
229
+ # When set to false, does not sign a user in automatically after their password is
230
+ # reset. Defaults to true, so a user is signed in automatically after a reset.
231
+ # config.sign_in_after_reset_password = true
232
+
233
+ # ==> Configuration for :encryptable
234
+ # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
235
+ # You can use :sha1, :sha512 or algorithms from others authentication tools as
236
+ # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
237
+ # for default behavior) and :restful_authentication_sha1 (then you should set
238
+ # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
239
+ #
240
+ # Require the `devise-encryptable` gem when using anything other than bcrypt
241
+ # config.encryptor = :sha512
242
+
243
+ # ==> Scopes configuration
244
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
245
+ # "users/sessions/new". It's turned off by default because it's slower if you
246
+ # are using only default views.
247
+ # config.scoped_views = false
248
+
249
+ # Configure the default scope given to Warden. By default it's the first
250
+ # devise role declared in your routes (usually :user).
251
+ # config.default_scope = :user
252
+
253
+ # Set this configuration to false if you want /users/sign_out to sign out
254
+ # only the current scope. By default, Devise signs out all scopes.
255
+ # config.sign_out_all_scopes = true
256
+
257
+ # ==> Navigation configuration
258
+ # Lists the formats that should be treated as navigational. Formats like
259
+ # :html should redirect to the sign in page when the user does not have
260
+ # access, but formats like :xml or :json, should return 401.
261
+ #
262
+ # If you have any extra navigational formats, like :iphone or :mobile, you
263
+ # should add them to the navigational formats lists.
264
+ #
265
+ # The "*/*" below is required to match Internet Explorer requests.
266
+ # config.navigational_formats = ['*/*', :html, :turbo_stream]
267
+
268
+ # The default HTTP method used to sign out a resource. Default is :delete.
269
+ config.sign_out_via = :delete
270
+
271
+ # ==> OmniAuth
272
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
273
+ # up on your models and hooks.
274
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
275
+ if defined?(OmniAuth)
276
+ Groovestack::Auth.configured_providers(ancestor: Groovestack::Auth::Providers::OmniAuth).each do |p|
277
+ config.omniauth(*p.generate_omniauth_args)
278
+ end
279
+ end
280
+
281
+ OmniAuth.config.logger = Rails.logger if Rails.env.development?
282
+ OmniAuth.config.allowed_request_methods = [:post]
283
+
284
+ # ==> Warden configuration
285
+ # If you want to use other strategies, that are not supported by Devise, or
286
+ # change the failure app, you can configure them inside the config.warden block.
287
+ #
288
+ # config.warden do |manager|
289
+ # manager.intercept_401 = false
290
+ # manager.default_strategies(scope: :user).unshift :some_external_strategy
291
+ # end
292
+
293
+ # ==> Mountable engine configurations
294
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
295
+ # is mountable, there are some extra configurations to be taken into account.
296
+ # The following options are available, assuming the engine is mounted as:
297
+ #
298
+ # mount MyEngine, at: '/my_engine'
299
+ #
300
+ # The router that invoked `devise_for`, in the example above, would be:
301
+ # config.router_name = :my_engine
302
+ #
303
+ # When using OmniAuth, Devise cannot automatically set OmniAuth path,
304
+ # so you need to do it manually. For the users scope, it would be:
305
+ config.omniauth_path_prefix = '/users/auth'
306
+
307
+ # ==> Hotwire/Turbo configuration
308
+ # When using Devise with Hotwire/Turbo, the http status for error responses
309
+ # and some redirects must match the following. The default in Devise for existing
310
+ # apps is `200 OK` and `302 Found` respectively, but new apps are generated with
311
+ # these new defaults that match Hotwire/Turbo behavior.
312
+ # Note: These might become the new default in future versions of Devise.
313
+ config.responder.error_status = :unprocessable_entity
314
+ config.responder.redirect_status = :see_other
315
+
316
+ # ==> Configuration for :registerable
317
+
318
+ # When set to false, does not sign a user in automatically after their password is
319
+ # changed. Defaults to true, so a user is signed in automatically after changing a password.
320
+ # config.sign_in_after_change_password = true
321
+
322
+ # ==> Configuration for :magic_link_authenticatable
323
+
324
+ # Need to use a custom Devise mailer in order to send magic links.
325
+ # If you're already using a custom mailer just have it inherit from
326
+ # Devise::Passwordless::Mailer instead of Devise::Mailer
327
+ config.mailer = 'Devise::Passwordless::Mailer'
328
+
329
+ # Which algorithm to use for tokenizing magic links. See README for descriptions
330
+ config.passwordless_tokenizer = '::Groovestack::Auth::Passwordless::TOtpTokenizer'
331
+
332
+ # Time period after a magic login link is sent out that it will be valid for.
333
+ config.passwordless_login_within = 20.minutes
334
+
335
+ # The secret key used to generate passwordless login tokens. The default value
336
+ # is nil, which means defer to Devise's `secret_key` config value. Changing this
337
+ # key will render invalid all existing passwordless login tokens. You can
338
+ # generate your own secret value with e.g. `rake secret`
339
+ # config.passwordless_secret_key = nil
340
+
341
+ # When using the :trackable module and MessageEncryptorTokenizer, set to true to
342
+ # consider magic link tokens generated before the user's current sign in time to
343
+ # be expired. In other words, each time you sign in, all existing magic links
344
+ # will be considered invalid.
345
+ config.passwordless_expire_old_tokens_on_sign_in = true
346
+ end
347
+
348
+ module Devise
349
+ module Strategies
350
+ class MagicLinkAuthenticatable < Authenticatable
351
+ # NOTE: need to monkey patch to pass email through
352
+ # to tokenizer (allows stateless tokens)
353
+ attr_accessor :email
354
+
355
+ def valid_for_http_auth?
356
+ super && http_auth_hash[:token].present? && http_auth_hash[:email].present?
357
+ end
358
+
359
+ def valid_for_params_auth?
360
+ super && params_auth_hash[:token].present? && params_auth_hash[:email].present?
361
+ end
362
+
363
+ def authenticate!
364
+ resource_class = mapping.to
365
+
366
+ begin
367
+ resource, extra = resource_class.decode_passwordless_token(token, email, resource_class)
368
+ rescue Devise::Passwordless::InvalidOrExpiredTokenError
369
+ fail!(:magic_link_invalid)
370
+ return
371
+ end
372
+
373
+ if validate(resource)
374
+ remember_me(resource)
375
+ resource.after_magic_link_authentication
376
+ env['warden.magic_link_extra'] = extra.fetch('data', {}).delete('extra')
377
+ success!(resource)
378
+ else
379
+ fail!(:magic_link_invalid)
380
+ end
381
+ end
382
+
383
+ private
384
+
385
+ # Sets the authentication hash and the token from params_auth_hash or http_auth_hash.
386
+ def with_authentication_hash(auth_type, auth_values)
387
+ self.authentication_hash = {}
388
+ self.authentication_type = auth_type
389
+ self.token = auth_values[:token]
390
+ self.email = auth_values[:email] # NOTE: persist email to include in decode key
391
+
392
+ parsed_auth_values = parse_authentication_key_values(auth_values, authentication_keys)
393
+ parsed_request_values = parse_authentication_key_values(request_values, request_keys)
394
+
395
+ parsed_auth_values && parsed_request_values
396
+ end
397
+ end
313
398
  end
314
399
  end