how to fetch Share-point OAuth 2.0 access and refresh token for share-point API's

Viewed 91

I am working on the share-point API via the OAuth 2.0, As Basic auth will be deprecating. So i am able to find the access token, however when passing the access token to the share-point API it is generating error with Status code 401 Unauthorized.

I have tried both the method i.e creating the API via the share-point and via AzureAD, however both of the API is generating the error even after passing the correct parameter's,

The share-point APP API is generating the error : {"error":"invalid_request","error_description":"Token type is not allowed."} with status code 401,

on the otherhand when creating the app via the AzureAD and granting all the access to the share-point app , I am getting the error : {"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."} with the same status code 401.

for access token I am using the API : https://accounts.accesscontrol.windows.net/tenant-id/tokens/oauth/2

so what I need is the procedure to generate the access and refresh token and via that fetching the response of endpoint of share-point.

Error code while fetching response from share-point via sharepoint APP

enter image description here

2 Answers

I tried to reproduce in my environment i m getting result successfully as below:

enter image description here

To resolve this error:

{"error_description":"Exception of type Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException'was thrown."} with the same status code 401.

  1. Make sure to Assign Request XML permission to the app to use Api endpoint to get all the details as below:

enter image description here

<AppPermissionRequests AllowAppOnlyPolicy="true">  
 <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" 
  Right="FullControl" />
</AppPermissionRequests>
  1. Make sure in postman you have to pass the value client_id:clientid@tenantid and add resource: resource/<resource/SiteDomain@TenantID as below:

enter image description here enter image description here

  1. Please check whether you have provided correct Api endpoints Uri like https://{site_url}/_api/web/lists also see this Specify entry points for the SharePoint REST service

thank's mate I had already performed the above mentioned steps, even pass the permission to the Share-point API of XML, I am able to get the access token, but when passing the token to share-point API, It is giving me below mentioned error => "error": {"code": "-2147024891, System.UnauthorizedAccessException"}

Is the reason I do made the app in AzureAD as it grant all the access to all office 365 product. And that app to is also throwing the error.

Related