Sharepoint Online C# CSOM MFA Issues

Klein, John 20 Reputation points

I keep going round and round. Microsoft keeps changing how things work, so even examples from 2022 no longer work.

All I need help with is doing Multi-Factor Authentication to Sharepoint Online through C#. All the examples I find have you using older packages that no longer work with the latest Visual Studio environment. I use NuGet to get my packages, and if I try to use the older methods, they are not supported.

The previous way I see it was done is the following:

string siteUrl = "";
var authManager = new OfficeDevPnp.Core.AuthenticationManager();
ClientContext ctx = authManager.GetWebLoginClientContext(siteUrl);

I now need to use the following per Microsoft.

  • Microsoft.SharePointOnline.CSOM
  • PnP.Framework

With these new Packages, how am I supposed to create a ClientContext using a AuthenticationManager that supports Multi-Factor Authentication for a Username?

This works so easy with PowerShell using Microsoft.Online.Sharepoint.PowerShell.

Connect-SPOService -Url -Credential
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,536 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,174 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 30,666 Reputation points Microsoft Vendor

    Hi Klein, John,

    Per my test, the latest version of SharePointPnPCoreOnline doesn't contain authManager.GetWebLoginClientContext(siteUrl);. This function has been deleted.

    I will recommend you to use app-only for authentication:

    Since you don't want to use app, the only way is to use old version pnpcore. You can follow the steps

    1. Go to Manage NuGet Packet.
    2. choose older version such as 3.25 User's image
    3. Now the authManager.GetWebLoginClientContext(siteUrl) is available

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful