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

Dmytro Pavlov 1 Reputation point

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"
{"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

    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.



    --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

    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.


    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.