Skip to content

Instantly share code, notes, and snippets.

@vman

vman/CSOM.MFA.cs

Last active Feb 23, 2021
Embed
What would you like to do?
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();
}
}
}
@vman

This comment has been minimized.

Copy link
Owner Author

@vman vman commented Jul 15, 2017

OfficeDevPnP.Core.AuthenticationManager is part of the PnP Core Library available here: https://www.nuget.org/packages/SharePointPnPCoreOnline

mfa gist

@shaipetel

This comment has been minimized.

Copy link

@shaipetel shaipetel commented Feb 3, 2020

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

@ksuresh1988

This comment has been minimized.

Copy link

@ksuresh1988 ksuresh1988 commented Mar 31, 2020

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

@abarpetia

This comment has been minimized.

Copy link

@abarpetia 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

This comment has been minimized.

Copy link

@mantrawadirama mantrawadirama commented Aug 26, 2020

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

This comment has been minimized.

Copy link

@nirav5884 nirav5884 commented Feb 23, 2021

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?

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