Skip to content
ecdsa.com
PyJWT (Python)JWT libraries

Error message

Invalid audience

Also printed as

  • jwt.exceptions.InvalidAudienceError: Invalid audience

Compare with "Audience doesn't match", which means you did pass `audience` but no value overlapped.

PyJWT (Python) — jwt.exceptions.InvalidAudienceError

What it means

The token contains an `aud` claim, but `jwt.decode()` was called without an `audience` argument. PyJWT does not ignore an audience it cannot check: a token that names its recipient is rejected unless you say which recipient you are. The same message appears if `aud` has an invalid type (neither a string nor a list of strings).

Why it happens

How to fix it

  1. 1.

    Tell PyJWT which audience you are

    Pass your API's identifier (or a list of acceptable identifiers). Do not switch off `verify_aud` — the check is what prevents tokens for other services from being accepted.

    python
    claims = jwt.decode(
        token,
        signing_key,
        algorithms=["ES256"],
        audience="https://api.example.com",  # the identifier your API is registered with
    )
  2. 2.

    Use unverified decoding only to inspect

    `verify_signature: False` turns off every check, including audience. It is useful to read `aud` while debugging, never to authorize a request.

    python
    # Reading claims without trusting them (debugging, routing) - never for authorization.
    header = jwt.get_unverified_header(token)
    claims = jwt.decode(token, options={"verify_signature": False})

Related errors

Browse the full signature error database