Skip to content

Commit

Permalink
Add omniauth publik (#13) (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Quentin Champenois <[email protected]>
  • Loading branch information
paulinebessoles and Quentinchampenois authored Oct 20, 2022
1 parent f1b9416 commit 078ab91
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
23 changes: 17 additions & 6 deletions config/initializers/omniauth_publik.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 078ab91

Please sign in to comment.