Skip to content

Commit 558b578

Browse files
authored
Fix oidc callback for authenticated users (#978)
* Handle OIDC callback for already authenticated users Co-authored-by: contact <[email protected]> * Fix lifetime annotations and remove unnecessary self references Co-authored-by: contact <[email protected]> * Move OIDC callback handling after user authentication check Co-authored-by: contact <[email protected]> * fmt * fix cursor fuckup * Move OIDC callback handler to standalone function
1 parent 4b15bf1 commit 558b578

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/webserver/oidc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ where
254254
}
255255
}
256256

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+
257270
impl<S> Service<ServiceRequest> for OidcService<S>
258271
where
259272
S: Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error>,
@@ -271,6 +284,9 @@ where
271284
let oidc_client = Arc::clone(&self.oidc_state.client);
272285
match get_authenticated_user_info(&oidc_client, &request) {
273286
Ok(Some(claims)) => {
287+
if request.path() == SQLPAGE_REDIRECT_URI {
288+
return handle_authenticated_oidc_callback(request);
289+
}
274290
log::trace!("Storing authenticated user info in request extensions: {claims:?}");
275291
request.extensions_mut().insert(claims);
276292
}

0 commit comments

Comments
 (0)