Skip to content

Commit c59ee5b

Browse files
committed
aaa
1 parent 4a62a23 commit c59ee5b

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

crates/oidc-client/src/requests/authorization_code.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,28 +528,26 @@ pub async fn access_token_with_authorization_code(
528528
.await?;
529529

530530
let id_token = if let Some(verification_data) = id_token_verification_data {
531-
let signing_alg = verification_data.signing_algorithm;
532-
533531
let id_token = token_response
534532
.id_token
535533
.as_deref()
536534
.ok_or(IdTokenError::MissingIdToken)?;
537535

538-
let id_token = verify_id_token(id_token, verification_data, None, now)?;
536+
let (id_token, signing_alg) = verify_id_token(id_token, verification_data, None, now)?;
539537

540538
let mut claims = id_token.payload().clone();
541539

542540
// Access token hash must match.
543541
claims::AT_HASH
544542
.extract_optional_with_options(
545543
&mut claims,
546-
TokenHash::new(signing_alg, &token_response.access_token),
544+
TokenHash::new(&signing_alg, &token_response.access_token),
547545
)
548546
.map_err(IdTokenError::from)?;
549547

550548
// Code hash must match.
551549
claims::C_HASH
552-
.extract_optional_with_options(&mut claims, TokenHash::new(signing_alg, &code))
550+
.extract_optional_with_options(&mut claims, TokenHash::new(&signing_alg, &code))
553551
.map_err(IdTokenError::from)?;
554552

555553
// Nonce must match.

crates/oidc-client/src/requests/jose.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ pub struct JwtVerificationData<'a> {
102102
pub fn verify_signed_jwt<'a>(
103103
jwt: &'a str,
104104
verification_data: JwtVerificationData<'_>,
105-
) -> Result<Jwt<'a, HashMap<String, Value>>, JwtVerificationError> {
105+
) -> Result<(Jwt<'a, HashMap<String, Value>>, JsonWebSignatureAlg), JwtVerificationError> {
106106
tracing::debug!("Validating JWT...");
107107

108108
let JwtVerificationData {
109109
issuer,
110110
jwks,
111111
client_id,
112-
signing_algorithm,
112+
signing_algorithm: _,
113113
} = verification_data;
114114

115115
let jwt: Jwt<HashMap<String, Value>> = jwt.try_into()?;
@@ -124,12 +124,7 @@ pub fn verify_signed_jwt<'a>(
124124
// Must have the proper audience.
125125
claims::AUD.extract_required_with_options(&mut claims, client_id)?;
126126

127-
// Must use the proper algorithm.
128-
if header.alg() != signing_algorithm {
129-
return Err(JwtVerificationError::WrongSignatureAlg);
130-
}
131-
132-
Ok(jwt)
127+
Ok((jwt, header.alg().clone()))
133128
}
134129

135130
/// Decode and verify an ID Token.
@@ -167,8 +162,8 @@ pub fn verify_id_token<'a>(
167162
verification_data: JwtVerificationData<'_>,
168163
auth_id_token: Option<&IdToken<'_>>,
169164
now: DateTime<Utc>,
170-
) -> Result<IdToken<'a>, IdTokenError> {
171-
let id_token = verify_signed_jwt(id_token, verification_data)?;
165+
) -> Result<(IdToken<'a>, JsonWebSignatureAlg), IdTokenError> {
166+
let (id_token, signing_alg) = verify_signed_jwt(id_token, verification_data)?;
172167

173168
let mut claims = id_token.payload().clone();
174169

@@ -202,5 +197,5 @@ pub fn verify_id_token<'a>(
202197
}
203198
}
204199

205-
Ok(id_token)
206-
}
200+
Ok((id_token, signing_alg))
201+
}

crates/oidc-client/src/requests/refresh_token.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ pub async fn refresh_access_token(
9797
id_token_verification_data.zip(token_response.id_token.as_ref())
9898
{
9999
let auth_id_token = auth_id_token.ok_or(IdTokenError::MissingAuthIdToken)?;
100-
let signing_alg = verification_data.signing_algorithm;
101100

102-
let id_token = verify_id_token(id_token, verification_data, Some(auth_id_token), now)?;
101+
let (id_token, signing_alg) =
102+
verify_id_token(id_token, verification_data, Some(auth_id_token), now)?;
103103

104104
let mut claims = id_token.payload().clone();
105105

106106
// Access token hash must match.
107107
claims::AT_HASH
108108
.extract_optional_with_options(
109109
&mut claims,
110-
TokenHash::new(signing_alg, &token_response.access_token),
110+
TokenHash::new(&signing_alg, &token_response.access_token),
111111
)
112112
.map_err(IdTokenError::from)?;
113113

crates/oidc-client/src/requests/userinfo.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ pub async fn fetch_userinfo(
108108
let response_body = std::str::from_utf8(userinfo_response.body())?;
109109

110110
let mut claims = if let Some(verification_data) = jwt_verification_data {
111-
verify_signed_jwt(response_body, verification_data)
112-
.map_err(IdTokenError::from)?
113-
.into_parts()
114-
.1
111+
let (id_token, _) =
112+
verify_signed_jwt(response_body, verification_data).map_err(IdTokenError::from)?;
113+
id_token.into_parts().1
115114
} else {
116115
serde_json::from_str(response_body)?
117116
};

0 commit comments

Comments
 (0)