SharePoint OAuth Authentication | Authorizing REST API SharePoint| Get Access token from SharePoint | Set up OAuth for SharePoint | SharePoint Integration | Rest API Integration

Abhilash Ananthakrishnan
4 min readMay 19, 2022

SharePoint is a web-based collaborative platform that integrates with Microsoft Office. It was launched in 2001 and is primarily used as a document management and storage system, but the product is highly configurable and usage varies substantially among organizations.

In this blog, we will see how we can get the access token from Sharepoint using PostMan tool.

Step 1: Join the Microsoft 365 Developer Program

  1. Go to the Join the Microsoft 365 Developer Program page.
  2. Click on Join now and complete the Signup process.
Microsoft 365 Developer Program

Keep note of the domain name and Administrator email, this will be the email we will be using in the next steps.

Step 2: Register an app in SharePoint

a. Navigate to https://<>/layouts/15/appregnew.aspx (For ex:

b. Click Generate for Client Id and Client Secret and provide a name.

c. Fill in the app domain ( Enter the Redirect URL, it should be https and the URL.

d. Click Create.

Note down the Client Id, Client Secret & Redirect URI for future use.

Step 3: Get the Realm of your site using PostMan.

  1. Open PostMan App (Get it from here)
  2. Create a GET request with url https://<domain_Name>
  3. Headers, ‘Authorization’ : ‘Bearer’ & ‘Content-Type’ : ‘text/html’
  4. Send Request and click on Header section in response and scroll down till you see Bearer realm. (screenshot attached below)

Note down the Bearer realm for future use.

Step 4: Get the Authorization code

  1. Construct the below url using your domain, client Id, and redirect uri and scope value from the following link.

(Choose Scope: )


Ex :

Go to this url in browser and we will reach authorization screen where we have click ‘Trust it’ button.

Once clicked we will redirect to another URL that appends our redirect uri with authorization code as shown below. Copy and paste the auth code for future use.


Step 5: Get the access token and refresh token

  1. Construct the below url and body for POST request in POSTMAN

URL :<site_realm>/tokens/OAuth/2

site_realm — use the code which we got in Step 3 (Ex. )


grant_type=client_credentials&client_id=<client_id>@<site_realm>&client_secret=<client_secret>&code=<auth_code>&redirect_uri=<redirect_url>&resource=< audience principal ID>/<site_host>@<site_realm>

Use Client Id, Client Secret & Redirect URI from Step 2, site_realm from Step 3, and auth_code from Step 4.

“<client_id from Step 2>@<site_realm from Step 3>” —> Copy this combined string and encode it before using. (Encode here)

<client_secret from Step 2> → Use it without encoding

<auth_code from step 4>→ Use it without encoding

<redirect_url from Step 2>→ Use it without encoding

< audience principal ID>/<site_host>@<site_realm> →

audience principal ID is a permanent security principal ID for SharePoint- ‘00000003–0000–0ff1-ce00–000000000000

site_host → <domain> (Ex.

<site_realm from Step 3>

— > Copy this combined string and encode it before using. (Encode here)

Final Body will look like :



Content-Type : application/x-www-form-urlencoded

Craete post request and Send for getting access token as response

We can use this Access code for accessing sharepoint for our requirements.