mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
oidc: Add checking of state returned by IdP
This commit is contained in:
@@ -131,6 +131,7 @@ pub async fn route_post_oidc(
|
|||||||
pub struct AuthCallbackQuery {
|
pub struct AuthCallbackQuery {
|
||||||
code: AuthorizationCode,
|
code: AuthorizationCode,
|
||||||
iss: IssuerUrl,
|
iss: IssuerUrl,
|
||||||
|
state: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle callback from IdP page
|
/// Handle callback from IdP page
|
||||||
@@ -139,7 +140,7 @@ pub async fn route_get_oidc_callback<AP: AuthenticationProvider>(
|
|||||||
oidc_config: Data<OidcConfig>,
|
oidc_config: Data<OidcConfig>,
|
||||||
session: Session,
|
session: Session,
|
||||||
auth_provider: Data<AP>,
|
auth_provider: Data<AP>,
|
||||||
Query(AuthCallbackQuery { code, iss }): Query<AuthCallbackQuery>,
|
Query(AuthCallbackQuery { code, iss, state }): Query<AuthCallbackQuery>,
|
||||||
default_redirect_name: Data<DefaultRedirectRouteName>,
|
default_redirect_name: Data<DefaultRedirectRouteName>,
|
||||||
) -> Result<impl Responder, OidcError> {
|
) -> Result<impl Responder, OidcError> {
|
||||||
assert_eq!(iss, oidc_config.issuer);
|
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"))?
|
.ok_or(OidcError::Other("No local OIDC state"))?
|
||||||
.map_err(|_| OidcError::Other("Error parsing OIDC state"))?;
|
.map_err(|_| OidcError::Other("Error parsing OIDC state"))?;
|
||||||
|
|
||||||
|
assert_eq!(oidc_state.state.secret(), &state);
|
||||||
|
|
||||||
let http_client = get_http_client();
|
let http_client = get_http_client();
|
||||||
let oidc_client = get_oidc_client(
|
let oidc_client = get_oidc_client(
|
||||||
oidc_config.get_ref().clone(),
|
oidc_config.get_ref().clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user