From 8dea936d4195e79718365befc922609b234ca470 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 5 Mar 2024 16:32:18 +0100 Subject: [PATCH] double callback on FC based on the request host --- app/controllers/application_controller.rb | 3 +++ app/models/current.rb | 2 +- app/models/france_connect_particulier_client.rb | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 38ac6cbcf..469c6e060 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -28,6 +28,9 @@ class ApplicationController < ActionController::Base Current.request_id = request.uuid Current.user = current_user Current.browser = browser + # TODO: remove this block when migration to new domain is done + # headers['Host'] instead of request.host to keep the port (ex: localhost:3000) + Current.host = request.headers['Host'] end def staging_authenticate diff --git a/app/models/current.rb b/app/models/current.rb index c32b02f6d..e7d4f2a6a 100644 --- a/app/models/current.rb +++ b/app/models/current.rb @@ -1,3 +1,3 @@ class Current < ActiveSupport::CurrentAttributes - attribute :user, :request_id, :browser + attribute :user, :request_id, :browser, :host end diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index 072b5ab90..29e3d64bd 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,6 +1,13 @@ class FranceConnectParticulierClient < OpenIDConnect::Client def initialize(code = nil) - super(FRANCE_CONNECT[:particulier]) + config = FRANCE_CONNECT[:particulier] + + # TODO: remove this block when migration to new domain is done + if !Rails.env.test? && Current.host != ENV.fetch("APP_HOST") + config[:redirect_uri] = config[:redirect_uri].gsub(ENV.fetch("APP_HOST"), Current.host) + end + + super(config) if code.present? self.authorization_code = code