Forum Discussion
CSOM SharePoint Online AuthenticationManager Client Credentaial flow support
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);
}