Skip to main content

Registered Claims

Every token so far in this course carried a sub and an exp. Those are two of seven claim names the JWT standard sets aside for jobs nearly every application has: saying who made a token, who it's about, who it's for, when it counts and which token it is. This tutorial explains all seven, then builds a sign-in service that sets every one of them and an orders API that checks who made each token and who it's for, in eight languages. All three tokens it makes carry a valid signature, and the orders API still turns two of them away.

The Seven Registered Claims​

A JWT's payload is a JSON object, and each of its members is a claim: a name and a value. You can make up names of your own, which Custom Claims (coming soon) covers. RFC 7519, the JWT standard, registers seven names for jobs nearly every token has, and every JWT library knows them:

ClaimNameWhat it saysExample value
issIssuerWho made the token"https://auth.example.com"
subSubjectWho or what the token is about"user-42"
audAudienceWho the token is for"https://orders.example.com"
expExpiration TimeWhen the token stops counting1796058773
nbfNot BeforeWhen the token starts counting1796057873
iatIssued AtWhen the token was made1796057873
jtiJWT IDThis one token's own ID"881a921a-e755-4e83-9a21-bd7e53ffeee4"

Decoded, the payload of a token with all seven looks like this. It's the token the Node.js program in this tutorial printed:

Payload
{
"iss": "https://auth.example.com",
"sub": "user-42",
"aud": "https://orders.example.com",
"iat": 1796057873,
"nbf": 1796057873,
"exp": 1796058773,
"jti": "881a921a-e755-4e83-9a21-bd7e53ffeee4"
}

The names are only three letters long for a reason the standard gives itself: "All the names are short because a core goal of JWTs is for the representation to be compact." Every byte of a token travels with every request.

Every Registered Claim Is Optional​

RFC 7519 doesn't make any of the seven mandatory. Section 4.1 says: "None of the claims defined below are intended to be mandatory to use or implement in all cases, but rather they provide a starting point for a set of useful, interoperable claims. Applications using JWTs should define which specific claims they use and when they are required or optional."

So the choice is yours: which claims your tokens carry, and which ones your API refuses to do without. Libraries don't make that choice the same way. Given the same token, the eight libraries in this tutorial disagreed about what to check and what to require, as How Each Library Checks iss and aud and Which Claims to Require show.

Two Kinds of Values​

The seven claims hold two kinds of values, which section 2 of RFC 7519 defines:

  • StringOrURI, for iss, sub and aud: any text, except that text with a colon in it must be a URI, such as https://auth.example.com. They "are compared as case-sensitive strings with no transformations or canonicalizations applied". https://auth.example.com/, with a slash at the end, is a different issuer from https://auth.example.com, and the orders API rejected it in all eight languages. The one exception this tutorial found is .NET's audience check, which by default ignores a slash at the end of the audience: its IgnoreTrailingSlashWhenValidatingAudience setting starts out true.
  • NumericDate, for exp, nbf and iat: "the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds", which is Unix time. 1796057873 is 30 November 2026 at 16:57:53 UTC. It counts seconds, not milliseconds, and the difference matters in JavaScript, where Date.now() returns milliseconds.

jti is a plain string, compared exactly like the other three.

Who Made the Token: iss​

iss names the issuer: the service that created and signed the token. Sign-in services use their own address, such as https://auth.example.com. RFC 8725, the JWT best-practice standard, describes OpenID Connect issuers this way: "issuer values are "https" URLs that reference a JSON metadata document that contains a "jwks_uri" value that is an "https" URL from which the issuer's keys are retrieved".

That ties the issuer to its keys, and section 3.8 of RFC 8725 makes it a rule: "When a JWT contains an "iss" (issuer) claim, the application MUST validate that the cryptographic keys used for the cryptographic operations in the JWT belong to the issuer. If they do not, the application MUST reject the JWT."

