Load OmniauthTenantSetup inside a lambda

This way we avoid loading the OmniauthTenantSetup in the initializer,
which could be problematic when switching to Zeitwerk.
This commit is contained in:
Javi Martín
2024-03-29 00:49:18 +01:00
parent 1cf529b134
commit 1af5c18bd7
2 changed files with 12 additions and 20 deletions

View File

@@ -1,27 +1,19 @@
module OmniauthTenantSetup
class << self
def twitter
->(env) do
oauth(env, secrets.twitter_key, secrets.twitter_secret)
end
def twitter(env)
oauth(env, secrets.twitter_key, secrets.twitter_secret)
end
def facebook
->(env) do
oauth2(env, secrets.facebook_key, secrets.facebook_secret)
end
def facebook(env)
oauth2(env, secrets.facebook_key, secrets.facebook_secret)
end
def google_oauth2
->(env) do
oauth2(env, secrets.google_oauth2_key, secrets.google_oauth2_secret)
end
def google_oauth2(env)
oauth2(env, secrets.google_oauth2_key, secrets.google_oauth2_secret)
end
def wordpress_oauth2
->(env) do
oauth2(env, secrets.wordpress_oauth2_key, secrets.wordpress_oauth2_secret)
end
def wordpress_oauth2(env)
oauth2(env, secrets.wordpress_oauth2_key, secrets.wordpress_oauth2_secret)
end
private

View File

@@ -270,22 +270,22 @@ Devise.setup do |config|
config.omniauth :twitter,
Rails.application.secrets.twitter_key,
Rails.application.secrets.twitter_secret,
setup: OmniauthTenantSetup.twitter
setup: ->(env) { OmniauthTenantSetup.twitter(env) }
config.omniauth :facebook,
Rails.application.secrets.facebook_key,
Rails.application.secrets.facebook_secret,
scope: "email",
info_fields: "email,name,verified",
setup: OmniauthTenantSetup.facebook
setup: ->(env) { OmniauthTenantSetup.facebook(env) }
config.omniauth :google_oauth2,
Rails.application.secrets.google_oauth2_key,
Rails.application.secrets.google_oauth2_secret,
setup: OmniauthTenantSetup.google_oauth2
setup: ->(env) { OmniauthTenantSetup.google_oauth2(env) }
config.omniauth :wordpress_oauth2,
Rails.application.secrets.wordpress_oauth2_key,
Rails.application.secrets.wordpress_oauth2_secret,
client_options: { site: Rails.application.secrets.wordpress_oauth2_site },
setup: OmniauthTenantSetup.wordpress_oauth2
setup: ->(env) { OmniauthTenantSetup.wordpress_oauth2(env) }
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or