@@ -252,29 +252,19 @@ where
252252 }
253253 } )
254254 }
255+ }
255256
256- fn handle_authenticated_oidc_callback (
257- request : ServiceRequest ,
258- ) -> LocalBoxFuture < Result < ServiceResponse < BoxBody > , Error > > {
259- Box :: pin ( async move {
260- log:: debug!( "Handling OIDC callback for already authenticated user" ) ;
261-
262- // Try to get the initial URL from the state cookie
263- let redirect_url = match get_state_from_cookie ( & request) {
264- Ok ( state) => {
265- log:: debug!( "Found initial URL in state: {}" , state. initial_url) ;
266- state. initial_url
267- }
268- Err ( e) => {
269- log:: debug!( "Could not get state from cookie (user might have been redirected from elsewhere): {e}. Redirecting to /" ) ;
270- "/" . to_string ( )
271- }
272- } ;
273-
274- let response = build_redirect_response ( redirect_url) ;
275- Ok ( request. into_response ( response) )
276- } )
277- }
257+ /// When an user has already authenticated (potentially in another tab), we ignore the callback and redirect to the initial URL.
258+ fn handle_authenticated_oidc_callback (
259+ request : ServiceRequest ,
260+ ) -> LocalBoxFuture < Result < ServiceResponse < BoxBody > , Error > > {
261+ let redirect_url = match get_state_from_cookie ( & request) {
262+ Ok ( state) => state. initial_url ,
263+ Err ( _) => "/" . to_string ( ) ,
264+ } ;
265+ log:: debug!( "OIDC callback received for authenticated user. Redirecting to {redirect_url}" ) ;
266+ let response = request. into_response ( build_redirect_response ( redirect_url) ) ;
267+ Box :: pin ( ready ( Ok ( response) ) )
278268}
279269
280270impl < S > Service < ServiceRequest > for OidcService < S >
@@ -294,14 +284,11 @@ where
294284 let oidc_client = Arc :: clone ( & self . oidc_state . client ) ;
295285 match get_authenticated_user_info ( & oidc_client, & request) {
296286 Ok ( Some ( claims) ) => {
297- log:: trace!( "Storing authenticated user info in request extensions: {claims:?}" ) ;
298- request. extensions_mut ( ) . insert ( claims) ;
299-
300- // Handle OIDC callback URL for authenticated users
301287 if request. path ( ) == SQLPAGE_REDIRECT_URI {
302- log:: debug!( "The request is the OIDC callback for an authenticated user" ) ;
303- return Self :: handle_authenticated_oidc_callback ( request) ;
288+ return handle_authenticated_oidc_callback ( request) ;
304289 }
290+ log:: trace!( "Storing authenticated user info in request extensions: {claims:?}" ) ;
291+ request. extensions_mut ( ) . insert ( claims) ;
305292 }
306293 Ok ( None ) => {
307294 log:: trace!( "No authenticated user found" ) ;
0 commit comments