Getting an Azure AD token to send events to an event hub is not working

Vinod Ramasubbu 6 Reputation points
2021-07-15T15:03:24.807+00:00

I followed the below document and tried getting an access token from Azure AD.

I am getting an error that request body must contain grant_type ,even though its being pass as part of the request body.
I tried the same with postman and got the same error.

https://learn.microsoft.com/en-us/rest/api/eventhub/get-azure-active-directory-token#see-also

curl --location --request GET 'https://login.microsoftonline.com/MY-TENANT-ID/oauth2/token' --header 'Content-Type: application/x-www-form-urlencoded' --form 'grant_type="client_credentials"' --form 'client_id="MY-CLIENT_ID"' --form 'client_secret="MY-CLIENT-IDS-SECRET"' --form 'resource="https://eventhubs.azure.net"'

{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 80a20306-05bf-4054-b240-b1eb1ec0d300\r\nCorrelation ID: 0292cf87-b34d-4586-b89b-e057741bc3fa\r\nTimestamp: 2021-07-15 14:38:29Z","error_codes":[900144],"timestamp":"2021-07-15 14:38:29Z","trace_id":"80a20306-05bf-4054-b240-b1eb1ec0d300","correlation_id":"0292cf87-b34d-4586-b89b-e057741bc3fa","error_uri":"https://login.microsoftonline.com/error?code=900144"}

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
641 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,811 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,616 Reputation points
    2021-07-16T09:59:25.097+00:00

    Hi @Vinod Ramasubbu · Thank you for reaching out.

    You need to replace Content-Type: with Content-Type= to set its value to application/x-www-form-urlencoded. You can also set Content-Type to application/form-data. Both works.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.