Search code examples
oauth-2.0microsoft-graph-apipostman

Authentication Token x-www-form-urlencoded body to a JSON body


I can get an authentication token using Microsoft Graph API on Postman using the Post Token api call. https://login.microsoftonline.com/{{AzuretenantID}}/oauth2/v2.0/token

However, I need to make the call in a program we have that only accepts a JSON body. I currently use a x-www-form-urlencoded body as represented in the image below.

x-www-form-urlencoded

I tried to write it as a JSON body in the "raw" body section of Postman.

{"grant_type": "client_credentials",
"client_id":"7721b276-c186-42e0-b81c-c8cf0bfc5f21",
"client_secret":"Lu48Q~5SQ8ge6O2OXvsfYJJH-ga0DdHCNsgubaea",
"scope": "https://graph.microsoft.com/.default"}

However I get the following error:

{
    "error": "invalid_request",
    "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: c5e88698-3b60-4763-85ea-b807ec280000\r\nCorrelation ID: 0998db90-1b32-48e1-b095-7ceb3fe2ff2f\r\nTimestamp: 2023-05-01 18:37:24Z",
    "error_codes": [
        900144
    ],
    "timestamp": "2023-05-01 18:37:24Z",
    "trace_id": "c5e88698-3b60-4763-85ea-b807ec280000",
    "correlation_id": "0998db90-1b32-48e1-b095-7ceb3fe2ff2f",
    "error_uri": "https://login.microsoftonline.com/error?code=900144"
}

Solution

  • The Microsoft identity platform /token endpoint follows standard document and accepts only application/x-www-form-urlencoded message format.

    So application/x-www-form-urlencoded is mandatory and sending JSON request bodies will result in an error.