Conversation
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
There was a problem hiding this comment.
Pull request overview
Adds support for verifying JWTs using an additional configuration key (unified_secret) as a fallback to jwt_secret, centralizing the verification logic in a helper.
Changes:
- Introduces
verify_with_key_strhelper to verify a token with a provided secret and validate required claims. - Updates
verify_jwt_tokento tryjwt_secretfirst, then fall back tounified_secretif present.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let toml_cfg = get_config_content(); | ||
| let parsed_toml = toml_cfg.parse::<Table>().unwrap(); | ||
| let key_str = parsed_toml["jwt_secret"].as_str().unwrap(); |
There was a problem hiding this comment.
jwt_secret is still accessed via parsed_toml["jwt_secret"].as_str().unwrap(), which will panic before the new unified_secret fallback is attempted. If the intent is to support configs that only define unified_secret (or temporarily omit jwt_secret), switch this to an optional lookup (e.g., get("jwt_secret").and_then(|v| v.as_str())) and only attempt verification when present, otherwise fall through to unified_secret.
|
|
||
| Err(jwt::Error::InvalidSignature) |
There was a problem hiding this comment.
When jwt_secret verification fails and unified_secret is not configured, the function returns a generic jwt::Error::InvalidSignature here, discarding the original verification error from the first attempt. Consider carrying the first error through (e.g., store it and return it when no fallback key exists) so failures are diagnosed accurately.
| if let Some(unified) = parsed_toml.get("unified_secret").and_then(|v| v.as_str()) { | ||
| match verify_with_key_str(token_str, unified) { | ||
| Ok(claims) => { | ||
| debug_log!("email (unified_secret): {}", claims["email"]); | ||
| return Ok(claims); |
There was a problem hiding this comment.
New unified_secret verification path isn’t covered by existing tests (e2e tests currently only configure/sign with jwt_secret). Add a test that signs a token with unified_secret (and optionally ensures fallback works when jwt_secret is wrong/missing) to prevent regressions.
No description provided.