Add iss element to jwt claim#8
Merged
Merged
Conversation
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds an optional JWT issuer (iss) claim to the crate’s JWT Claims model and updates JWT-related tests accordingly.
Changes:
- Extend
Claimswith an optionaliss: Option<String>field (omitted during serialization whenNone). - Update JWT tests to construct
Claimswith anissvalue. - Add a new public accessor
ApiError::status_code().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/jwt.rs | Adds optional iss field to JWT claims with conditional serialization. |
| src/tests/jwt.rs | Updates claim construction in tests to include iss. |
| src/error.rs | Adds a public status_code() accessor on ApiError. |
Comments suppressed due to low confidence (1)
src/tests/jwt.rs:68
- Tests now include
isswhen constructingClaims, but they never assert thatissround-trips through encode/decode. Consider assertingdecoded.iss == Some("test".to_string())in the valid-token test, and adding a small test case whereissis omitted (None) to ensure backwards compatibility for tokens without an issuer.
fn decode_jwt_valid_token() {
let secret = "mysecret";
let claims = Claims {
prompt: "test prompt".to_string(),
exp: 9999999999,
iss: Some("test".to_string()),
};
let token = jsonwebtoken::encode(
&jsonwebtoken::Header::default(),
&claims,
&jsonwebtoken::EncodingKey::from_secret(secret.as_bytes()),
)
.unwrap();
let decoded = decode_jwt(&token, secret).unwrap();
assert_eq!(decoded.prompt, "test prompt");
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+56
to
+60
| impl ApiError { | ||
| pub fn status_code(&self) -> u16 { | ||
| self.status | ||
| } | ||
| } |
There was a problem hiding this comment.
The PR description focuses on adding an optional iss claim, but this change also adds a new public API (ApiError::status_code). If this method is required for the JWT issuer work, please update the PR description to mention it; otherwise consider splitting it into a separate PR to keep changes scoped and easier to review/revert.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds optional issuer to claims