How jwks-rsa.koaJwtSecret works with koa-jwt
masterThe integration between koa-jwt and jwks-rsa follows this lifecycle during a request:
- Token Decoding:
koa-jwtdecodes the incoming JWT and passes the request and the decoded token tojwksRsa.koaJwtSecret. - Key Retrieval:
jwks-rsadownloads the signing keys from the configuredjwksUriand searches for a key where thekidmatches thekidin the JWT header.- If no match is found: An error is thrown.
- If a match is found: The specific signing key is passed back to
koa-jwt.
- Validation:
koa-jwtuses the provided key to validate the token's signature, expiration (exp), audience (aud), and issuer (iss).
Key Features:
- Caching: When
cache: trueis set, subsequent requests will use the cached keys instead of hitting the JWKS endpoint again. - Rate Limiting: When
rateLimit: trueis set, the library limits the frequency of requests to the JWKS endpoint to protect your authorization server.