Error: 401 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown.

Muhammad Arsal 0 Reputation points
2024-12-02T17:55:22.67+00:00

I have used all the correct values here, and I'm receiving an access token from the code below

rich text editor image

I have given this amount of API permission (for testing purposes ofcourse)

rich text editor image

but when I access it through the endpoint below:
https://{site_url}.sharepoint.com/sites/TestSite/_api/web/GetFolderByServerRelativeUrl('/sites/TestSite/Shared%20Documents/Guide')/Files

I keep getting the error 401 'error_description': "Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown.

Why is it like this? Can anyone please help me regarding this issue?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,468 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,968 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,107 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,007 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xyza Xue_MSFT 26,201 Reputation points Microsoft Vendor
    2024-12-03T06:24:00.63+00:00

    Hi @Muhammad Arsal ,

    1.Make sure your scope value is set to https://{tenant-name}.sharepoint.com/.default.

    User's image

    2.Build your REST API link, Here is an example of what the URL could look like:

    https://mycompany.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('Shared Documents/Target Folder')/Files


    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 Answers by the question author, which helps users to know the answer solved the author's problem.