In a JSON Web Token (JWT), sub (subject) identifies who or what the token is about (usually a user), while aud (audience) specifies the intended recipient service or API that should accept the token. [1, 2]
sub (Subject)- Meaning: Identifies the principal or entity the token represents, such as a user ID, device, or service account.
- Uniqueness: It is typically unique within the context of its issuer (
iss), so combining(iss, sub)avoids collisions across identity providers.
aud (Audience)- Meaning: Identifies the intended consumer(s) of the JWT, such as a specific API or resource server. It can be a single string or an array of strings. [1, 2]
- Security role: Receiving services check
audagainst their own identifier and reject tokens that do not match, preventing a token meant for one API from being replayed against another. [1, 2] - Related terms / synonyms: Intended recipient, target audience, resource identifier, consumer.
Example Payload
json
{
"iss": "https://auth.example.com",
"sub": "user_98765",
"aud": ["https://api.example.com", "https://billing.example.com"],
"exp": 1796134800
}
Use code with caution.