In this tutorial every service shares one HMAC key, so the key alone can't tell two issuers apart, and the orders API compares iss with the one issuer it trusts. That's also why a shared key is risky: the run shows a token from a staging sign-in service that has the production key by mistake. Later tutorials give each issuer its own key pair, which is how real systems keep issuers apart.

Who the Token Is For: aud​

aud names the audience: the API or APIs the token was made for. Section 4.1.3 of RFC 7519 puts the check on the receiving side: "Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the "aud" claim when this claim is present, then the JWT MUST be rejected."

The value is usually one string, but it can be an array of strings when a token is meant for several APIs. An API accepts a token when its own name is anywhere in the array, and the orders API accepted a two-item aud in all eight languages.

The audience is what stops a token made for one API from working at another. Section 3.9 of RFC 8725 explains it: "If the same issuer can issue JWTs that are intended for use by more than one relying party or application, the JWT MUST contain an "aud" (audience) claim that can be used to determine whether the JWT is being used by an intended party or was substituted by an attacker at an unintended party." The same section says the API "MUST validate the audience value".

Whoever holds a billing token, whether a buggy client, the billing API itself or someone who copied it, could send it to the orders API. Its signature is valid and its issuer is trusted. Only aud says it was never meant for the orders API.

Who the Token Is About: sub​

sub names the subject, usually the user the token speaks for. Section 4.1.2 of RFC 7519 only requires it to be unique within its issuer: "The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique."

So user-42 from one issuer and user-42 from another can be two different people. An API that accepts tokens from more than one issuer keeps each user's record under the pair of iss and sub, never under sub alone, and never under an email address the token happens to carry. RFC 8725 adds that the application "MUST validate that the subject value corresponds to a valid subject and/or issuer-subject pair at the application".

When the Token Counts: exp, nbf and iat​

Three claims hold times, all as NumericDate:

  • exp is "the expiration time on or after which the JWT MUST NOT be accepted for processing".
  • nbf is "the time before which the JWT MUST NOT be accepted for processing". A token can be made now and start counting later.
  • iat is "the time at which the JWT was issued. This claim can be used to determine the age of the JWT."

The standard allows "some small leeway, usually no more than a few minutes, to account for clock skew" between servers. This tutorial sets iat and nbf to the moment the token is made and exp 15 minutes later. Expiry, Not-Before and Clock Skew (coming soon) covers how each library checks the times, how much leeway it allows, and what happens to a token that has no exp at all.

Which Token It Is: jti​

jti gives one token an ID of its own. Section 4.1.7 asks for an ID that is practically never repeated: "The identifier value MUST be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object; if the application uses multiple issuers, collisions MUST be prevented among values produced by different issuers as well."

A random UUID does that. A version 4 UUID has 122 random bits, and seven of the eight languages make one with a single call. PHP has no UUID function, so the PHP program uses 16 random bytes written as hexadecimal, which has 128.

The standard adds that "The "jti" claim can be used to prevent the JWT from being replayed." That takes a list of the IDs already used, kept until their tokens expire, so a token presented a second time can be refused. A library can't keep that list for you, because it has to last between requests. Refresh Token Rotation and Reuse Detection (coming soon) and Revoke Tokens and Log Out (coming soon) use jti that way.

The Example​

The program plays every part at once:

  • The sign-in service, https://auth.example.com, makes tokens for Zara, whose user ID is user-42. Each token carries all seven claims: its issuer, sub, an audience, iat and nbf set to now, exp 15 minutes later, and a fresh random jti.
  • The orders API, https://orders.example.com, checks each token's signature, algorithm and times, as in Create and Verify a JWT in Code, and now also checks that iss is its own sign-in service and that aud names the orders API.

The sign-in service makes three tokens and hands each to the orders API:

  • The orders token, for the orders API. It should be accepted.
  • The billing token, made by the same sign-in service with the same key, but for https://billing.example.com.
  • The staging token, for the orders API, but made by https://auth.staging.example.com, a test copy of the sign-in service that was given the production key by mistake.

