Skip to content

Add configurable issuer/audience validation with dynamic claim support#957

Open
diegocastrum wants to merge 9 commits intojazzband:masterfrom
diegocastrum:feature/support_to_set_aud_and_iss_claims
Open

Add configurable issuer/audience validation with dynamic claim support#957
diegocastrum wants to merge 9 commits intojazzband:masterfrom
diegocastrum:feature/support_to_set_aud_and_iss_claims

Conversation

@diegocastrum
Copy link
Copy Markdown
Member

@diegocastrum diegocastrum commented Dec 19, 2025

This pull request introduces flexible and configurable validation for the JWT audience (aud) and issuer (iss) claims in both token generation and verification. It allows projects to choose between strict/static validation (using fixed values from settings) or dynamic validation (accepting values from incoming tokens and validating them according to custom logic). The changes include new settings, backend logic updates, token claim handling, and comprehensive tests for these behaviors.

Audience and Issuer Validation Improvements:

  • Added new settings: AUDIENCE_VALIDATION and ISSUER_VALIDATION, allowing control over whether audience and issuer are validated statically (default, using configured values) or dynamically (accepting values from tokens and validating them in code). [1] [2]
  • Updated the backend initialization and decode logic in TokenBackend to respect the new validation modes, passing or omitting audience and issuer to PyJWT as appropriate. [1] [2] [3] [4]

Token Claim Handling:

  • Implemented set_iss, set_aud, verify_iss, and verify_aud methods in the Token class to support dynamic/static claim population and validation, including support for an allowed issuers whitelist. [1] [2]
  • Ensured that tokens are populated with iss and aud claims during creation, and that these claims are validated according to the selected mode. [1] [2]

Documentation Updates:

  • Expanded the documentation to explain the new audience and issuer validation settings, their valid values, and how they affect token processing.

Testing Enhancements:

  • Added comprehensive tests to cover static and dynamic validation scenarios for both audience and issuer claims, including correct acceptance and rejection of claims based on configuration. [1] [2]

Closes #899

- 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
@diegocastrum diegocastrum requested a review from 2ykwang December 26, 2025 06:26
@diegocastrum diegocastrum requested review from Andrew-Chen-Wang and vgrozdanic and removed request for 2ykwang and vgrozdanic February 1, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for aud (audience) and iss (issuer) claims in tokens

1 participant