Skip to content

Commit

Permalink
check nonce only if it was passed (kilork#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork authored Feb 28, 2023
1 parent cab523f commit 56f5f7d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<C: CompactJson + Claims, P: Provider + Configurable> Client<P, C> {
/// - Jose Error if the Token isn't decoded
/// - Validation::Mismatch::Issuer if the provider issuer and token issuer mismatch
/// - Validation::Mismatch::Nonce if a given nonce and the token nonce mismatch
/// - Validation::Missing::Nonce if either the token or args has a nonce and the other does not
/// - Validation::Missing::Nonce if args has a nonce and the token does not
/// - Validation::Missing::Audience if the token aud doesn't contain the client id
/// - Validation::Missing::AuthorizedParty if there are multiple audiences and azp is missing
/// - Validation::Mismatch::AuthorizedParty if the azp is not the client_id
Expand Down
9 changes: 2 additions & 7 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn validate_token_issuer<C: Claims>(claims: &C, config: &Config) -> Result<(
}

pub fn validate_token_nonce<C: Claims>(claims: &C, nonce: Option<&str>) -> Result<(), Error> {
match nonce {
Some(expected) => match claims.nonce() {
if let Some(expected) = nonce {
match claims.nonce() {
Some(actual) => {
if expected != actual {
let expected = expected.to_string();
Expand All @@ -26,11 +26,6 @@ pub fn validate_token_nonce<C: Claims>(claims: &C, nonce: Option<&str>) -> Resul
}
}
None => return Err(Validation::Missing(Missing::Nonce).into()),
},
None => {
if claims.nonce().is_some() {
return Err(Validation::Missing(Missing::Nonce).into());
}
}
}

Expand Down

0 comments on commit 56f5f7d

Please sign in to comment.