Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Entra ID token request fails: the request body must contain the parameter 'grant_type'

ErrorAADSTS90014: The request body must contain the following parameter: 'grant_type'.

Short answer

The token endpoint did not find grant_type in the form body of your POST. Send application/x-www-form-urlencoded data in the body, not JSON and not the query string. For client credentials the body needs client_id, client_secret, scope ending in /.default, and grant_type=client_credentials.

  • Applies to Microsoft identity platform v2.0 token endpoint, curl 8.x, Postman, Node.js 22 fetch
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Send the request with curl and form fields. If it works, the fault is in how your client builds the body.

    curl -s -X POST "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token" \
      -H "Content-Type: application/x-www-form-urlencoded" \
      --data-urlencode "client_id=<application-id>" \
      --data-urlencode "client_secret=<secret>" \
      --data-urlencode "scope=https://graph.microsoft.com/.default" \
      --data-urlencode "grant_type=client_credentials"
  2. 2Match what you see, then jump to its fix

    1. 1The request has Content-Type: application/json, or the fields appear after a ? in the URL, and the body is emptyThe body is JSON or the parameters are in the URLFix
    2. 2The body is form-encoded, but the message names a parameter such as grant_type, and your code does not set it or sets it under another namegrant_type or another required field is missing or misspelledFix
    3. 3The URL is a /authorize URL, a tenant that does not exist, or a path other than /oauth2/v2.0/tokenThe request goes to the wrong URL, so the endpoint does not read your body as a token requestFix

What does the error look like?

  • AADSTS90014: The request body must contain the following parameter: 'grant_type'.
  • AADSTS900144: The request body must contain the following parameter: 'grant_type'.

Cause 1 of 3

The body is JSON or the parameters are in the URL

1Check

Microsoft documents the token request as a POST with Content-Type application/x-www-form-urlencoded and the parameters in the body. Anything else leaves the body without grant_type.

# Look at the raw request in your HTTP client's log or a proxy: header Content-Type and the body

2Fix

Build the body with a form encoder. In Node.js use URLSearchParams, which fetch sends as form data.

const body = new URLSearchParams({
  client_id: process.env.CLIENT_ID,
  client_secret: process.env.CLIENT_SECRET,
  scope: "https://graph.microsoft.com/.default",
  grant_type: "client_credentials",
});
const res = await fetch(`https://login.microsoftonline.com/${process.env.TENANT_ID}/oauth2/v2.0/token`, {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body,
});

3Verify

The response is 200 with access_token, token_type Bearer and expires_in.

# console.log((await res.json()).token_type)

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

grant_type or another required field is missing or misspelled

1Check

The client-credentials request needs client_id, scope, client_secret (or a client assertion) and grant_type set to client_credentials. The error text names the field the endpoint did not find.

# Print the keys of the body you send (not the secret values)

2Fix

Add the missing field with the exact name. For a shared secret all four must be present.

grant_type=client_credentials
client_id=<application-id>
client_secret=<secret>
scope=https://graph.microsoft.com/.default

3Verify

The same request returns an access token.

# Decode the token on a debugging tool you control, or call the API with it

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

The request goes to the wrong URL, so the endpoint does not read your body as a token request

1Check

The token endpoint is https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token and takes POST. Compare it with the token_endpoint in the discovery document.

curl -s https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration | grep -o '"token_endpoint":"[^"]*"'

2Fix

Use the exact token_endpoint from the discovery document and the POST method.

POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token

3Verify

Repeat the request from the first step against that URL.

# Expect HTTP 200 and JSON with access_token

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Use MSAL where you can; it builds token requests for you.
  • Keep one tested curl command in the repository as a reference for the exact request.
  • Log the Content-Type and field names of auth requests (never the secret) in non-production.

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

Security

A valid JWT fails to decode because its segments are base64url, not base64

Convert.FromBase64String throws FormatException on a JWT segment

A JWT is three base64url segments joined by dots, and a standard base64 decoder refuses all three differences: base64url uses - and _ instead of + and /, leaves off the = padding, and the dots are not part of any base64 alphabet.

3 causes, each with a fix

Next step

Want this handled for good?

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