Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Microsoft Graph rejects an access token with an invalid audience

ErrorAccess token validation failure. Invalid audience.

Short answer

Every access token is issued for one audience, shown in its aud claim. Graph accepts only tokens whose audience is Graph, and your API accepts only tokens meant for it. Decode the token to read aud, then request the token with the scope of the API you are calling. A middle-tier API exchanges its token with the on-behalf-of flow.

  • Applies to Microsoft Entra ID, Microsoft Graph v1.0, OAuth 2.0 v2.0 endpoint
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Decode the token you send and read the aud claim. It must name the API that receives the call. For debugging only, paste a token for your own tenant into the Microsoft decoder.

    # open https://jwt.ms and paste the access token
  2. 2Match what you see, then jump to its fix

    1. 1aud shows your app's client ID or api:// URI, and the call goes to graph.microsoft.comThe token was requested for your own API but is sent to GraphFix
    2. 2The error comes from your own validation code and aud holds Microsoft GraphYour API received a token meant for Graph, or for another APIFix
    3. 3Graph rejects the call and the forwarded token has your API as audYour API forwards the caller's token to Graph instead of exchanging itFix
    4. 4The token is for your API but validation still says invalid audienceYour API checks aud in a different format than the token usesFix

What does the error look like?

  • Access token validation failure. Invalid audience.

Cause 1 of 4

The token was requested for your own API but is sent to Graph

1Check

The scope in the token request sets the audience. A scope like api://<your-api>/access_as_user gives a token for your API, not for Graph.

# jwt.ms: compare aud with the host you call

2Fix

Ask for a token with a Graph scope. If the resource part of the scope is left out, Microsoft Graph is assumed. You can also use the .default scope with the Graph identifier.

scope=https://graph.microsoft.com/User.Read
scope=https://graph.microsoft.com/.default

3Verify

Decode the new token and check aud, then call Graph.

curl -H "Authorization: Bearer $TOKEN" https://graph.microsoft.com/v1.0/me

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

Your API received a token meant for Graph, or for another API

1Check

A web API must accept only tokens whose aud is its own identifier. Accepting a token meant for another resource is the confused deputy problem, and Graph tokens cannot be validated like normal JWTs.

# compare aud in the failing token with your API's Application ID URI

2Fix

Have the client request a token for your API's scope, and keep audience validation on. Do not accept or parse tokens issued for APIs you do not own.

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

3Verify

The client's new token has your API as aud and passes validation.

# jwt.ms: aud equals your Application ID URI or client ID

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

Your API forwards the caller's token to Graph instead of exchanging it

1Check

A token for your API cannot be redeemed for another app by forwarding it. The middle tier must use the on-behalf-of flow, with the incoming token as the assertion, and ask for Graph scopes.

# inspect the Authorization header your API sends to Graph

2Fix

Send an on-behalf-of request to the token endpoint, then call Graph with the new token. Prefer MSAL, which does this for you.

POST https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
client_id=<api-client-id>
client_secret=<api-secret>
assertion=<token received by your API>
scope=https://graph.microsoft.com/user.read
requested_token_use=on_behalf_of

3Verify

Call Graph with the token from the response.

curl -H "Authorization: Bearer $NEW_TOKEN" https://graph.microsoft.com/v1.0/me

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 4

Your API checks aud in a different format than the token uses

1Check

In v1 access tokens aud can be an App ID URI, with or without a trailing slash, or the client ID. In v2 tokens it is the client ID. The version comes from requestedAccessTokenVersion in the API's manifest.

# Entra admin center > App registrations > your API > Manifest > requestedAccessTokenVersion

2Fix

Accept the exact aud values your API can receive, or set requestedAccessTokenVersion to 2 so aud is always the client ID.

"requestedAccessTokenVersion": 2

3Verify

Request a new token and decode it; aud is the client ID.

# jwt.ms

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Write the audience each client must request next to the API in your documentation.
  • Keep audience validation on in every API; never disable it to make an error go away.
  • Use MSAL for token requests and the on-behalf-of exchange instead of hand-built requests.

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.

Related fixes

Next step

Want this handled for good?

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