Is there a way to use the Project CSOM from a server side event receiver using an implicit identity?

Copper Contributor

I have a server side event receiver to handle publishing events, and I need to set a Project scoped enterprise custom field when a project is published.


I thought I would be able to use the Project CSOM to connect to Project Server to get this done. All of the examples I can find for using Project CSOM set the projectCtx.Credentials to a SharePointOnlineCredentials object.  I'm working on-prem, so I thought the code would be executed using the implicit identity of the user who triggered the event, the way that SharePoint event receivers work, so I never set the credentials.


It seems I was wrong about that, because I keep getting 403 - Forbidden errors when I try and do anything after creating the ProjectContext.


Is there a way to either create a credential object that the ProjectContext will accept out of stuff I have access to from within the event receiver (without a password), or tell the ProjectContext that it should use the identity of the user who triggered the event?


I can get the SPUser object of the user who triggered the event because the PSLib.PSContextInfo passed in to the event receiver has the site ID and the user login name, so I could do something like



using (SPSite site = new SPSite(contextInfo.SiteGuid))
    SPUser user = site.RootWeb.SiteUsers[contextInfo.UserName];

    using (ProjectContext prjCtx = new ProjectContext(site.Url))
        // can i do something with the SPUser object here?



What can I do to to get the ProjectContext to work without requiring a password to make a credential object?

0 Replies