oidc: Add checking of state returned by IdP

This commit is contained in:
Lennart
2025-04-20 21:30:32 +02:00
parent 2c74d56f50
commit 5e4cdc6a12

View File

@@ -131,6 +131,7 @@ pub async fn route_post_oidc(
pub struct AuthCallbackQuery {
code: AuthorizationCode,
iss: IssuerUrl,
state: String,
}
/// Handle callback from IdP page
@@ -139,7 +140,7 @@ pub async fn route_get_oidc_callback<AP: AuthenticationProvider>(
oidc_config: Data<OidcConfig>,
session: Session,
auth_provider: Data<AP>,
Query(AuthCallbackQuery { code, iss }): Query<AuthCallbackQuery>,
Query(AuthCallbackQuery { code, iss, state }): Query<AuthCallbackQuery>,
default_redirect_name: Data<DefaultRedirectRouteName>,
) -> Result<impl Responder, OidcError> {
assert_eq!(iss, oidc_config.issuer);
@@ -148,6 +149,8 @@ pub async fn route_get_oidc_callback<AP: AuthenticationProvider>(
.ok_or(OidcError::Other("No local OIDC state"))?
.map_err(|_| OidcError::Other("Error parsing OIDC state"))?;
assert_eq!(oidc_state.state.secret(), &state);
let http_client = get_http_client();
let oidc_client = get_oidc_client(
oidc_config.get_ref().clone(),