How to generate App ID & Secret key to access SharePoint online through console application using Access Token – Part 1

Ahamed Fazil Buhari
 
Senior Developer
August 23, 2018
 
Rate this article
 
Views
35402

Hello,

In this article we will see how to access SharePoint online site from your console application. This is mainly useful when your SharePoint site does not have service accounts. In this case, when you don’t have service account it’s not good approach to access using user account, instead of that we can register an App and generate secret key, using this secret key we can access SharePoint from Console application or any other application.

There are 3 steps to create App Id and App Secret key that will be later used to access SharePoint. In this article we will see how to create App id and secret key; in the next article we will see how we can utilize this in our console application to access SharePoint Online.

Step 1: Create or Register new app (https://<site>/_layouts/15/AppRegNew.aspx)

Click on Generate for App Id and App Secret (copy the value somewhere for later use). Give any name as Title and App Domain & Redirect URI are sample values it can be anything as shown below,

clip_image002

Step 2: Giving permission to the app Id which is created in Step 1,

Go to -> https://<site>/_layouts/15/appinv.aspx

In App ID textbox paste the app Id which is created in the previous step and click on Lookup button. SharePoint will find the account and fills rest of the values,

In Permission Request XML, paste the below XML

 <AppPermissionRequests AllowAppOnlyPolicy="true">
   <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
 </AppPermissionRequests>
 

clip_image004

clip_image006

Here I am giving FullConrol to the site collection, you can give various permission level by changing Scope and Right attribute values in the XML. For example in the below example giving Read permission to Web and Write Permission to list

 <AppPermissionRequests AllowAppOnlyPolicy="true">
       <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read"/>
       <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/>
     </AppPermissionRequests>
 

Step 3: Check whether you app is available in Site App Permission list, by going to Site Settings -> Site app permission or (https://<site>/_layouts/15/appprincipals.aspx )

clip_image008

Well, now we have app which can access SharePoint with FullControl.

In the next article we will see how we can access SharePoint using App Id and App secret key. Thank you for reading

 

Happy Coding

Ahamed

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment