Connect to SharePoint Online with MFA using CSOM

%3CLINGO-SUB%20id%3D%22lingo-sub-2690560%22%20slang%3D%22en-US%22%3EConnect%20to%20SharePoint%20Online%20with%20MFA%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2690560%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20the%20CSOM%20code%20below%20for%20trying%20to%20connect%20to%20SharePoint%20Online%20with%20MFA%20enabled%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24SiteUrl%20%3D%20%22http%3A%2F%2Four-tenant.sharepoint.com%22%0A%0A%23Setup%20Authentication%20Manager%0A%24AuthenticationManager%20%3D%20new-object%20OfficeDevPnP.Core.AuthenticationManager%0A%24Ctx%20%3D%20%24AuthenticationManager.GetWebLoginClientContext(%24SiteUrl)%0A%24Ctx.Load(%24Ctx.Web)%0A%24Ctx.ExecuteQuery()%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20encountering%20the%20following%20error%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EError%3A%20Cannot%20find%20type%20%5BOfficeDevPnP.Core.AuthenticationManager%5D%3A%20verify%20that%20the%20assembly%20containing%20this%20type%20is%20loaded%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20already%20have%20PnP%20SharePoint%20installed%20via%20%22%3CSPAN%20class%3D%22hljs-pscommand%22%3EInstall-Module%3C%2FSPAN%3E%3CSPAN%3E%20PnP.PowerShell%22%20so%20I%20am%20not%20sure%20what%20is%20wrong.%20For%20reasons%2C%20I%20cannot%20use%20the%20Connect-PnPOnline%20cmdlet.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHow%20do%20I%20connect%20to%20SharePoint%20Online%20with%20CSOM%20if%20my%20account%20has%20MFA%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2690560%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2691211%22%20slang%3D%22en-US%22%3ERe%3A%20Connect%20to%20SharePoint%20Online%20with%20MFA%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2691211%22%20slang%3D%22en-US%22%3EThe%20latest%20iteration%20of%20the%20PnP.PowerShell%20module%20no%20longer%20includes%20this.%20You%20can%20try%20and%20replace%20%22OfficeDevPnP.Core.AuthenticationManager%22%20with%20%22PnP.Framework.AuthenticationManager%22%20instead.%3C%2FLINGO-BODY%3E
Occasional 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?

1 Reply
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.