Winforms 如何在启用多因素身份验证(MFA)的情况下遍历SharePoint网站集?

Winforms 如何在启用多因素身份验证(MFA)的情况下遍历SharePoint网站集?,winforms,sharepoint-online,multi-factor-authentication,Winforms,Sharepoint Online,Multi Factor Authentication,我有一个Winforms应用程序,它在TreeView控件中显示SharePoint网站集和文档库,并根据网站级别设置层次结构 对于启用MFA的帐户,我使用以下代码 AuthenticationManager authManager = new AuthenticationManager(); using (ClientContext clientContext = authManager.GetWebLoginClient

我有一个Winforms应用程序,它在
TreeView
控件中显示SharePoint网站集和文档库,并根据网站级别设置层次结构

对于启用MFA的帐户,我使用以下代码

            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();
            }

团队站点URL将添加到my
TreeView
中的每个
TreeNode
,每当用户单击
TreeNode
,它都需要使用上述方法加载子站点和文档库。但是,每次加载时,弹出窗口都会显示并消失,因为用户已经登录。是否有任何方法可以防止用户每次单击网站
TreeNode
?您可以使用应用程序身份验证


我可以在哪个命名空间中找到
TokenHelper
?My Resharper会自动添加没有上述方法的Microsoft Graph客户端命名空间。它是否可以与启用MFA的Sharepoint Online帐户一起使用?
//Get the realm for the URL
                string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);

                //Get the access token for the URL.  
                //   Requires this app to be registered with the tenant
                string accessToken = TokenHelper.GetAppOnlyAccessToken(
                    TokenHelper.SharePointPrincipal,
                    siteUri.Authority, realm).AccessToken;

                //Get client context with access token
                using (var clientContext =
                    TokenHelper.GetClientContextWithAccessToken(
                        siteUri.ToString(), accessToken))
                {