[18.0][IMP] auth_jwt: allow more authorization options over aud#944
Open
dnplkndll wants to merge 1 commit into
Open
[18.0][IMP] auth_jwt: allow more authorization options over aud#944dnplkndll wants to merge 1 commit into
dnplkndll wants to merge 1 commit into
Conversation
34e527c to
e1cfb6f
Compare
e1cfb6f to
7969643
Compare
Contributor
Author
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.
Revives #753 (closed stale
2026-02-08) with the documentation improvements requested by
@lmignon in
the prior review.
Same code as #753 (with @kobros-tech's 5 tests preserved) plus:
help=text onaudience_type,audience_type_custom,and
audienceso each form-field tooltip explains the matchingsemantics and the IdP scenarios that motivate each option.
readme/USAGE.md("Audience type — matchingnon-standard JWT claims") covering the four
audience_typevalueswith a worked AWS Cognito example showing how to restrict a route by
cognito:groupsorscope.audience_type_customis nowrequiredin the view whenaudience_type == 'custom'(it was previously a bare field; userscould save a Custom validator with no payload key, which would then
always fail at runtime).
What this PR does (recap from #753)
Some identity providers — notably AWS Cognito and several OAuth2-only
flows — mint access tokens without an
audclaim but exposeauthorization information under other claims (
cognito:groups,scope, vendor-specific keys). Todayauth_jwtrequiresaudandhard-fails on such tokens.
This PR keeps standard
audvalidation as the default and adds threeopt-in modes via a new
audience_typeselection:Group— match against thegroupsclaim.Scope— match against thescopeclaim (RFC 6749 §3.3).Custom— match against an arbitrary payload key (e.g.cognito:groups,permissions).For non-
audtypes the JWT library's built-inaudverification isskipped (the token has no
aud) and the configuredaudiencelist ismatched against the selected claim as a set intersection: any one
configured value present in the token authorizes the request.
Design notes (responding to @sbidoul's #753 comment)
@sbidoul suggested an
expected_claimdict field (parsed withast.literal_evalor json) as an alternative to overloading theaudiencefield. We kept the selection-based approach because:aud/group/scope/custom) cover ~95% ofreal-world IdPs and are discoverable in the form view; a free-form
dict would let users misconfigure in subtle ways.
acceptable values; set-intersection match), so reusing the
audiencefield surface is intuitive.Customaudience_type withaudience_type_customcovers thelong tail of IdPs publishing under vendor-specific claim names
(e.g.
https://example.com/claims/roles).Happy to redesign if reviewers feel strongly — the docs make the
current approach legible enough that the discussion can happen on
substance rather than guesswork.
Note on the audience-optional split
The audience-optional change (#755)
also went stale and is closed. Not refiling here — that's a separate
concern; this PR keeps
audiencerequired across allaudience_typevalues (the list to match is always needed, regardless of which claim
we match against).