Preview Sharepoint file with Graph API thrown Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException

Djiby THIAW [SNT DSI/INS/IRCP] 20 Reputation points
2023-03-24T23:06:35.4966667+00:00

Hello,

I am using Microsoft graph API to preview a file from Sharepoint. The application has the permission Sites.ReadWrite.All. I am calling the API POST /drives/{driveId}/items/{itemId}/preview and I use the getUrl value to GET the preview of the document. I am also using a valid token with calling the GET API.

But I am getting the error below:

{"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."}

I have also the same error when I use directly the ifram code generated by MS when you preview à file in Sharepoint.

Thanks for your help.

Regards

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
{count} votes

Accepted answer
  1. Siddharth Gautam 860 Reputation points
    2023-03-25T01:12:14.3333333+00:00

    Hello Djiby THIAW [SNT DSI/INS/IRCP],

    Thanks for posting!

    As per my testing, I am able to replicate the error message when I use the bearer token instead of using the access token present in short-lived embeddable URL, please refer below screenshots for better understanding:

    User's image

    Below is the screenshot with access token present in short-lived embeddable URL( getUrl).

    User's image

    Reference link: https://learn.microsoft.com/en-us/graph/api/driveitem-preview?view=graph-rest-1.0

    Hope this helps.

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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.