The program prints the orders token, the seven claims the orders API accepted, and why it rejected the other two.

Prerequisites​

  • The tools for your language. Pick its tab and check them. These are the versions this tutorial was run with:

Node.js 26, which comes with npm:

Terminal
node --version
npm --version
Output
v26.13.1
12.2.3

Step 1: Create a Project and Add the JWT Library​

Each project lives in its own folder. Where a tab starts with mkdir registered-claims and cd registered-claims, those two commands create the folder and move into it. The other tools create the folder themselves. The commands are the same in every terminal, including PowerShell.

Terminal
mkdir registered-claims
cd registered-claims
npm init -y
npm pkg set type=module
npm install jose
  • npm init -y creates a package.json, the file that describes a Node.js project, without asking any questions.
  • npm pkg set type=module makes the project use ES modules, so the code can load jose with import. npm 12 writes "type": "commonjs" into a new package.json, as the output shows.
  • npm install jose downloads jose into a node_modules folder and adds it to package.json.
Output
Wrote to /Users/Shared/you/registered-claims/package.json:
{
"name": "registered-claims",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"type": "commonjs"
}
added 1 package, and audited 2 packages in 903ms
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities

package.json now says the project is a module and depends on jose:

package.json
{
"name": "registered-claims",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"type": "module",
"dependencies": {
"jose": "^6.2.18"
}
}

Step 2: Give the Program a Secret​

Every service in this example uses the same secret: 32 random bytes, the size RFC 7518 requires for HS256. The program reads it from an environment variable named JWT_SECRET, so the secret never sits in the code. How to Generate a Secret Key for HS256 JWTs in the Terminal explains the command, and How to Set an Environment Variable in the Terminal explains the variable.

