spetz commented on code in PR #2656:
URL: https://github.com/apache/iggy/pull/2656#discussion_r2753616097
##########
core/server/src/http/jwt/jwt_manager.rs:
##########
@@ -232,15 +248,63 @@ impl JwtManager {
.error(|e: &IggyError| {
format!("{COMPONENT} (error: {e}) - failed to save revoked
access token: {id}")
})?;
- self.generate(jwt_claims.claims.sub)
+ let user_id = jwt_claims
+ .claims
+ .sub
+ .parse::<u32>()
+ .map_err(|_| IggyError::InvalidAccessToken)?;
+ self.generate(user_id)
}
- pub fn decode(
+ pub async fn decode(
&self,
token: &str,
algorithm: Algorithm,
) -> Result<TokenData<JwtClaims>, IggyError> {
let validation = self.validations.get(&algorithm);
+ let kid = jsonwebtoken::decode_header(token).ok().and_then(|h| h.kid);
+
+ #[allow(clippy::collapsible_if)]
+ if let Ok(insecure) =
jsonwebtoken::dangerous::insecure_decode::<JwtClaims>(token) {
+ debug!(
+ "JWT decoded insecurely, issuer: {}, kid: {:?}",
+ insecure.claims.iss, kid
+ );
+ if let Some(config) =
self.trusted_issuer.get(&insecure.claims.iss) {
+ debug!("Found trusted issuer config: {}", config.issuer);
+ if let Some(kid_str) = kid.as_deref() {
+ if let Some(decoding_key) = self
Review Comment:
Please try to avoid multiple levels of if statements, better to return/break
quickly whenever possible with `let Some()` or `let Ok()` patterns.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]