0

I am trying to get access token with Microsoft graph API. i am keep getting error -

error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'

in my post request i added the "grant_type" param, what do i do wrong?

Request: (i put my tenant and edit all the other parameters)

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret=qWgdYAmab0YSkuL1qKv5bPX
&grant_type=client_credentials

Response:

{
    "error": "invalid_request",
    "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 4c3017cc-8624-4921-8cea-794861ca5a00\r\nCorrelation ID: cf5e682c-7522-4be3-a9f3-16bb33f40946\r\nTimestamp: 2022-08-02 10:20:07Z",
    "error_codes": [
        900144
    ],
    "timestamp": "2022-08-02 10:20:07Z",
    "trace_id": "4c3017cc-8624-4921-8cea-794861ca5a00",
    "correlation_id": "cf5e682c-7522-4be3-a9f3-16bb33f40946",
    "error_uri": "https://login.microsoftonline.com/error?code=900144"
}

Reference: https://learn.microsoft.com/en-us/graph/auth-v2-service

this worked 4 days ago... i don't know what

thanks!

doron hine
  • 13
  • 7
  • did you try with Postman? In addition there already an question [here](https://stackoverflow.com/questions/49513122/oauth2-error-aadsts90014-the-request-body-must-contain-the-following-parameter) did you take a look. I would say first try with postman – AnkUser Aug 02 '22 at 11:36

2 Answers2

0

You shouldn't send grant_type neither in params nor in headers. Those should be sent in body params then only it will work.

Url: https://login.microsoftonline.com/common/oauth2/v2.0/token client_id, scope and redirect_uri params can be sent as query params. where as grant_type, code and client_secret should sent in body params.

grant_type:authorization_code, 
code: {code you got from the authorization step}, 
client_secret: ****
halfer
  • 19,824
  • 17
  • 99
  • 186
vicky kumar
  • 563
  • 3
  • 11
0

The grant_type should be passed as formData