mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00

When supporting Rails 5.2 credentials on https://github.com/plataformatec/devise/pull/4712, we ended up breaking apps that were upgraded to Rails 5.2 and weren't using `credentials` to store their `secret_key_base`. See https://github.com/plataformatec/devise/issues/4807 for more context. To fix it, we're now checking whether the key is present before using it. Since there weren't any automated test for this - the conditionals were in a Rails engine initializer - I've extracted it to a new class so that we are able to test it easily. Fixes #4807
47 lines
1.3 KiB
Ruby
47 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'devise/rails/routes'
|
|
require 'devise/rails/warden_compat'
|
|
|
|
module Devise
|
|
class Engine < ::Rails::Engine
|
|
config.devise = Devise
|
|
|
|
# Initialize Warden and copy its configurations.
|
|
config.app_middleware.use Warden::Manager do |config|
|
|
Devise.warden_config = config
|
|
end
|
|
|
|
# Force routes to be loaded if we are doing any eager load.
|
|
config.before_eager_load do |app|
|
|
app.reload_routes! if Devise.reload_routes
|
|
end
|
|
|
|
initializer "devise.url_helpers" do
|
|
Devise.include_helpers(Devise::Controllers)
|
|
end
|
|
|
|
initializer "devise.omniauth", after: :load_config_initializers, before: :build_middleware_stack do |app|
|
|
Devise.omniauth_configs.each do |provider, config|
|
|
app.middleware.use config.strategy_class, *config.args do |strategy|
|
|
config.strategy = strategy
|
|
end
|
|
end
|
|
|
|
if Devise.omniauth_configs.any?
|
|
Devise.include_helpers(Devise::OmniAuth)
|
|
end
|
|
end
|
|
|
|
initializer "devise.secret_key" do |app|
|
|
Devise.secret_key ||= Devise::SecretKeyFinder.new(app).find
|
|
|
|
Devise.token_generator ||=
|
|
if secret_key = Devise.secret_key
|
|
Devise::TokenGenerator.new(
|
|
ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|