Skip to content

Commit 8e07bab

Browse files
committed
OIDC callback: redirect to the auth URL on failure.
1 parent 9f22532 commit 8e07bab

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/webserver/oidc.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,16 @@ impl<S> OidcService<S> {
200200
) -> LocalBoxFuture<Result<ServiceResponse<BoxBody>, Error>> {
201201
let oidc_client = Arc::clone(&self.oidc_client);
202202
let http_client = Arc::clone(&self.http_client);
203+
let oidc_config = Arc::clone(&self.config);
203204

204205
Box::pin(async move {
205206
let query_string = request.query_string();
206207
match process_oidc_callback(&oidc_client, &http_client, query_string).await {
207208
Ok(response) => Ok(request.into_response(response)),
208209
Err(e) => {
209210
log::error!("Failed to process OIDC callback with params {query_string}: {e}");
210-
Ok(request.into_response(HttpResponse::BadRequest().body(e.to_string())))
211+
let auth_url = build_auth_url(&oidc_client, &oidc_config.scopes);
212+
Ok(request.into_response(build_redirect_response(auth_url)))
211213
}
212214
}
213215
})
@@ -457,3 +459,15 @@ struct OidcCallbackParams {
457459
code: String,
458460
state: String,
459461
}
462+
463+
fn build_auth_url(oidc_client: &OidcClient, scopes: &[Scope]) -> String {
464+
let (auth_url, csrf_token, nonce) = oidc_client
465+
.authorize_url(
466+
CoreAuthenticationFlow::AuthorizationCode,
467+
CsrfToken::new_random,
468+
Nonce::new_random,
469+
)
470+
.add_scopes(scopes.iter().cloned())
471+
.url();
472+
auth_url.to_string()
473+
}

0 commit comments

Comments
 (0)