Console App for Sharepoint Online with MFA turned on.

Console App for Sharepoint Online with MFA turned on.

Customers suggesting a deployment on a Friday (click for credit)

First, I couldn’t write the title until I got to a) the correct example online, then b) the proper credentials (a work-mate(s) hinted towards the answer) and c) the exact exception text “The sign-in name or password does not match one in the Microsoft account system.”

Sharepoint – as usual … SUPER FOR CONTRACTORS WHO GET PAID THE HOUR. (argggg).

First – do NOT use .net Core – use .net 7.7.x or 4.8. As a last ditch effort – I used this and boom all my previous experiments worked. FINALLY Success. Read the next paragraph and do NOT get fooled by the word “Core” in the needed NuGET package SharepointPNPCoreOnline .

Second – include the NuGet package SharepointPNPCoreOnline

A buddy and I found the main links together while screen sharing. I thank him for the head start – next was the MFA. A colleague hinted that our username is NOT first.last@mycompany.com but first.last@sharepointfrontpart.onmicrosoft.com so all this together and some google-fu and we have a solution!

Then here is your .NET class. I am sure there is a .NetCore solution – but at this point – I am happy to have gotten a context 🙂

using System;
using Microsoft.SharePoint.Client;
using System.Security;

namespace ConsoleAppSP_Net1
{
    class Class1
    {
        public string site_url = "https://joescompanyonline.sharepoint.com/sites/BEST-SITE-EVER/";
        
        public void try2_THIS_ONE_WORKS_FOR_MFA()
        {

            var authenticationManager = new OfficeDevPnP.Core.AuthenticationManager();

            ClientContext context = authenticationManager.GetWebLoginClientContext(site_url, null);

            Web web = context.Web;
            User user = web.CurrentUser;
            context.Load(web);
            context.Load(user);
            context.ExecuteQuery();
            Console.WriteLine(web.Title);
            Console.WriteLine(user.LoginName);
            Console.ReadLine();

        }
     }
}

So in order of thanks – here are the links

https://www.c-sharpcorner.com/article/connect-to-sharepoint-online-in-office-365-using-console-application/

https://knowledge-junction.com/2017/12/24/office-365-connecting-to-sharepoint-online-site-using-csom-when-multi-factor-authentication-mfa-is-enabled-for-the-user/

https://social.msdn.microsoft.com/Forums/en-US/c001d13c-3c25-40f1-9993-a3698d9b3639/sharepoint-online-mfa-csom-the-signin-name-or-password-does-not-match-one-in-the-microsoft?forum=sharepointdevelopment

https://www.c-sharpcorner.com/article/authenticate-sharepoint-using-pnp-authentication-manager/

https://github.com/pnp/PnP-Sites-Core/

https://social.msdn.microsoft.com/Forums/en-US/c001d13c-3c25-40f1-9993-a3698d9b3639/sharepoint-online-mfa-csom-the-signin-name-or-password-does-not-match-one-in-the-microsoft?forum=sharepointdevelopment

Here is a link that I goes through all the authentications and why you might want to use them.

https://www.c-sharpcorner.com/article/authenticate-sharepoint-using-pnp-authentication-manager/

https://csharp.hotexamples.com/examples/OfficeDevPnP.Core/AuthenticationManager/-/php-authenticationmanager-class-examples.html

ELB Solutions.com Inc.
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.