首页 > 解决方案 > 多因素认证获取Sharepoint ClientContext后如何获取ProjectContext?

问题描述

对于启用了 MFA 的客户端,我想通过 CSOM/C# 与 Project Onine 进行交互。通过下面的代码片段,我可以通过我认为的共享点 MFA(调试器通过这些行),但是我如何获得 Project Online 的上下文?强制转换失败(我想我从错误消息中理解为什么),那我该怎么办?

private static bool GetMultiFactorAuthCookie(string pwaPath)
{
    bool error = false;
    var authManager = new AuthenticationManager();
    ClientContext sharepointClientContext = authManager.GetWebLoginClientContext(pwaPath);

    web = sharepointClientContext.Web;
    user = web.CurrentUser;

    sharepointClientContext.Load(web);
    sharepointClientContext.Load(user);
    sharepointClientContext.ExecuteQuery();

    ProjectContext projContext = sharepointClientContext.CastTo<ProjectContext>(sharepointClientContext);

    return !error;
}

调试器告诉我

无法从“Microsoft.SharePoint.Client.ClientContext”转换为“Microsoft.SharePoint.Client.ClientObject”

标签: c#console-applicationcsommulti-factor-authenticationproject-online

解决方案


推荐阅读