Bram de Vries
Bram de Vries

Reputation: 21

How to get the ProjectContext after acquiring a Sharepoint ClientContext through multi factor authentication?

I would like to interact with Project Onine through CSOM/C#, for a client which has MFA enabled. With the snippet below I can get through the sharepoint MFA I think (the debugger progresses past those lines), but how then do I get the context for Project Online? The cast to fails (and I think I understand why, from the error message), so what should I do then?

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

The debugger tells me

cannot convert from 'Microsoft.SharePoint.Client.ClientContext' to 'Microsoft.SharePoint.Client.ClientObject'

Upvotes: 2

Views: 626

Answers (0)

Related Questions