Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException

Hemant Ashok 15 Reputation points
2024-08-28T12:45:50.7666667+00:00

I'm encountering an error: Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' when trying to access the API at https://<sharepoint domain>.sharepoint.com/sites/<site>/_api/siteiconmanager/getsitelogo?type=1. Although I can log in and perform operations via the web interface with the same user, the API call fails. I'm using the react MSAL library to generate the token.

 .acquireTokenSilent({
        scopes: ['https://<share point domain>.sharepoint.com/.default'],
        account: accounts[0]
      })
	  
Developer technologies ASP.NET ASP.NET Core
Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 17,766 Reputation points Moderator
    2024-08-28T19:43:05.25+00:00

    Hi @Hemant Ashok Greetings! Thank you for posting this question here.

    You may be setting the scope wrong when getting the access token using the MSAL library. Referring to the document How to Acquire token for an API I could see that the format to apply scopes is as follows scopes: ["user.read"]. You can then extract the access token in the desired format for the API by following the below snippet.

    const accessTokenRequest = {
            scopes: ["user.read"],
            account: accounts[0],
          };
          instance
            .acquireTokenSilent(accessTokenRequest)
            .then((accessTokenResponse) => {
              // Acquire token silent success
              let accessToken = accessTokenResponse.accessToken;
              // Call your API with token
    

    If the above approach does not work and you are using Account credentials to get access token, please refer to a solution shared on a similar thread How to get SharePoint site logo using Graph? which provides an alternate approach of acquiring token using an API end point.

    Hope this helps! Please let us know if you have any additional questions or need further assistance.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


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.