Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

A Microsoft Entra access token shows Invalid Signature when you check it yourself

ErrorInvalid Signature

Short answer

A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected. If the token is for your own API, the usual error is using the wrong key set: the keys must come from the metadata for the token's version, selected by its kid.

  • Applies to Microsoft Entra ID, Spring Boot 3, jwt.io
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Decode the token header and payload and read aud, ver and kid. They decide which cause applies.

    echo "$ACCESS_TOKEN" | cut -d. -f1,2 | tr '.' '\n' | tr '_-' '/+' | while read p; do echo "$p==" | base64 -d 2>/dev/null; echo; done
  2. 2Match what you see, then jump to its fix

    1. 1aud is Microsoft Graph, usually after requesting the User.Read scopeThe token was issued for Microsoft Graph, not for your APIFix
    2. 2aud is your API, but the signature check still failsThe keys were fetched from the wrong metadata documentFix

What does the error look like?

  • Invalid Signature
  • Tokens that a Microsoft API receives might not always be a JWT that can be decoded

Cause 1 of 2

The token was issued for Microsoft Graph, not for your API

1Check

Read the aud claim. Tokens for Microsoft-owned APIs follow their own proprietary format, and the docs say you cannot validate Graph tokens by the normal rules. Validating a token meant for another resource also leads to the confused deputy problem.

echo "$ACCESS_TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | grep -o '"aud":"[^"]*"'

2Fix

Register your own API in Entra, expose a scope, and have the client request that scope. The token then carries your API as aud, and your API can validate it.

scope=api://<your-api-client-id>/access_as_user

3Verify

Decode the new token: aud now shows your API, and its signature validates against your tenant's keys.

echo "$ACCESS_TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | grep -o '"aud":"[^"]*"'

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 2

The keys were fetched from the wrong metadata document

1Check

A v1.0 token (ver 1.0) must be checked against the v1.0 metadata document, and a v2.0 token against the v2.0 one, whatever authority your API is configured with. Keys are rotated, so pick the key whose kid matches the token header, and use the application-specific keys URL if custom signing keys are in use.

curl -s https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration | grep jwks_uri

2Fix

Point your validator at the metadata endpoint that matches the token version and let the library refresh keys; do not paste one certificate into the config.

# v2.0 tokens
https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration
# v1.0 tokens: remove /v2.0
https://login.microsoftonline.com/<tenant-id>/.well-known/openid-configuration

3Verify

Fetch the jwks_uri from that document and check that a key with the token's kid is listed.

curl -s <jwks_uri> | grep <kid>

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Let a library such as Microsoft.Identity.Web or your framework's resource server validate tokens; do not hand-roll signature checks.
  • Only validate tokens whose aud is your own API.
  • Never debug production tokens on a public website; use a local decoder.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.