Microsoft Graph API error: Access token validation failure. Invalid audience.

MOUSSAOUI Mohammed 40 Reputation points
2024-08-20T13:48:26.91+00:00

Hello,

I am encountering a small problem with the API key. I would like to fetch data from a file located in a SharePoint library using JavaScript.
User's image

I created an application on SharePoint and granted it the following permissions:

**
User's image

I used Postman to generate an access token, but when I try to use this access token, it doesn't work either on Postman or in JavaScript.

User's image

I successfully generated an access token, but when I try to use it, I encounter an error.

  1. Error on Postman:

User's image

  1. Error on JS (Here is my JavaScript code:

User's image

User's image

Could you please help me resolve this issue? Thank you.

Microsoft 365 and Office | SharePoint | Development
Microsoft Security | Microsoft Graph
{count} votes

Answer accepted by question author
  1. CarlZhao-MSFT 46,411 Reputation points
    2024-08-21T02:37:18.9166667+00:00

    Hi @MOUSSAOUI Mohammed

    The 00000002-0000-0000-c000-000000000000 is the application ID for Azure AD Graph API, which has been deprecated and cannot be used to call MS Graph API. You should request a token for MS Graph API, please follow this documentation.

    Additionally, if the audience of the token you request in JS is MS Graph API, do not apply it to SharePoint REST API, otherwise it will still throw a 401 error.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

6 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.