Forum Discussion

Jerror's avatar
Jerror
Copper Contributor
Jul 06, 2023

trying to get access token using sharepoint onpremise api but getting error in first step

We are making SharePoint API calls for our on-premises SharePoint website 

We are following the rest API's to get access token 
in the first step 

Request 
https://sharepoint.tenat.com:*****/sites/live/_layouts/15/OAuthAuthorize.aspx?client_id=*************&scope=Web.Manage&response_type=code&redirect_uri=https://sharepoint.tenant.com:*****/sites/live/_layouts/15/viewlsts.aspx
after recalling this request getting the trust it option 
but after that instead of code, we are getting this unauthorized error

Error
error=server_error&error_description=The%20remote%20server%20returned%20an%20error%3A%20%28401%29%20Unauthorized%2E

We also tried from the owner account still getting this error 

In a normal SharePoint website, the API is working fine getting errors in the on-premises website
We are using Sharepoint 2016 on-premise

  • Kelly005's avatar
    Kelly005
    Copper Contributor

    Did you find the solution? I have same issue for getting on-premise access token.


    I can get share point online access token with share point online resource id, but can’t find any document about how to get on-premise resource id.

     

    If you resolved the problem, could you share the solution? Thank you.

    • Jerror's avatar
      Jerror
      Copper Contributor
      Hi,
      We did not get any solution for this till now.
      • Kelly005's avatar
        Kelly005
        Copper Contributor
        Thank you for quick reply, I will continue the research.
  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi Jerror,

    If you are getting the "401 Unauthorized" error, you can try:

    1. Check if the owner account has the necessary permissions:
    - Make sure that the owner account used for authentication has the appropriate permissions to access the SharePoint resources and perform the desired API actions.
    - Verify that the owner account has full control (or the required permissions)

    2.Ensure the SharePoint on-premises environment is configured for OAuth:

    - Verify that the SharePoint 2016 on-premises environment has been properly configured to support OAuth authentication.

    3. Confirm the URL and parameters:
    - Double-check the URL you are using to request the access token and ensure it is correctly formatted and matches the SharePoint on-premises environment.
    - Verify that all required parameters, such as client_id, redirect_uri, and other necessary parameters, are included and correctly specified in the request URL.

    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

    Kindest regards

    Leon Pavesic

    • Jerror's avatar
      Jerror
      Copper Contributor

      Hi LeonPavesic 
      Still, we are getting the same error
      We checked all things, we tried from the admin account

Resources