[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 Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 20,491 Reputation points MVP Volunteer Moderator
    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 46,406 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.


Your answer

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