Connect to SharePoint Online without Basic Authentication from C# Console App

Elmo 41 Reputation points
2022-10-31T12:00:41.643+00:00

Hello,

I have developed a C# Windows Console app. In the past I could connect and write data to SharePoint Online using Basic Authentication very easily. See my (simplified) code here:

using Microsoft.SharePoint.Client;  
using System.Security;  
  
onlineCredentials = new SharePointOnlineCredentials(userName, securePassword);  
  
ClientContext ctx = new ClientContext(myWebsiteUrl)  
ctx.Credentials = onlineCredentials;  
Web web = ctx.Web;  
ctx.Load(web);  
ctx.ExecuteQuery();  

Now, Basic Authentication is disabled in the target Sharepoint Online tenant.

What are the options to connect to SharePoint Online (from my Console application) now? Is the only way to create an Azure app to get ?

Thanks for any help! :)

Regards,
Elmo

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

2 answers

Sort by: Newest
  1. Elmo 41 Reputation points
    2022-10-31T16:24:22.967+00:00

    Hi RobWindsor,

    thanks a lot for your great answer. This helps me a lot.

    A few points are still not clear to me:

    Okay, I grant my Azure app specific permissions. And with the combination of the client ID and the certificate my console app can perform specific actions (in your example, the console app can read data from SharePoint sites.)

    Does this mean, that the permissions of the console app are valid for each and every SharePoint site of the tenant?
    What if I want to limit the permissions of the console app to a specific SharePoint site?

    I hope you understand what's my point here: If you cannot limit the permissions of the app to certain SharePoint sites, then everybody who has the client ID and the certificate has read permissions to everything in the tenant, in the worst case to confidential data.

    Regards,
    Emmo

    Was this answer helpful?


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    6 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.