A simple Node.js utility to validate Microsoft access tokens using JWKS (JSON Web Key Set).
-
Clone this repository
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory (cp .env.example .env):TENANT_ID=your-tenant-id-here APPLICATION_ID=api://your-application-id-hereReplace the values with:
TENANT_ID: Your Azure AD tenant IDAPPLICATION_ID: Your application's client ID/audience (with theapi://prefix)
Run the validator with your access token:
node index.js <your-access-token>This script performs the following steps to validate Microsoft access tokens:
- Loads environment variables for your tenant ID and application ID
- Fetches the JWKS (JSON Web Key Set) from Microsoft's OpenID Connect metadata endpoint
- Decodes the provided access token to extract the key ID (kid) and token payload
- Retrieves the corresponding public key from the JWKS endpoint
- Validates the token's:
- Signature using the public key
- Audience claim matches your APPLICATION_ID
- Issuer claim matches Microsoft's token issuer
- Token format and algorithms
The script outputs:
- The decoded token header and payload for inspection
- Validation result (✅ valid or ❌ invalid)
- Full validated payload or error message if validation fails
This validation ensures the token:
- Was issued by Microsoft
- Hasn't been tampered with
- Is intended for your application
- Contains valid claims and signatures