-
-
Notifications
You must be signed in to change notification settings - Fork 747
JWT API: Offer a "strict audience" mode? #894
Description
Hello again!
I'm raising this as a potential feature request for the current jwt.decode API.
Current behavior
The current audience is an Optional[Union[str, Iterable[str]]]. If a single audience value is passed verify_aud=True is passed, then the underlying API does the following:
- If the JWT's
audis astr, create a working audience list of[aud] - If the JWT's
audis aList[str], use it as the working audience list - Check if the passed in
audienceis included in the audience list
This is the right behavior in some JWT applications, but not in all. In particular, some JWT users may prefer to have "strict" audience checking, where passing in a single str means that the aud claim must also be a single str that exactly matches.
Proposed behavior
I propose the addition of an "strict_aud" (or "exact_aud") option in the options kwarg that gets passed into jwt.decode. When present and set to True, this should change the behavior as stated above: rather than constructing an internal audience list, it should enforce that the aud claim is only a single str that exactly matches the provided audience.
See pypi/warehouse#13887 for some justification for this new behavior.
If you're interested in this, let me know and I'd be happy to implement it!