diff --git a/.env-example b/.env-example index 6c8f3e1..6b65b40 100644 --- a/.env-example +++ b/.env-example @@ -2,3 +2,6 @@ SECRET_KEY_BASE= HELP_SCOUT_BEACON_ID_MAIN= SENTRY_DSN= DECIDIM_SESSION_TIMEOUT= +OMNIAUTH_PUBLIK_CLIENT_ID= +OMNIAUTH_PUBLIK_CLIENT_SECRET= +OMNIAUTH_PUBLIK_SITE_URL= diff --git a/config/initializers/omniauth_publik.rb b/config/initializers/omniauth_publik.rb index 184c3c7..cd6e794 100644 --- a/config/initializers/omniauth_publik.rb +++ b/config/initializers/omniauth_publik.rb @@ -1,9 +1,20 @@ # frozen_string_literal: true -Devise.setup do |config| - config.omniauth :publik, - client_id: ENV["PUBLIK_CLIENT_ID"], - client_secret: ENV["PUBLIK_CLIENT_SECRET"], - site: ENV["PUBLIK_SITE_URL"], - scope: "openid email profile" +return unless defined?(OmniAuth::Strategies::Publik) + +if Rails.application.secrets.dig(:omniauth, :publik).present? + Rails.application.config.middleware.use OmniAuth::Builder do + provider( + :publik, + setup: lambda { |env| + request = Rack::Request.new(env) + organization = Decidim::Organization.find_by(host: request.host) + provider_config = organization.enabled_omniauth_providers[:publik] + env["omniauth.strategy"].options[:client_id] = provider_config[:client_id] + env["omniauth.strategy"].options[:client_secret] = provider_config[:client_secret] + env["omniauth.strategy"].options[:site] = provider_config[:site_url] + }, + scope: :public + ) + end end diff --git a/config/secrets.yml b/config/secrets.yml index 57e49b4..0b85310 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -34,7 +34,10 @@ default: &default # client_id: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_ID"] %> # client_secret: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"] %> publik: - enabled: false + enabled: <%= ENV["OMNIAUTH_PUBLIK_CLIENT_SECRET"].present? %> + client_id: <%= ENV["OMNIAUTH_PUBLIK_CLIENT_ID"] %> + client_secret: <%= ENV["OMNIAUTH_PUBLIK_CLIENT_SECRET"] %> + site_url: <%= ENV["OMNIAUTH_PUBLIK_SITE_URL"] %> geocoder: here_api_key: <%= ENV["GEOCODER_API_KEY"] %> maps: