@@ -254,6 +254,19 @@ where
254
254
}
255
255
}
256
256
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) ) )
268
+ }
269
+
257
270
impl < S > Service < ServiceRequest > for OidcService < S >
258
271
where
259
272
S : Service < ServiceRequest , Response = ServiceResponse < BoxBody > , Error = Error > ,
@@ -271,6 +284,9 @@ where
271
284
let oidc_client = Arc :: clone ( & self . oidc_state . client ) ;
272
285
match get_authenticated_user_info ( & oidc_client, & request) {
273
286
Ok ( Some ( claims) ) => {
287
+ if request. path ( ) == SQLPAGE_REDIRECT_URI {
288
+ return handle_authenticated_oidc_callback ( request) ;
289
+ }
274
290
log:: trace!( "Storing authenticated user info in request extensions: {claims:?}" ) ;
275
291
request. extensions_mut ( ) . insert ( claims) ;
276
292
}
0 commit comments