Skip to content

JWT API: Offer a "strict audience" mode? #894

@woodruffw

Description

@woodruffw

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:

  1. If the JWT's aud is a str, create a working audience list of [aud]
  2. If the JWT's aud is a List[str], use it as the working audience list
  3. Check if the passed in audience is 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions