From 1af66730f8502ddd5b0a939430e4ce9cb1f6a407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 15 Oct 2024 09:06:33 +0200 Subject: [PATCH] Allow seeding with path config as shown in docs --- .../app/models/openid_connect/provider.rb | 2 +- .../openid_connect/provider_seeder.rb | 2 +- .../openid_connect/configuration_mapper.rb | 27 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rb index 17e50f95aea9..06905634e297 100644 --- a/modules/openid_connect/app/models/openid_connect/provider.rb +++ b/modules/openid_connect/app/models/openid_connect/provider.rb @@ -32,7 +32,7 @@ class Provider < AuthProvider def self.slug_fragment = "oidc" def seeded_from_env? - (Setting.seed_openid_connect_provider || {}).key?(slug) + (Setting.seed_oidc_provider || {}).key?(slug) end def basic_details_configured? diff --git a/modules/openid_connect/app/seeders/env_data/openid_connect/provider_seeder.rb b/modules/openid_connect/app/seeders/env_data/openid_connect/provider_seeder.rb index 861dd96206ad..732ff3bc3e48 100644 --- a/modules/openid_connect/app/seeders/env_data/openid_connect/provider_seeder.rb +++ b/modules/openid_connect/app/seeders/env_data/openid_connect/provider_seeder.rb @@ -33,7 +33,7 @@ class ProviderSeeder < Seeder def seed_data! Setting.seed_oidc_provider.each do |name, configuration| print_status " ↳ Creating or Updating OpenID provider #{name}" do - call = ::OpenIDConnect::SyncService.new(name, configuration).call + call = ::OpenIDConnect::SyncService.new(name, configuration.merge(name:)).call if call.success print_status " - #{call.message}" diff --git a/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb b/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb index 59ad4826a0ce..bb56b5ec63b2 100644 --- a/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb +++ b/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb @@ -44,9 +44,9 @@ def call! "client_id" => options["identifier"], "client_secret" => options["secret"], "issuer" => options["issuer"], - "authorization_endpoint" => options["authorization_endpoint"], - "token_endpoint" => options["token_endpoint"], - "userinfo_endpoint" => options["userinfo_endpoint"], + "authorization_endpoint" => extract_url(options, "authorization_endpoint"), + "token_endpoint" => extract_url(options, "token_endpoint"), + "userinfo_endpoint" => extract_url(options, "userinfo_endpoint"), "end_session_endpoint" => options["end_session_endpoint"], "jwks_uri" => options["jwks_uri"] } @@ -54,6 +54,27 @@ def call! private + def extract_url(options, key) + value = options[key] + return value if value.start_with?('http') + unless value.start_with?("/") + raise ArgumentError.new("Provided #{key} '#{value}' needs to be http(s) URL or path starting with a slash.") + end + + URI + .join(base_url(options), value) + .to_s + end + + def base_url(options) + raise ArgumentError.new("Missing host in configuration") unless options["host"] + URI::Generic.build( + host: options["host"], + port: options["port"], + scheme: options["scheme"] || "https" + ).to_s + end + def mapped_options(options) extract_mapping(options)