I make a
Winforms Program that allows users to connect to their own SharePoint Online environments to download and upload files from their document libraries. I am using the code below to get
List Objects. My current problem with this method is that a login window appears every time it is called (by
GetWebLoginClientContext Method) and disappears because the user would have been logged in from the beginning. I need to use this method because it works with accounts that have multi-factor authentication enabled.
Is there any other way to log in to SPO with MFA enabled without having to see the popup every time it needs to be loaded?
I've read about app-only authentication with client ID and client secret, but it only works with the SP site that creates the ID and secret.
private void GetSitesAndLists(string siteUrl, out Dictionary teamSites, out List
using (ClientContext clientContext = _authManager.GetWebLoginClientContext(siteUrl))
Web web = clientContext.Web;
WebCollection site = web.GetSubwebsForCurrentUser(null);
clientContext.Load(site, we => we.Include(w => w.Url, w => w.Title));
teamSites = site.ToDictionary(w => w.Url, w => w.Title);
teamSites = teamSites.OrderBy(kvp => kvp.Value).ToDictionary(k => k.Key, k => k.Value);
ListCollection libraries = web.Lists;
clientContext.Load(libraries, l => l.Include(li => li.DefaultViewUrl, li => li.BaseType, li => li.Title, li => li.BaseTemplate, li => li.Hidden));
documentLibraries = libraries.Where(lib => lib.BaseType == BaseType.DocumentLibrary && lib.Hidden == false && lib.BaseTemplate == 101).ToList();