Feb 10 2018 05:40 PM - edited Feb 10 2018 05:54 PM
Hi,
I am in the process to write a console app to access SharePoint Online without interactive user log in.
I am thinking using clientID and clientSecret in code so no user login is required.
Does anyone know if it is supported. If it is, any links will be appreciated
Regards
JL
Feb 11 2018 12:09 AM
Feb 11 2018 12:34 AM
Thanks for the reply and link. I am thinking using Azure AD to register the app so the app security will be managed by Azure AD in consistent with other Azure services.
Feb 11 2018 12:37 AM
Feb 20 2018 06:51 PM
Hi Joe,
PnP Team has created PnP Core APIs as wrapper on top of Microsoft CSOM APIs which provides lot of extension methods. Do below steps to PnP Core nuget package to your console app.
1. In your console application project, right click in VS solution and select Manage Nuget packages for solution.
2. Search for 'SharePointPnPCoreOnline' package and install it. It install all dependent packages as well.
3. Once installed, you can use below namespace in using section
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
4. Then you can use AuthenticatonManager class to create SharePoint context as below.
var authManager = new OfficeDevPnP.Core.AuthenticationManager();
string appId = "<SharePoint App Client ID>";
string appSecret = "<SharePoint App Client Secret>";
string siteURL = "<SiteURL>";
using(ClientContext context = authManager.GetAppOnlyAuthenticatedContext(siteURL, appId, appSecret))
{
Site objSite = context.Site;
context.Load(objSite);
context.ExecuteQuery();
Console.WriteLine("Site Url:" + objSite.Url);
}