Forum Discussion

Jack_Le_Syn's avatar
Jack_Le_Syn
Copper Contributor
Apr 01, 2020

How to traverse SharePoint site collection with Multi Factor Authentication (MFA) enabled?

I have a Winforms app that displays a SharePoint site collection and document libraries in a TreeView control with hierarchy according to the site level.

I use the following code for account with MFA enabled

 

 

AuthenticationManager authManager = new AuthenticationManager();            
            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));
                clientContext.ExecuteQuery();
                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));
                clientContext.ExecuteQuery();
                documentLibraries = libraries.Where(lib => lib.BaseType == BaseType.DocumentLibrary && lib.Hidden == false && lib.BaseTemplate == 101).ToList();
            }

 

 

The team site URL will be added to each TreeNode in my TreeView, whenever user clicks on a TreeNode, it will need to load the sub-sites and document libraries using the above method. However, every time it loads, the pop up shows and disappears because user is already logged in. Is there anyway to prevent it popping up every single time user clicks on the site TreeNode?

  • What about not using user and password to connect to SPO? You could connect as an App so you could avoid MFA
    • Jack_Le_Syn's avatar
      Jack_Le_Syn
      Copper Contributor
      This program is for end-users to connect to their SP environments. Can "Connecting as an App" work?
    • Jack_Le_Syn's avatar
      Jack_Le_Syn
      Copper Contributor
      Btw, the end-users will connect to their OWN SP environments, not ours. So with the app-only flow, I don't think it will work for others' SP environments

Resources