Skip to content

Instantly share code, notes, and snippets.

@vman
Last active December 17, 2021 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vman/37bab1e1d700be238011f1de23a3e275 to your computer and use it in GitHub Desktop.
Save vman/37bab1e1d700be238011f1de23a3e275 to your computer and use it in GitHub Desktop.
SharePoint Online: Using CSOM with an account configured with Multi-factor Authentication (MFA)
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using System;
namespace CSOMDemo
{
class Program
{
static void Main(string[] args)
{
var authManager = new AuthenticationManager();
var ctx = authManager.GetWebLoginClientContext("https://contoso.sharepoint.com/");
Web web = ctx.Web;
User user = web.CurrentUser;
ctx.Load(web);
ctx.Load(user);
ctx.ExecuteQuery();
Console.WriteLine(web.Title);
Console.WriteLine(user.LoginName);
Console.ReadLine();
}
}
}
@shaipetel
Copy link

This API is no longer in the SharePointPnPCoreOnline Nuget package.
Any ideas where this API can be found now?

@ksuresh1988
Copy link

try to install an older version that is 3.12.1908 then you can able to use "using OfficeDevPnP.Core;"

@abarpetia
Copy link

abarpetia commented Apr 23, 2020

Hello, I am getting following error at? authManager.GetWebLoginClientContext(siteUrl);

Error CS0012 The type 'Icon' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

and If install System.Drawing.Common package, Getting

"Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral" this error.

Any Idea how to solve this? I am using console app project with VS 2019 Thanks.

**UPDATE
I was using .net Core which is not supported changed to .net 4.7.4

https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/16585795-support-net-core-with-csom

@mantrawadirama
Copy link

I am working on provider hosted app with MFA enabled for SharePoint online. Can you please suggest what are the options for user authentication.

@nirav5884
Copy link

Hello, I am getting following error at? authManager.GetWebLoginClientContext(siteUrl);

Error CS0012 The type 'Icon' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

and If install System.Drawing.Common package, Getting

"Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral" this error.

Any Idea how to solve this? I am using console app project with VS 2019 Thanks.

**UPDATE
I was using .net Core which is not supported changed to .net 4.7.4

https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/16585795-support-net-core-with-csom

Did this solve after changing the .net framework from .net core? Have you developed this in Web or Windows App?

@sigomtesting
Copy link

Yes, you must definitely use a Windows Forms project in .NET Framework 4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment