How to Check a JWT's Issuer and Audience in Node.js with jose
jose's jwtVerify checks a token's issuer and audience when you pass the issuer and audience options. A token from another issuer, or one made for another API, is rejected with unexpected "iss" claim value or unexpected "aud" claim value.
Syntax
const { payload } = await jwtVerify(<token>, <key>, {
algorithms: ['<alg>'],
issuer: '<expected iss>',
audience: '<expected aud>',
});
| Part | What it does |
|---|---|
<token>, <key> | The JWT to verify and the key that checks its signature. |
algorithms | The signing algorithms you accept. |
issuer | The iss you expect, or an array of several you trust. |
audience | The aud you expect, usually your own API's name, or an array of several. |
payload | The token's claims, returned only when every check passes. |
The jose documentation for JWTVerifyOptions describes issuer as "Expected JWT "iss" (Issuer) Claim value(s). Requires the claim to be present." and audience the same way for aud.
The Example
The example signs one token, issued by https://login.example.org for https://photos.example.org, and verifies it three times: with the right issuer and audience, with the audience of another API, and with another issuer.
Prerequisites
- Node.js. This guide uses Node.js 26.13.1.
Step 1: Create the Project
mkdir demo
cd demo
npm init -y
npm pkg set type=module
npm install jose
npm init -y writes a package.json, npm pkg set type=module lets the code use import, and npm install jose adds the library, version 6.2.18 here.
Step 2: Write the Code
Create main.js:

import { SignJWT, jwtVerify, errors } from 'jose';
// The signing key: 32 random bytes, written as base64.
// It's in the code only for this example; a real app loads it from its configuration.
const key = Uint8Array.fromBase64('C4iNOOORzmu+fnrPK29yq/9n92b/zf5mOs5KvOMaY64=');
const token = await new SignJWT()
.setProtectedHeader({ alg: 'HS256' })
.setIssuer('https://login.example.org')
.setSubject('ada')
.setAudience('https://photos.example.org')
.setExpirationTime('2h')
.sign(key);
async function check(issuer, audience) {
try {
const { payload } = await jwtVerify(token, key, { algorithms: ['HS256'], issuer, audience });
console.log(`accepted: sub ${payload.sub}`);
} catch (err) {
if (!(err instanceof errors.JOSEError)) throw err;
console.log(`rejected: ${err.message}`);
}
}
await check('https://login.example.org', 'https://photos.example.org');
await check('https://login.example.org', 'https://videos.example.org');
await check('https://other.example.org', 'https://photos.example.org');
{ algorithms: ['HS256'], issuer, audience } uses shorthand property names: issuer means issuer: issuer. check catches only jose's own errors, which all extend errors.JOSEError.
Step 3: Run It
node main.js
accepted: sub ada
rejected: unexpected "aud" claim value
rejected: unexpected "iss" claim value

What Happened
- The right issuer and audience passed, and
jwtVerifyreturned the claims. - The videos audience failed. The signature was valid and the issuer was right, but the token wasn't made for
https://videos.example.org. - Another issuer failed in the same way, on
iss.
Both rejections are JWTClaimValidationFailed errors. Without the audience option, jose doesn't look at aud at all, so a token made for any API would pass. That's why an API that shares a sign-in service with other APIs must always pass its own audience.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out audience | jose ignores aud, and a token made for another API passes | Pass your API's own audience |
| Writing the issuer with a slash too many or too few | https://login.example.org/ and https://login.example.org are different issuers | Copy the issuer exactly as the token has it |
Catching every error in check | Real bugs look like rejected tokens | Catch errors.JOSEError and rethrow the rest |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
unexpected "aud" claim value | The token's aud doesn't contain your audience | Check which API the token was made for |
unexpected "iss" claim value | The token comes from an issuer you didn't list | Check the issuer, or add it to an array if you trust it |
missing required "aud" claim | The token has no aud, but you asked for one | Have the sign-in service set an audience |
FAQ
Can I accept several issuers or audiences?
Yes. Pass an array to issuer or audience. For aud, the token is accepted when any of its values is one you listed.
Does jwtVerify check aud when I don't pass audience?
No. It checks the signature and the times, and leaves aud alone.
How do I know which claim failed?
The error message names it, and a JWTClaimValidationFailed error also has a claim property with the claim's name, such as aud.
Conclusion
Pass issuer and audience to jwtVerify, and jose rejects tokens from issuers you don't trust and tokens made for other APIs, each with an error that names the claim.
Additional Resources
- JWTVerifyOptions and jwtVerify, in the jose documentation.
- RFC 8725 section 3.9: Use and Validate Audience.
