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

Error message

Audience doesn't match

Also printed as

  • jwt.exceptions.InvalidAudienceError: Audience doesn't match

PyJWT (Python) — jwt.exceptions.InvalidAudienceError

What it means

The token has an `aud` claim and you passed `audience=` to `jwt.decode()`, but no value overlaps. PyJWT accepts the token when at least one of the token's audiences equals one of the audiences you allow; here none did. The signature was valid — the token was issued for a different recipient.

Why it happens

How to fix it

  1. 1.

    Compare the token's aud with your audience

    Decode without verification only to inspect, then verify with the exact identifier. Change the client's token request if the token was issued for the wrong audience; change the verifier if the identifier was misspelled.

    python
    unverified = jwt.decode(token, options={"verify_signature": False})
    print(repr(unverified.get("aud")))  # str or list[str]
    
    claims = jwt.decode(
        token,
        signing_key,
        algorithms=["ES256"],
        audience="https://api.example.com/orders",  # must equal one of the token's aud values
        issuer="https://issuer.example.com/",
    )
  2. 2.

    Allow multiple identifiers explicitly

    `audience` accepts a list. Use it when one API legitimately has several identifiers; never pass `options={"verify_aud": False}` to make the error disappear.

    python
    # Any one of these may appear in the token's aud.
    claims = jwt.decode(token, signing_key, algorithms=["ES256"], audience=["orders-api", "https://api.example.com/orders"])

Related errors

Browse the full signature error database