Connect to SharePoint Online with MFA using CSOM

Copper Contributor

I have the CSOM code below for trying to connect to SharePoint Online with MFA enabled:

 

 

$SiteUrl = "http://our-tenant.sharepoint.com"

#Setup Authentication Manager
$AuthenticationManager = new-object OfficeDevPnP.Core.AuthenticationManager
$Ctx = $AuthenticationManager.GetWebLoginClientContext($SiteUrl)
$Ctx.Load($Ctx.Web)
$Ctx.ExecuteQuery()

 

 

I am encountering the following error: 

 

Error: Cannot find type [OfficeDevPnP.Core.AuthenticationManager]: verify that the assembly containing this type is loaded

 

 

I already have PnP SharePoint installed via "Install-Module PnP.PowerShell" so I am not sure what is wrong. For reasons, I cannot use the Connect-PnPOnline cmdlet.

 

How do I connect to SharePoint Online with CSOM if my account has MFA?

3 Replies
The latest iteration of the PnP.PowerShell module no longer includes this. You can try and replace "OfficeDevPnP.Core.AuthenticationManager" with "PnP.Framework.AuthenticationManager" instead.
I was able to by following this post but then get an error for "401 unauthorized":

https://morgantechspace.com/2021/09/connect-to-sharepoint-site-with-mfa-account-using-csom-and-power...