Home > Forum > Data sources > Microsoft Graph: How to get auth token?

Microsoft Graph: How to get auth token?
0

Hi there,

this is regarding Microsoft Graph. I'm trying to get a Bearer token but I always get an error message when loading stating:

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

I attached a couple of screenshots of the configuraiton. And here's the full error message:


Request Start
Request-Url:
https://login.microsoftonline.com/[I SANITIZED IT]/oauth2/v2.0/token
Request-Header:
Scope: https://graph.microsoft.com/.default

Request-Body:
{
"Grant_Type":"client_credentials",
"client_id":"[I SANITIZED IT]",
"client_secret":"[I SANITIZED IT]",
"resource":"https://graph.microsoft.com"
}

Request End
Response Start
Response-Code:
BadRequest (400)
Response-Body:
{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 0768443e-3dcf-41ae-b29c-3bf5c6b66c00\r\nCorrelation ID: 08fffc80-37ae-4651-b6b0-a1de65076cd6\r\nTimestamp: 2022-10-05 09:51:53Z","error_codes":[900144],"timestamp":"2022-10-05 09:51:53Z","trace_id":"0768443e-3dcf-41ae-b29c-3bf5c6b66c00","correlation_id":"08fffc80-37ae-4651-b6b0-a1de65076cd6","error_uri":"https://login.microsoftonline.com/error?code=900144"}
Response-Header:
Cache-Control: no-store, no-cache
Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
x-ms-request-id: 0768443e-3dcf-41ae-b29c-3bf5c6b66c00
x-ms-ests-server: 2.1.13777.6 - NEULR2 ProdSlices
X-XSS-Protection: 0
Set-Cookie: fpc=AvbOfFjwoSJMo6ALHk8VnPU; expires=Fri, 04-Nov-2022 09:51:53 GMT; path=/; secure; HttpOnly; SameSite=None, x-ms-gateway-slice=estsfd; path=/; secure; httponly, stsservicecookie=estsfd; path=/; secure; httponly
Date: Wed, 05 Oct 2022 09:51:52 GMT

Response End

Exceptions:
System.Exception: Rest service call failed. Http code BadRequest (400). Inspect log to get more information.


I've tried every combination and syntaxes I could think of.
In Postman it works without issues.

Has anyone ever set up a connection/data source to retrieve a Graph auth token?

Thanks for your help.

In reply to: Maksymilian Stachowiak

It's not in the graph documentation, but first thing i've noticed is that you are using Grant_Type, and returned response talks about grant_type.

Check if it's case sensitive - one drive api at least is: https://learn.microsoft.com/bs-latn-ba/onedrive/developer/rest-api/concepts/case-sensitivity?view=odsp-graph-online#json-request-body

Hi there,
thanks for your reply.
Unfortunately, case-sensitivity was not the issue.
I noticed that I can even leave the request body empty and I will still get the exact error message.
It doesn't matter what I put in the request body, can be any character.

Other connections that don't use https://login.microsoftonline.com work, e.g. https://graph.microsoft.com.
However, with that base url you cannot request a token as far as I know.

Are you able to get a token through Webcon?

Thank you.

In reply to: Flo

Hi there,
thanks for your reply.
Unfortunately, case-sensitivity was not the issue.
I noticed that I can even leave the request body empty and I will still get the exact error message.
It doesn't matter what I put in the request body, can be any character.

Other connections that don't use https://login.microsoftonline.com work, e.g. https://graph.microsoft.com.
However, with that base url you cannot request a token as far as I know.

Are you able to get a token through Webcon?

Thank you.

Hi Florian,

Are you able to resolve this error ?
I am also facing same error its working fine with postman but whenever I used this in dot net core so I am getting error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 6cdd389d-2bee-4bb4-9bdf-89d7aa56d300\r\nCorrelation ID: d489bf42-4578-4012-baf0-db0cc51c51f8\r\nTimestamp: 2022-12-01 07:18:36Z","error_codes":[900144],"timestamp":"2022-12-01 07:18:36Z","trace_id":"6cdd389d-2bee-4bb4-9bdf-89d7aa56d300","correlation_id":"d489bf42-4578-4012-baf0-db0cc51c51f8","error_uri":"https://login.microsoftonline.com/error?code=900144