diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 97d52b9b5..197f98f07 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -31,12 +31,10 @@ end SETUP_PROC = lambda do |env| - service = HostingEnvironment.current_service(Rack::Request.new(env)) + request = Rack::Request.new(env) + service = HostingEnvironment.current_service(request) - dfe_sign_in_redirect_uri = URI.join( - HostingEnvironment.application_url(service), - "/auth/dfe/callback", - ) + dfe_sign_in_redirect_uri = URI.join(request.base_url, "/auth/dfe/callback") env["omniauth.strategy"].options.client_options = { port: dfe_sign_in_issuer_uri&.port, diff --git a/lib/hosting_environment.rb b/lib/hosting_environment.rb index 3716d6ee9..42578dc39 100644 --- a/lib/hosting_environment.rb +++ b/lib/hosting_environment.rb @@ -14,11 +14,6 @@ module HostingEnvironment placements: ENV["PLACEMENTS_DFE_SIGN_IN_SECRET"], }.with_indifferent_access.freeze - SERVICE_HOST = { - claims: ENV["CLAIMS_HOST"], - placements: ENV["PLACEMENTS_HOST"], - }.with_indifferent_access.freeze - def self.env @env ||= ActiveSupport::EnvironmentInquirer.new(ENV["HOSTING_ENV"].presence || "development") end @@ -39,14 +34,6 @@ def self.dfe_sign_in_secret(current_service) DFE_SIGN_IN_CLIENT_SECRETS.fetch(current_service) end - def self.application_url(current_service) - if Rails.env.development? - "http://#{SERVICE_HOST.fetch(current_service)}:#{ENV.fetch("PORT", 3000)}" - else - "https://#{SERVICE_HOST.fetch(current_service)}" - end - end - def self.current_service(request) case request.host when ENV["CLAIMS_HOST"], *ENV.fetch("CLAIMS_HOSTS", "").split(",") diff --git a/spec/lib/hosting_environment_spec.rb b/spec/lib/hosting_environment_spec.rb index c14dcda22..b8522c8a8 100644 --- a/spec/lib/hosting_environment_spec.rb +++ b/spec/lib/hosting_environment_spec.rb @@ -88,42 +88,6 @@ end end - describe ".application_url" do - it "returns the application url for claims" do - current_service = "claims" - expect(described_class.application_url(current_service)).to eq( - "https://claims.localhost", - ) - end - - it "returns the application url for placements" do - current_service = "placements" - expect(described_class.application_url(current_service)).to eq( - "https://placements.localhost", - ) - end - - context "when env is development" do - it "returns the application url for claims with port" do - allow(Rails.env).to receive(:development?).and_return(true) - current_service = "claims" - - expect(described_class.application_url(current_service)).to eq( - "http://claims.localhost:3000", - ) - end - - it "returns the application url for placements with port" do - allow(Rails.env).to receive(:development?).and_return(true) - current_service = "placements" - - expect(described_class.application_url(current_service)).to eq( - "http://placements.localhost:3000", - ) - end - end - end - describe ".current_service" do it "returns the current service for claims" do request = instance_double("Rack::Request", host: ENV["CLAIMS_HOST"])