Authorization and Token endpoints in Sharepoint

codeninja12 1 Reputation point
2022-02-10T20:52:13.047+00:00

Hi Guys,
I am trying to authenticate to sharepoint rest api. These are the steps I did.

  1. Created app registration in azure active directory and I gave permission to Site.ReadAll, Site.ManageAll .etc
  2. Generated client credentials, and copied client ID,
  3. Send the token request to the following url
    https://login.microsoftonline.com/\*\*\*\*\*-***-***-\*\*/oauth2/v2.0/token
    with the scope
    https://**********.sharepoint.com/.default
  4. I got the token and use that as bearer token, and send the request to get a sharepoint resource, And it fails with 401 unauthorized.

Anyone has any idea why it is failing. If you can point me to a right direction, that will great. I appreciate your help.

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,716 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,825 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,711 Reputation points Microsoft Vendor
    2022-02-11T02:02:43.663+00:00

    Hi @codeninja12 ,
    You need to create self signed certificate if you are using azure app. You can refer to the document to upload certificate. So I will recommend you to grant access using SharePoint App-Only. grant permission to your client id by steps and then you can get bearer token by https://login.microsoftonline.com/---/oauth2/v2.0/token


    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.


    1 person found this answer 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.