Friday, 21 July 2017

Using CSOM with an account configured with Multi-factor Authentication (MFA)

Here is some quick code I put together for using CSOM with an account which has MFA enabled. It uses the SharePoint PnP Core library which can be found here: https://www.nuget.org/packages/SharePointPnPCoreOnline

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();
}
}
}
view raw CSOM.MFA.cs hosted with ❤ by GitHub
This will give you a prompt to enter your details:

No comments: