Calling Azure service from Project Online with current project context RRS feed

  • Question

  • We have created an Azure web service in which we have written functions using CSOM custom code to get and update project tasks. We are calling the service from Project online PDP page to get the project tasks.

    As we cannot send the ProjetcCOntext directly from javascript being used in page, we are trying to set the context using access token, mainly following this link 

    Following the above link we created the accesstoken and passing it from PDP page to Azure Service method. The access token is passed to the web service function to get project tasks.

    In the Azure REST service function, we are creating project context using the access token with the code below

    public static ProjectContext GetProjectContextWithAccessToken(string targetUrl, string accessToken)


                Uri targetUri = new Uri(targetUrl);

                ProjectContext projectContext = new ProjectContext(targetUrl);

                projectContext.AuthenticationMode = ClientAuthenticationMode.Anonymous;

                projectContext.FormDigestHandlingEnabled = false;

                projectContext.ExecutingWebRequest +=

                    delegate (object oSender, WebRequestEventArgs webRequestEventArgs)


                        webRequestEventArgs.WebRequestExecutor.RequestHeaders["Authorization"] =

                            "Bearer " + accessToken;


                return projectContext;


     The above code created the context successfully but while querying the projects data we get 0 projects. Please refer below code

                projectContext = TokenHelper.GetProjectContextWithAccessToken(pwaPath, accesstoken);

                projectContext.Load(projectContext.Projects, ps => ps.Include(p => p.Id, p => p.Name));


                var project = projectContext.Projects.First(p => p.Id == new Guid(projectId));

    Whereas same user when used in CSOM context using below code, we get 11 projects which are of current users.

    var projectContext1 = new ProjectContext(pwaPath);

                projectContext1.Credentials = new SharePointOnlineCredentials(pwaUserName, secpassword);

                projectContext1.Load(projectContext1.Projects, ps => ps.Include(p => p.Id, p => p.Name));


                var project = projectContext1.Projects.First(p => p.Id == new Guid(projectId));

    Any help would be appreciated. This is becoming a show stopper for one of our application and urgent to resolve.

    Monday, March 26, 2018 6:26 AM