CSOM SharePoint Online AuthenticationManager Client Credentaial flow support

%3CLINGO-SUB%20id%3D%22lingo-sub-154799%22%20slang%3D%22en-US%22%3ECSOM%20SharePoint%20Online%20AuthenticationManager%20Client%20Credentaial%20flow%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-154799%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20am%20in%20the%20process%20to%20write%20a%20console%20app%20to%20access%20SharePoint%20Online%20without%20interactive%20user%20log%20in.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20am%20thinking%20using%20clientID%20and%20clientSecret%20in%20code%20so%20no%20user%20login%20is%20required.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDoes%20anyone%20know%20if%20it%20is%20supported.%20If%20it%20is%2C%20any%20links%20will%20be%20appreciated%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERegards%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJL%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-161991%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20SharePoint%20Online%20AuthenticationManager%20Client%20Credentaial%20flow%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-161991%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Joe%2C%3C%2FP%3E%0A%3CP%3EPnP%20Team%20has%20created%20PnP%20Core%20APIs%20as%20wrapper%20on%20top%20of%20Microsoft%20CSOM%20APIs%20which%20provides%20lot%20of%20extension%20methods.%26nbsp%3B%20Do%20below%20steps%20to%20PnP%20Core%20nuget%20package%20to%20your%20console%20app.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20In%20your%20console%20application%20project%2C%20right%20click%20in%20VS%20solution%20and%20select%20Manage%20Nuget%20packages%20for%20solution.%3C%2FP%3E%0A%3CP%3E2.%20Search%20for%20'SharePointPnPCoreOnline'%20package%20and%20install%20it.%20It%20install%20all%20dependent%20packages%20as%20well.%3C%2FP%3E%0A%3CP%3E3.%20Once%20installed%2C%20you%20can%20use%20below%20namespace%20in%20using%20section%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eusing%20Microsoft.SharePoint.Client%3B%3CBR%20%2F%3Eusing%20OfficeDevPnP.Core%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4.%20Then%20you%20can%20use%20AuthenticatonManager%20class%20to%20create%20SharePoint%20context%20as%20below.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Evar%20authManager%20%3D%20new%20OfficeDevPnP.Core.AuthenticationManager()%3B%3CBR%20%2F%3E%20string%20appId%20%3D%20%22%3CSHAREPOINT%20app%3D%22%22%20client%3D%22%22%20id%3D%22%22%3E%22%3B%3CBR%20%2F%3E%20string%20appSecret%20%3D%20%22%3CSHAREPOINT%20app%3D%22%22%20client%3D%22%22%20secret%3D%22%22%3E%22%3B%3CBR%20%2F%3E%20string%20siteURL%20%3D%20%22%3CSITEURL%3E%22%3B%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20using(ClientContext%20context%20%3D%20authManager.GetAppOnlyAuthenticatedContext(siteURL%2C%20appId%2C%20appSecret))%3CBR%20%2F%3E%20%7B%3CBR%20%2F%3E%20Site%20objSite%20%3D%20context.Site%3B%3CBR%20%2F%3E%20context.Load(objSite)%3B%3CBR%20%2F%3E%20context.ExecuteQuery()%3B%3CBR%20%2F%3E%20Console.WriteLine(%22Site%20Url%3A%22%20%2B%20objSite.Url)%3B%3C%2FSITEURL%3E%3C%2FSHAREPOINT%3E%3C%2FSHAREPOINT%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-154817%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20SharePoint%20Online%20AuthenticationManager%20Client%20Credentaial%20flow%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-154817%22%20slang%3D%22en-US%22%3EMight%20I%20ask%20what%20do%20you%20want%20to%20achieve%3F%20Registering%20as%20an%20Azure%20AD%20App%20might%20require%20you%20have%20to%20use%20the%20Microsoft%20Graph%20to%20work%20with%20SPO.%20By%20the%20way%2C%20it's%20also%20possible%20to%20follow%20a%20similar%20approach%20to%20the%20one%20described%20in%20the%20link%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-154815%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20SharePoint%20Online%20AuthenticationManager%20Client%20Credentaial%20flow%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-154815%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20reply%20and%20link.%20I%20am%20thinking%20using%20Azure%20AD%20to%20register%20the%20app%20so%20the%20app%20security%20will%20be%20managed%20by%20Azure%20AD%20in%20consistent%20with%20other%20Azure%20services.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-154812%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20SharePoint%20Online%20AuthenticationManager%20Client%20Credentaial%20flow%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-154812%22%20slang%3D%22en-US%22%3EYes%2C%20this%20should%20be%20possible%20(it%20has%20been%20a%20while%20since%20last%20time%20I%20did)%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.codeproject.com%2FArticles%2F1034444%2FAccess-Office-using-a-Console-Application%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.codeproject.com%2FArticles%2F1034444%2FAccess-Office-using-a-Console-Application%3C%2FA%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

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

 

 

4 Replies
Highlighted
Highlighted

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.

Highlighted
Might I ask what do you want to achieve? Registering as an Azure AD App might require you have to use the Microsoft Graph to work with SPO. By the way, it's also possible to follow a similar approach to the one described in the link
Highlighted

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);


}