Terminal
export JWT_SECRET=$(openssl rand -base64 32)
echo ${#JWT_SECRET}
Output
44

A zsh terminal where export JWT_SECRET stores the output of openssl rand -base64 32 and echo with a hash sign prints its length, 44 characters.

JWT_SECRET now holds the 32 bytes as 44 characters of base64 text, and the program decodes that text back into the 32 bytes it uses as the key. The length check confirms the variable is set without printing the secret on your screen. The variable lasts until you close this terminal, so run the program from the same window.

Step 3: Write the Code That Creates a Token with All Seven Claims​

Create the program's file: main.js, main.py, Program.cs, src/main/java/com/example/Main.java, main.go, main.php, main.rb or src/main.rs, depending on your language. Most editors create the folders in the path for you. In Python, C# and Rust, replace what the template put in the file. The code goes in over the next three steps, and the complete file shows it all together.

The file starts with the two values the orders API trusts: its own sign-in service, ISSUER, and its own address, ORDERS_API. Then comes the sign-in service's function. It takes the key, an issuer, an audience and a user ID, and returns a token with all seven claims. The comment next to each claim says which job it does.

main.js
import { SignJWT, jwtVerify, errors } from 'jose';

const ISSUER = 'https://auth.example.com';
const ORDERS_API = 'https://orders.example.com';

// The sign-in service's job: a token with all seven registered claims.
async function createToken(key, issuer, audience, userId) {
const now = Math.floor(Date.now() / 1000);
return new SignJWT()
.setProtectedHeader({ alg: 'HS256', typ: 'JWT' })
.setIssuer(issuer) // iss: who made the token
.setSubject(userId) // sub: who the token is about
.setAudience(audience) // aud: who the token is for
.setIssuedAt(now) // iat: when it was made
.setNotBefore(now) // nbf: the time it starts to count
.setExpirationTime(now + 15 * 60) // exp: the time it stops counting
.setJti(crypto.randomUUID()) // jti: this token's own ID
.sign(key);
}
  • const declares the two constants.
  • Math.floor(Date.now() / 1000) is the current time in seconds: Date.now() counts milliseconds, and a JWT counts seconds.
  • Each set method writes one claim. Given a number, jose writes it as it is, so setIssuedAt(now), setNotBefore(now) and setExpirationTime(now + 15 * 60) put the same second in iat and nbf and a time 900 seconds later in exp.
  • crypto.randomUUID() returns a random UUID. crypto is built into Node.js, so it needs no import.

Step 4: Check the Issuer and the Audience​

Next, the orders API. It verifies a token as the earlier tutorials did: the signature with the shared key, only HS256, and the times. On top of that, it now checks that iss is ISSUER and that aud names ORDERS_API, and it rejects a token that leaves either claim out. Each library does that its own way:

main.js
// The orders API's check: the signature and the times, then the issuer and audience.
async function verifyForOrders(key, token) {
const { payload } = await jwtVerify(token, key, {
algorithms: ['HS256'],
issuer: ISSUER,
audience: ORDERS_API,
});
return payload;
}
  • The issuer and audience options of jwtVerify turn on both checks. jose rejects a token whose iss isn't ISSUER, whose aud doesn't name ORDERS_API, or that leaves out either claim.
  • Without the audience option, jose doesn't look at aud at all.

Step 5: Print the Claims and Put It Together​

The last piece prints the seven claims of an accepted token, reports what the orders API made of each token, and makes the three tokens:

main.js
// Print each registered claim of a verified token.
function showClaims(claims) {
console.log(` iss: ${claims.iss}`);
console.log(` sub: ${claims.sub}`);
console.log(` aud: ${claims.aud}`);
console.log(` iat: ${claims.iat}`);
console.log(` nbf: ${claims.nbf}`);
console.log(` exp: ${claims.exp}`);
console.log(` jti: ${claims.jti}`);
}

// Show what the orders API makes of one token.
async function report(key, label, token) {
try {
const claims = await verifyForOrders(key, token);
console.log(`${label} accepted:`);
showClaims(claims);
} catch (err) {
if (!(err instanceof errors.JOSEError)) throw err;
console.log(`${label} rejected: ${err.message}`);
}
}

// The key every service shares: 32 random bytes, kept as base64 text in JWT_SECRET.
const secret = process.env.JWT_SECRET;
if (!secret) {
console.error('Set the JWT_SECRET environment variable first.');
process.exit(1);
}
const key = Uint8Array.fromBase64(secret);

const orders = await createToken(key, ISSUER, ORDERS_API, 'user-42');
const billing = await createToken(key, ISSUER, 'https://billing.example.com', 'user-42');
const staging = await createToken(key, 'https://auth.staging.example.com', ORDERS_API, 'user-42');
console.log(`Orders token: ${orders}`);

await report(key, 'Orders token', orders);
await report(key, 'Billing token', billing);
await report(key, 'Staging token', staging);
  • report catches jose's errors, which all extend JOSEError, and prints their message.
  • The billing token has the right issuer and the billing API's audience. The staging token has the orders API's audience and the staging issuer.

Step 6: Run the Program​

Run the program in the terminal where you set JWT_SECRET:

Terminal
node main.js
Output
Orders token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGguZXhhbXBsZS5jb20iLCJzdWIiOiJ1c2VyLTQyIiwiYXVkIjoiaHR0cHM6Ly9vcmRlcnMuZXhhbXBsZS5jb20iLCJpYXQiOjE3OTYwNTc4NzMsIm5iZiI6MTc5NjA1Nzg3MywiZXhwIjoxNzk2MDU4NzczLCJqdGkiOiI4ODFhOTIxYS1lNzU1LTRlODMtOWEyMS1iZDdlNTNmZmVlZTQifQ.2uCz8jYl1GurfHEAWa15ikX2nCpvo7U8J6fchkQ7ifg
Orders token accepted:
iss: https://auth.example.com
sub: user-42
aud: https://orders.example.com
iat: 1796057873
nbf: 1796057873
exp: 1796058773
jti: 881a921a-e755-4e83-9a21-bd7e53ffeee4
Billing token rejected: unexpected "aud" claim value
Staging token rejected: unexpected "iss" claim value

A zsh terminal where node main.js prints the orders token and its seven claims, iss, sub, aud, iat, nbf, exp and jti, then rejects the billing token with unexpected aud claim value and the staging token with unexpected iss claim value.

Your token, times and IDs will differ, because the program makes new ones on every run. The rest of the output should match.

The Complete File​

main.js
import { SignJWT, jwtVerify, errors } from 'jose';

const ISSUER = 'https://auth.example.com';
const ORDERS_API = 'https://orders.example.com';

// The sign-in service's job: a token with all seven registered claims.
async function createToken(key, issuer, audience, userId) {
const now = Math.floor(Date.now() / 1000);
return new SignJWT()
.setProtectedHeader({ alg: 'HS256', typ: 'JWT' })
.setIssuer(issuer) // iss: who made the token
.setSubject(userId) // sub: who the token is about
.setAudience(audience) // aud: who the token is for
.setIssuedAt(now) // iat: when it was made
.setNotBefore(now) // nbf: the time it starts to count
.setExpirationTime(now + 15 * 60) // exp: the time it stops counting
.setJti(crypto.randomUUID()) // jti: this token's own ID
.sign(key);
}

// The orders API's check: the signature and the times, then the issuer and audience.
async function verifyForOrders(key, token) {
const { payload } = await jwtVerify(token, key, {
algorithms: ['HS256'],
issuer: ISSUER,
audience: ORDERS_API,
});
return payload;
}

// Print each registered claim of a verified token.
function showClaims(claims) {
console.log(` iss: ${claims.iss}`);
console.log(` sub: ${claims.sub}`);
console.log(` aud: ${claims.aud}`);
console.log(` iat: ${claims.iat}`);
console.log(` nbf: ${claims.nbf}`);
console.log(` exp: ${claims.exp}`);
console.log(` jti: ${claims.jti}`);
}

// Show what the orders API makes of one token.
async function report(key, label, token) {
try {
const claims = await verifyForOrders(key, token);
console.log(`${label} accepted:`);
showClaims(claims);
} catch (err) {
if (!(err instanceof errors.JOSEError)) throw err;
console.log(`${label} rejected: ${err.message}`);
}
}

// The key every service shares: 32 random bytes, kept as base64 text in JWT_SECRET.
const secret = process.env.JWT_SECRET;
if (!secret) {
console.error('Set the JWT_SECRET environment variable first.');
process.exit(1);
}
const key = Uint8Array.fromBase64(secret);

const orders = await createToken(key, ISSUER, ORDERS_API, 'user-42');
const billing = await createToken(key, ISSUER, 'https://billing.example.com', 'user-42');
const staging = await createToken(key, 'https://auth.staging.example.com', ORDERS_API, 'user-42');
console.log(`Orders token: ${orders}`);

await report(key, 'Orders token', orders);
await report(key, 'Billing token', billing);
await report(key, 'Staging token', staging);

The complete main.js: the ISSUER and ORDERS_API constants, createToken setting all seven claims with SignJWT, verifyForOrders checking the issuer and audience with jwtVerify, showClaims, report, and the code that makes and reports on three tokens.

What the Run Shows​

  • The orders token passed every check, and its seven claims came back exactly as the sign-in service wrote them: iat and nbf are the same second, exp is 900 seconds later, and jti is a new random ID.
  • The billing token had a valid signature. It came from the right issuer, signed with the right key. Only the audience check stopped it, which is the substitution RFC 8725 warns about.
  • The staging token had a valid signature too, because the staging service had the production key. Only the issuer check stopped it. Checking iss caught the mistake, and giving each issuer its own key would have made it impossible.
  • The libraries don't write aud the same way. jjwt and golang-jwt write it as an array even when there's one audience, which is why the Java program printed it in brackets. The other six write the string they're given.
  • .NET put the claims in another order, with aud first, as decoding its token shows. Order doesn't matter in JSON, and every library reads the claims by name.

How Each Library Checks iss and aud​

Every library could check both claims, but they don't agree on what happens when you leave something out. This table comes from running each library against extra tokens made for the purpose:

LanguageLibraryCheck the issuer and audience withA token without iss or audA token with aud when you set no audience
Node.jsjoseissuer and audience options of jwtVerifyRejected: missing required "aud" claimAccepted: aud is ignored
PythonPyJWTissuer= and audience=Rejected: Token is missing the "aud" claimRejected: Invalid audience
C#JsonWebTokenHandlerValidIssuer and ValidAudience, checked by defaultRejected: IDX10211 for the issuer, IDX10206 for the audienceRejected: IDX10208, for every token
JavajjwtrequireIssuer and requireAudienceRejected: Missing 'aud' claimAccepted: aud is ignored
Gogolang-jwtjwt.WithIssuer and jwt.WithAudienceRejected: aud claim is requiredAccepted: aud is ignored
PHPphp-jwtNothing: your code compares the claimsWhatever your code doesAccepted: aud is ignored
Rubyjwtiss: and aud:, with verify_iss: true and verify_aud: trueRejected: received <none>Accepted: aud is ignored
Rustjsonwebtokenset_issuer and set_audienceAccepted, unless the claims are in set_required_spec_claimsRejected: InvalidAudience

Two columns deserve a second look. In Rust, setting an issuer and an audience still lets through a token that has neither claim, which is why Step 4 lists them as required. And in Python, Rust and C#, a token with an aud fails until you say which audience you are, while the other five libraries ignore aud unless you ask. An API built on one of those five can forget the audience check and never notice.

Which Claims to Require​

Require every claim your API relies on, so a token without it is turned away instead of slipping past a check that only runs when the claim is there. For the orders API, that's iss and aud, which Step 4 requires, exp, so no token lasts forever, and sub, if the API looks the user up by it.

Libraries let you require a claim in different ways, and some not at all:

LanguageLibraryMake a claim requiredA token without exp, by default
Node.jsjoserequiredClaims: ['exp', 'sub']Accepted
PythonPyJWToptions={"require": ["exp", "sub"]}Accepted
C#JsonWebTokenHandlerRequireExpirationTime for exp and RequireAudience for aud, both on by default; other claims in your own codeRejected: IDX10225
JavajjwtOnly by expected value, with the require methods; check others in your own codeAccepted
Gogolang-jwtjwt.WithExpirationRequired() and jwt.WithNotBeforeRequired(); others by expected valueAccepted
PHPphp-jwtNothing: check in your own codeAccepted
Rubyjwtrequired_claims: ['exp', 'sub']Accepted
Rustjsonwebtokenset_required_spec_claims(&["exp", "sub"]), for exp, nbf, iss, aud and subRejected: Missing required claim: exp

Six of the eight libraries accepted a token with no exp under the same checks as this tutorial's orders API. Every token the sign-in service makes has one, so the run never shows it. Expiry, Not-Before and Clock Skew (coming soon) makes the orders API require exp in all eight languages.

What You Can Do Now​

  • Explain all seven registered claims, what kind of value each one holds and which party checks it.
  • Set all seven when you create a token, in any of the eight languages.
  • Check a token's issuer and audience, and know which libraries ignore aud unless you ask and which reject it.
  • Choose which claims your API requires, and make your library require them.

Common Mistakes​

MistakeWhat happensDo this instead
Not checking aud when one sign-in service serves several APIsA token for one API works at all of them, as the billing token would haveGive each API its own audience and check it on every request
Comparing the issuer loosely, or with a slash too manyhttps://auth.example.com/ and https://auth.example.com are different issuersCopy the issuer exactly as the sign-in service writes it
Writing exp, nbf or iat in millisecondsThe token seems to expire tens of thousands of years from nowDivide JavaScript's Date.now() by 1000 and round down
Ruby: passing iss: and aud: without verify_iss: true and verify_aud: trueruby-jwt checks neither, and accepted a staging token for the billing APIAdd both verify_ options
Rust: set_issuer and set_audience without set_required_spec_claimsA token with no iss or aud is acceptedList both claims as required
PHP: expecting php-jwt to check iss or audIt doesn't, so every issuer and audience passesCompare both yourself after JWT::decode, as Step 4 does
Sharing one key between issuers or environmentsA staging token passes in production unless iss is checkedGive each issuer its own key, and check iss as well
Keeping a user's record under sub aloneTwo issuers can each have a user-42, and they're different peopleKey users by iss and sub together
Declaring aud as a single string in a Rust struct when tokens come from jjwt or golang-jwtThey write aud as an array, and decoding failsDeclare aud as Vec<String>

Troubleshooting​

SymptomLikely causeFix
Set the JWT_SECRET environment variable first.Step 2 ran in another terminal, or not at allRun Step 2 again in the terminal where you run the program
Python: jwt.exceptions.InvalidAudienceError: Invalid audience though you didn't ask for an audience checkThe token has an aud, and PyJWT rejects it unless you pass audiencePass your API's audience to jwt.decode
C#: IDX10208: Unable to validate audience. validationParameters.ValidAudience is null or whitespace and validationParameters.ValidAudiences is null.IdentityModel checks the audience by default, and there's nothing to compare withSet ValidAudience
C#: IDX10214: Audience validation failed. See https://aka.ms/identitymodel/app-context-switchesThe token's aud isn't the ValidAudience. Since IdentityModel 8.8.0, this message leaves out the values, so it doesn't say whichDecode the token and compare its aud with ValidAudience
C#: IDX10205: Issuer validation failed.The token's iss isn't the ValidIssuer. The message shows both valuesUse the issuer exactly as the token has it
Node.js: unexpected "aud" claim valueThe token's aud doesn't name the audience you passedCheck which API the sign-in service made the token for
Rust: JSON error: invalid type: sequence, expected a stringThe token's aud is an array, and the Claims struct says StringDeclare aud as Vec<String>, or have the sign-in service write one string
Rust: InvalidAudience though the audience looks rightset_audience was never called, and jsonwebtoken checks the audience by defaultCall set_audience with your API's audience

Frequently Asked Questions​

Does a JWT have to contain the registered claims?​

No. RFC 7519 makes every one of them optional and leaves it to each application to decide which ones it uses and requires. In practice, almost every access token carries iss, sub, aud and exp, and an API should require the ones it relies on.

Can aud have more than one value?​

Yes. aud can be an array of strings, and an API accepts the token if its own name is one of them. The orders API accepted a token whose aud named both the orders API and the billing API, in all eight languages. golang-jwt also has jwt.WithAllAudiences, which requires every value you list.

What's the difference between iss and aud?​

iss says who made the token and aud says who it's for. An API checks that it trusts the first and that it is the second.

Does every library check sub and jti?​

Most can compare sub with a value you expect, but an API rarely knows in advance which user to expect, so it reads sub instead of checking it. No library remembers which jti values it has seen, because that needs a list that lasts between requests.

Should iss be a URL?​

It can be any string, and a value with a colon in it must be a URI. Sign-in services that follow OpenID Connect use an https URL, because the issuer's keys are found from it.

Why do iat and nbf have the same value here?​

Because the sign-in service sets both to the moment it makes the token. nbf can be later than iat for a token that should only start counting in the future, and it can be left out.

Conclusion​

The seven registered claims answer the questions every API asks about a token: who made it, who it's about, who it's for, when it counts and which one it is. A valid signature answers none of them, as the billing and staging tokens showed: both were signed correctly with the right key, and only aud and iss kept them out. Set the claims when you create a token, and check and require the ones your API relies on when you verify it.

Next: Custom Claims (coming soon). How to add claims of your own, such as a role, without colliding with anyone else's names.

Additional Resources​