Add configurable issuer/audience validation with dynamic claim support#957
Open
diegocastrum wants to merge 15 commits into
Open
Add configurable issuer/audience validation with dynamic claim support#957diegocastrum wants to merge 15 commits into
diegocastrum wants to merge 15 commits into
Conversation
Member
Author
|
@Andrew-Chen-Wang would you mind taking a look when you have time? Would appreciate a quick review or guidance on how to move forward |
Andrew-Chen-Wang
requested changes
Apr 20, 2026
Member
Andrew-Chen-Wang
left a comment
There was a problem hiding this comment.
thanks for these changes. left some comments. have more to come pending your thoughts
diegocastrum
added a commit
to diegocastrum/djangorestframework-simplejwt
that referenced
this pull request
Apr 20, 2026
- Add `ISS_CLAIM` and `ALLOWED_ISSUERS` settings for issuer configuration - Implement `set_iss()` and `verify_iss()` methods in `Token` class - Add issuer verification in `Token.verify()` when configured - Call `set_iss()` in `TokenRefreshSerializer` during token rotation - Comment out issuer parameter from `TokenBackend` (WIP) - Disable PyJWT's built-in issuer validation in `decode()` This enables tokens to have dynamic issuers based on request context while maintaining backward compatibility with static `ISSUER` setting. Validation supports three modes: - Static issuer (`ISSUER` setting) - Whitelist validation (`ALLOWED_ISSUERS` setting) - Dynamic issuers (no issuer validation beyond format checks) Note: `TokenBackend` issuer handling still needs refactoring to fully support the dynamic issuer workflow without double-decoding. Fixes jazzband#899
…port - add `ISSUER_VALIDATION` setting (static/dynamic) defaulting to static PyJWT enforcement - pass issuer to `TokenBackend/PyJWT` only in static mode; skip in dynamic mode to allow per-token issuers Add support for `aud` (audience) and `iss` (issuer) claims in tokens Fixes jazzband#899
- add `AUDIENCE_VALIDATION` setting (static/dynamic) and wire backend to skip PyJWT audience checks in dynamic mode - allow `Token.verify_aud` to accept per-token audiences when config is unset and dynamic mode is enabled - expose backend `verify_aud`/`verify_iss` flags and document the new setting Add support for `aud` (audience) and `iss` (issuer) claims in tokens Fixes jazzband#899
for more information, see https://pre-commit.ci
b629c42 to
0a5479f
Compare
…on logic and tests Fixes jazzband#899
for more information, see https://pre-commit.ci
Member
Author
|
@Andrew-Chen-Wang I’ve addressed the previous feedback and updated the PR accordingly. Would you mind taking another look when you have some time? Thanks a lot! |
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.
This pull request introduces enhanced support for dynamic and static validation of JWT audience and issuer claims in Simple JWT, along with improved settings validation and more flexible claim handling. It adds new settings (
AUDIENCE_VALIDATION,ISSUER_CLAIM), refines how audience and issuer are validated or set, and provides comprehensive documentation and tests for these behaviors.Settings and Validation Improvements:
AUDIENCE_VALIDATIONsetting to control whether audience validation is "static" (default, enforced by PyJWT) or "dynamic" (enforced by Simple JWT logic after decoding). [1] [2] [3]ISSUER_CLAIMsetting to allow customization of the issuer claim name (default:"iss"). [1] [2] [3]AUDIENCE_VALIDATIONis a supported value and thatISSUERis a non-empty string or a sequence of non-empty strings, raising clear errors otherwise. [1] [2]Token Claim Handling:
Tokenclass for setting and verifying audience (aud) and issuer (iss) claims, supporting both static and dynamic configurations, and handling both single and multiple allowed issuers/audiences. [1] [2] [3]issandaudclaims are set and checked according to the new settings and logic. [1] [2]Backend and Decode Logic:
Documentation and Testing:
These changes make Simple JWT more flexible for multi-tenant or dynamic audience/issuer scenarios, and ensure that misconfigurations are detected early with clear error messages.