This project demonstrates how to implement client credentials grant flow in Node.js using client assertion, public-private key pair and a JWKS endpoint in a microservices setup. Full article explaining the project can be found on my blog.
The project includes four Dockerized components:
- Bootstrapper - Generates RSA key pair and JWKS from the public key.
- Auth Server - Signs JWTs and exposes the JWKS (
/.well-known/jwks.json) endpoint. - API Server - Verifies JWTs against the Auth server’s JWKS.
- Client - Fetches a JWT and accesses the protected route.
node-jwks-demo/
├── bootstrapper/
├── auth/
├── api/
├── client/
├── docker-compose.yml
- Docker
- Docker Compose
Generate keys
docker-compose --profile bootstrap up --build --force-recreateStart the stack
docker-compose --profile stack up --build --force-recreateThis will:
- Generate keys and JWKS via the bootstrapper.
- Start the Auth server on
http://localhost:3001 - Start the API server on
http://localhost:3002 - Run the client to request a token and access the API
API Response: { message: 'Protected resource accessed' }- JWTs are signed using the RSA private key.
- The public key is shared via JWKS so that services can validate tokens securely.
- Uses the
joselibrary for signing/verifying.
Enhance this setup by adding:
- Token scopes and user roles
- Refresh tokens
- HTTPS with TLS certificates
- Rate limiting and logging
MIT