devise.rb 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. # frozen_string_literal: true
  2. require './lib/omni_auth/strategies/reddit'
  3. # Use this hook to configure devise mailer, warden hooks and so forth.
  4. # Many of these configuration options can be set straight in your model.
  5. Devise.setup do |config|
  6. # The secret key used by Devise. Devise uses this key to generate
  7. # random tokens. Changing this key will render invalid all existing
  8. # confirmation, reset password and unlock tokens in the database.
  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 = '8caa33dfbc71eedf4f4f1b6d7966f73840d73d20fa13cf47f5a166f6e90041a6813372a50ca939c25c72a67d99e96f51c04bbe1857fbbc248476af72aafa2a01'
  12. # ==> Controller configuration
  13. # Configure the parent class to the devise controllers.
  14. # config.parent_controller = 'DeviseController'
  15. # ==> Mailer Configuration
  16. # Configure the e-mail address which will be shown in Devise::Mailer,
  17. # note that it will be overwritten if you use your own mailer class
  18. # with default "from" parameter.
  19. # FIXME: change to env var or other
  20. config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
  21. # Configure the class responsible to send e-mails.
  22. # config.mailer = 'Devise::Mailer'
  23. # Configure the parent class responsible to send e-mails.
  24. # config.parent_mailer = 'ActionMailer::Base'
  25. # ==> ORM configuration
  26. # Load and configure the ORM. Supports :active_record (default) and
  27. # :mongoid (bson_ext recommended) by default. Other ORMs may be
  28. # available as additional gems.
  29. require 'devise/orm/active_record'
  30. # ==> Configuration for any authentication mechanism
  31. # Configure which keys are used when authenticating a user. The default is
  32. # just :email. You can configure it to use [:username, :subdomain], so for
  33. # authenticating a user, both parameters are required. Remember that those
  34. # parameters are used only when authenticating and not when retrieving from
  35. # session. If you need permissions, you should implement that in a before
  36. # filter. You can also supply a hash where the value is a boolean determining
  37. # whether or not authentication should be aborted when the value is not
  38. # present.
  39. config.authentication_keys = [:username]
  40. # Configure parameters from the request object used for authentication. Each
  41. # entry given should be a request method and it will automatically be passed
  42. # to the find_for_authentication method and considered in your model lookup.
  43. # For instance, if you set :request_keys to [:subdomain], :subdomain will be
  44. # used on authentication. The same considerations mentioned for
  45. # authentication_keys also apply to request_keys.
  46. # config.request_keys = []
  47. # Configure which authentication keys should be case-insensitive.
  48. # These keys will be downcased upon creating or modifying a user and when used
  49. # to authenticate or find a user. Default is :email.
  50. config.case_insensitive_keys = %i[username email email_confirmation]
  51. # Configure which authentication keys should have whitespace stripped. These
  52. # keys will have whitespace before and after removed upon creating or
  53. # modifying a user and when used to authenticate or find a user. Default is
  54. # :email.
  55. config.strip_whitespace_keys = %i[username email]
  56. # Tell if authentication through request.params is enabled. True by default.
  57. # It can be set to an array that will enable params authentication only for
  58. # the given strategies, for example, `config.params_authenticatable =
  59. # [:database]` will enable it only for database (email + password)
  60. # authentication.
  61. # config.params_authenticatable = true
  62. # Tell if authentication through HTTP Auth is enabled. False by default. It
  63. # can be set to an array that will enable http authentication only for the
  64. # given strategies, for example, `config.http_authenticatable = [:database]`
  65. # will enable it only for database authentication. The supported strategies
  66. # are: :database = Support basic authentication with authentication key +
  67. # password config.http_authenticatable = false
  68. # If 401 status code should be returned for AJAX requests. True by default.
  69. # config.http_authenticatable_on_xhr = true
  70. # The realm used in Http Basic Authentication. 'Application' by default.
  71. # config.http_authentication_realm = 'Application'
  72. # It will change confirmation, password recovery and other workflows
  73. # to behave the same regardless if the e-mail provided was right or wrong.
  74. # Does not affect registerable.
  75. config.paranoid = true
  76. # By default Devise will store the user in session. You can skip storage for
  77. # particular strategies by setting this option.
  78. # Notice that if you are skipping storage for all authentication paths, you
  79. # may want to disable generating routes to Devise's sessions controller by
  80. # passing skip: :sessions to `devise_for` in your config/routes.rb
  81. config.skip_session_storage = [:http_auth]
  82. # By default, Devise cleans up the CSRF token on authentication to
  83. # avoid CSRF token fixation attacks. This means that, when using AJAX
  84. # requests for sign in and sign up, you need to get a new CSRF token
  85. # from the server. You can disable this option at your own risk.
  86. # config.clean_up_csrf_token_on_authentication = true
  87. # When false, Devise will not attempt to reload routes on eager load.
  88. # This can reduce the time taken to boot the app but if your application
  89. # requires the Devise mappings to be loaded during boot time the application
  90. # won't boot properly.
  91. # config.reload_routes = true
  92. # ==> Configuration for :database_authenticatable
  93. # For bcrypt, this is the cost for hashing the password and defaults to 11. If
  94. # using other algorithms, it sets how many times you want the password to be
  95. # hashed.
  96. #
  97. # Limiting the stretches to just one in testing will increase the performance
  98. # of your test suite dramatically. However, it is STRONGLY RECOMMENDED to not
  99. # use a value less than 10 in other environments. Note that, for bcrypt (the
  100. # default algorithm), the cost increases exponentially with the number of
  101. # stretches (e.g. a value of 20 is already extremely slow: approx. 60 seconds
  102. # for 1 calculation).
  103. config.stretches = Rails.env.test? ? 1 : 11
  104. # Set up a pepper to generate the hashed password.
  105. # config.pepper = '51526ffa94bb35de720f3acebdf749bd07d86ffef03bf637f07022806dff74e6045d94ec7912548e53dce24829e8cfb5ed042a08128ea2592a8542d9f5e8f0e5'
  106. # Send a notification to the original email when the user's email is changed.
  107. config.send_email_changed_notification = true
  108. # Send a notification email when the user's password is changed.
  109. config.send_password_change_notification = true
  110. # ==> Configuration for :confirmable
  111. # A period that the user is allowed to access the website even without
  112. # confirming their account. For instance, if set to 2.days, the user will be
  113. # able to access the website for two days without confirming their account,
  114. # access will be blocked just in the third day.
  115. # You can also set it to nil, which will allow the user to access the website
  116. # without confirming their account.
  117. # Default is 0.days, meaning the user cannot access the website without
  118. # confirming their account.
  119. # config.allow_unconfirmed_access_for = 2.days
  120. # A period that the user is allowed to confirm their account before their
  121. # token becomes invalid. For example, if set to 3.days, the user can confirm
  122. # their account within 3 days after the mail was sent, but on the fourth day
  123. # their account can't be confirmed with the token any more.
  124. # Default is nil, meaning there is no restriction on how long a user can take
  125. # before confirming their account.
  126. # config.confirm_within = 3.days
  127. # If true, requires any email changes to be confirmed (exactly the same way as
  128. # initial account confirmation) to be applied. Requires additional
  129. # unconfirmed_email db field (see migrations). Until confirmed, new email is
  130. # stored in unconfirmed_email column, and copied to email column on successful
  131. # confirmation.
  132. config.reconfirmable = true
  133. # Defines which key will be used when confirming an account
  134. # config.confirmation_keys = [:email]
  135. # ==> Configuration for :rememberable
  136. # The time the user will be remembered without asking for credentials again.
  137. # config.remember_for = 2.weeks
  138. # Invalidates all the remember me tokens when the user signs out.
  139. config.expire_all_remember_me_on_sign_out = true
  140. # If true, extends the user's remember period when remembered via cookie.
  141. # config.extend_remember_period = false
  142. # Options to be passed to the created cookie. For instance, you can set
  143. # secure: true in order to force SSL only cookies.
  144. # config.rememberable_options = {}
  145. # ==> Configuration for :validatable
  146. # Range for password length.
  147. config.password_length = 8..128
  148. # Email regex used to validate email formats. It simply asserts that
  149. # one (and only one) @ exists in the given string. This is mainly
  150. # to give user feedback and not to assert the e-mail validity.
  151. config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
  152. # ==> Configuration for :timeoutable
  153. # The time you want to timeout the user session without activity. After this
  154. # time the user will be asked for credentials again. Default is 30 minutes.
  155. # config.timeout_in = 30.minutes
  156. # ==> Configuration for :lockable
  157. # Defines which strategy will be used to lock an account.
  158. # :failed_attempts = Locks an account after a number of failed attempts to sign in.
  159. # :none = No lock strategy. You should handle locking by yourself.
  160. config.lock_strategy = :failed_attempts
  161. # Defines which key will be used when locking and unlocking an account
  162. config.unlock_keys = [:email]
  163. # Defines which strategy will be used to unlock an account.
  164. # :email = Sends an unlock link to the user email
  165. # :time = Re-enables login after a certain amount of time (see :unlock_in below)
  166. # :both = Enables both strategies
  167. # :none = No unlock strategy. You should handle unlocking by yourself.
  168. config.unlock_strategy = :both
  169. # Number of authentication tries before locking an account if lock_strategy
  170. # is failed attempts.
  171. config.maximum_attempts = 10
  172. # Time interval to unlock the account if :time is enabled as unlock_strategy.
  173. config.unlock_in = 10.minutes
  174. # Warn on the last attempt before the account is locked.
  175. # config.last_attempt_warning = true
  176. # ==> Configuration for :recoverable
  177. #
  178. # Defines which key will be used when recovering the password for an account
  179. config.reset_password_keys = [:email]
  180. # Time interval you can reset your password with a reset password key.
  181. # Don't put a too small interval or your users won't have the time to
  182. # change their passwords.
  183. config.reset_password_within = 6.hours
  184. # When set to false, does not sign a user in automatically after their
  185. # password is reset. Defaults to true, so a user is signed in automatically
  186. # after a reset.
  187. config.sign_in_after_reset_password = false
  188. # ==> Configuration for :encryptable
  189. # Allow you to use another hashing or encryption algorithm besides bcrypt
  190. # (default). You can use :sha1, :sha512 or algorithms from others
  191. # authentication tools as :clearance_sha1, :authlogic_sha512 (then you should
  192. # set stretches above to 20 for default behavior) and
  193. # :restful_authentication_sha1 (then you should set stretches to 10, and copy
  194. # REST_AUTH_SITE_KEY to pepper).
  195. #
  196. # Require the `devise-encryptable` gem when using anything other than bcrypt
  197. # config.encryptor = :sha512
  198. # ==> Scopes configuration
  199. # Turn scoped views on. Before rendering "sessions/new", it will first check
  200. # for "users/sessions/new". It's turned off by default because it's slower if
  201. # you are using only default views. config.scoped_views = false
  202. # Configure the default scope given to Warden. By default it's the first
  203. # devise role declared in your routes (usually :user).
  204. # config.default_scope = :user
  205. # Set this configuration to false if you want /users/sign_out to sign out
  206. # only the current scope. By default, Devise signs out all scopes.
  207. # config.sign_out_all_scopes = true
  208. # ==> Navigation configuration
  209. # Lists the formats that should be treated as navigational. Formats like
  210. # :html, should redirect to the sign in page when the user does not have
  211. # access, but formats like :xml or :json, should return 401.
  212. #
  213. # If you have any extra navigational formats, like :iphone or :mobile, you
  214. # should add them to the navigational formats lists.
  215. #
  216. # The "*/*" below is required to match Internet Explorer requests.
  217. # config.navigational_formats = ['*/*', :html]
  218. # The default HTTP method used to sign out a resource. Default is :delete.
  219. config.sign_out_via = :delete
  220. # ==> OmniAuth
  221. # Add a new OmniAuth provider. Check the wiki for more information on setting
  222. # up on your models and hooks.
  223. config.omniauth :reddit,
  224. ENV['REDDIT_OAUTH_CLIENT_ID'],
  225. ENV['REDDIT_OAUTH_SECRET'],
  226. scope: 'identity',
  227. duration: 'temporary'
  228. config.omniauth :google_oauth2,
  229. ENV['GOOGLE_OAUTH_CLIENT_ID'],
  230. ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
  231. scope: 'email'
  232. config.omniauth :discord,
  233. ENV['DISCORD_CLIENT_ID'],
  234. ENV['DISCORD_CLIENT_SECRET'],
  235. scope: 'email identify'
  236. # ==> Warden configuration
  237. # If you want to use other strategies, that are not supported by Devise, or
  238. # change the failure app, you can configure them inside the config.warden
  239. # block.
  240. #
  241. # config.warden do |manager|
  242. # manager.intercept_401 = false
  243. # manager.default_strategies(scope: :user).unshift :some_external_strategy
  244. # end
  245. # ==> Mountable engine configurations
  246. # When using Devise inside an engine, let's call it `MyEngine`, and this
  247. # engine is mountable, there are some extra configurations to be taken into
  248. # account. The following options are available, assuming the engine is
  249. # mounted as:
  250. #
  251. # mount MyEngine, at: '/my_engine'
  252. #
  253. # The router that invoked `devise_for`, in the example above, would be:
  254. # config.router_name = :my_engine
  255. #
  256. # When using OmniAuth, Devise cannot automatically set OmniAuth path,
  257. # so you need to do it manually. For the users scope, it would be:
  258. # config.omniauth_path_prefix = '/my_engine/users/auth'
  259. # ==> Turbolinks configuration
  260. # If your app is using Turbolinks, Turbolinks::Controller needs to be included
  261. # to make redirection work correctly:
  262. #
  263. # ActiveSupport.on_load(:devise_failure_app) do
  264. # include Turbolinks::Controller
  265. # end
  266. # ==> Configuration for :registerable
  267. # When set to false, does not sign a user in automatically after their
  268. # password is changed. Defaults to true, so a user is signed in automatically
  269. # after changing a password.
  270. # config.sign_in_after_change_password = true
  271. end