[Python] /oauth2/v2.0/token request returns InvalidAuthenticationToken error as a response

Dmytro Pavlov 1 Reputation point
2022-10-31T15:09:32.453+00:00

URL: https://login.microsoftonline.com/{MY_TENANT_ID}/oauth2/v2.0/token
request body:
{
"resource": "https://graph.microsoft.com",
"grant_type": "client_credentials",
"client_secret": "MY_SECRET",
"client_id": "MY_CLIENT_ID",
"scope": "https://graph.microsoft.com/.default"
}
Response:
{"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError":{"date":"2022-10-31T14:57:17","request-id":"...","client-request-id":"..."}}}

Why does TOKEN request return invalid TOKEN error?..

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,044 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,083 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 17,021 Reputation points MVP
    2022-10-31T15:51:50.207+00:00

    Have you configured the correct application permission?
    To configure application permissions for your app in the Azure app registrations portal under an application's API permissions page, choose Add a permission, select Microsoft Graph, and then choose the permissions your app requires under Application permissions.

    The following screenshot shows the Select Permissions dialog box for Microsoft Graph application permissions.

    255765-image.png

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

  2. CarlZhao-MSFT 38,936 Reputation points
    2022-11-01T07:11:52.733+00:00

    Hi @Dmytro Pavlov

    You should remove the resource parameter, as it is often applied to v1.0 endpoints, and in v2.0 it has been replaced by scope.

    255879-page13.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.