@@ -252,6 +252,30 @@ where
252252 }
253253 } )
254254 }
255+
256+ fn handle_authenticated_oidc_callback (
257+ & self ,
258+ request : ServiceRequest ,
259+ ) -> LocalBoxFuture < Result < ServiceResponse < BoxBody > , Error > > {
260+ Box :: pin ( async move {
261+ log:: debug!( "Handling OIDC callback for already authenticated user" ) ;
262+
263+ // Try to get the initial URL from the state cookie
264+ let redirect_url = match get_state_from_cookie ( & request) {
265+ Ok ( state) => {
266+ log:: debug!( "Found initial URL in state: {}" , state. initial_url) ;
267+ state. initial_url
268+ }
269+ Err ( e) => {
270+ log:: debug!( "Could not get state from cookie (user might have been redirected from elsewhere): {e}. Redirecting to /" ) ;
271+ "/" . to_string ( )
272+ }
273+ } ;
274+
275+ let response = build_redirect_response ( redirect_url) ;
276+ Ok ( request. into_response ( response) )
277+ } )
278+ }
255279}
256280
257281impl < S > Service < ServiceRequest > for OidcService < S >
@@ -268,6 +292,12 @@ where
268292 fn call ( & self , request : ServiceRequest ) -> Self :: Future {
269293 log:: trace!( "Started OIDC middleware request handling" ) ;
270294
295+ // Handle OIDC callback URL even for authenticated users
296+ if request. path ( ) == SQLPAGE_REDIRECT_URI {
297+ log:: debug!( "The request is the OIDC callback for an authenticated user" ) ;
298+ return self . handle_authenticated_oidc_callback ( request) ;
299+ }
300+
271301 let oidc_client = Arc :: clone ( & self . oidc_state . client ) ;
272302 match get_authenticated_user_info ( & oidc_client, & request) {
273303 Ok ( Some ( claims) ) => {
0 commit comments