I am encountering an issue while working with Azure Active Directory authentication. Specifically, I am receiving the following error message:
{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.}
Here is the context of my request:
Endpoint: https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token Request Method: POST Headers: "Content-Type" : "application/x-www-form-urlencoded" Request Body:
{
"grant_type": "client_credentials",
"client_id": {client_id},
"client_secret": {client_secret},
"scope": "https://graph.microsoft.com/.default"
}
Can someone please guide me on how to correctly include the 'grant_type' parameter in the request body? Any examples or insights into what might be causing this issue would be greatly appreciated.
Thank you in advance for your help!
I have ensured that the request body includes other necessary parameters, but the 'grant_type' parameter seems to be missing or incorrectly specified.
The error occurred as you are passing wrong Content-Type while generating the token.
Initially I got the same error:
I agree with @juunas, either change Content-Type to "application/json"
and pass json data OR with Content-Type : application/x-www-form-urlencoded
pass body as form-encoded POST parameters.
I passed the body as parameters like below to resolve the error:
https://login.microsoftonline.com/TENANTID/oauth2/v2.0/token
client_id:ClientID
client_secret:ClientSecret
grant_type:client_credentials
scope:https://graph.microsoft.com/.default
Otherwise, you can also change the Content-Type to "application/json"
and pass json data only