Introduction
SharePoint Online access token is required to perform any CRUD operations. We can use this token to authenticate and access SharePoint REST APIs.
Step 1. Register the app on SharePoint
To register the app, go to the /_layouts/appregnew.aspx page of your site collection. Below is an example.
Example: https://mysite.sharepoint.com/sites/demo/_layouts/15/appregnew.aspx
In the above link, the demo is the site collection where we are registering the app.
- Client Id: Click on the Generate button on Client Id
- Client Secret: Click on the Generate button on the Client secret
- Title: Provide the name of your app
- App Domain: Copy and paste the example 'www.contoso.com' (for our purpose, this will work)
- Redirect URI: Copy and paste the example 'https://www.contoso.com/default.aspx' (for our purpose, this will work)

Click on Create and copy and save the generated Client Id & Client Secret in Notepad, we will use this in our code.

Step 2. Install the above registered app on SharePoint Site collection
- Go to your site collection and access /_layouts/15/appinv.aspx
Example: https://mysite.sharepoint.com/sites/demo/_layouts/15/appinv.aspx

- In the App Id textbox, paste the Client Id that we generated in the previous step and click on Lookup
- On click of Lookup, values for Title, App Domain, and Redirect URI will be auto populated
- For Permission Request XML, copy and paste the below XML
Note: Above permission XML will give Full control to the app at the site collection level.<AppPermissionRequests AllowAppOnlyPolicy="true"> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" /> </AppPermissionRequests>
Permissions indicate the activities that an add-in is permitted to do within the requested scope. SharePoint add-in can have the following rights: Read, Write, Manage, FullControl - Click on the create
- Click on Trust It

That's it. Our app is now installed in our site collection.
You can verify your installed app using /_layouts/15/appprincipals.aspx page
Example: https://mysite.sharepoint.com/sites/demo/_layouts/15/appprincipals.aspx
Note: This app will be valid for 1 Year only, after 1 year Client ID & Client secret will be expired and we will have register new App following the same steps.

Join the conversation! Your thoughts help the community grow.