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/authenticate-sharepoint-using-pnp-authentication-manager/
https://github.com/pnp/PnP-Sites-Core/
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/