none
Programmatically login to Project Server 2013. RRS feed

  • Question

  • Hi,

    We are facing problems in programmatically login to Project Server 2013. 

    We have a PWA instance at port 8006. When we use only Windows Authentication we r able to connect to Project Server , Authenticate , create projects , read them successfully using the below code.

    private static ProjectContext projContext = new ProjectContext(pwaPath);
    
    projContext.Credentials = new NetworkCredential("msps_demouser3", "123+Infy", "ITLINFOSYS");

    We tried several combinations to login programmatically 

    //projContext.Credentials = new NetworkCredential("i:0#.f|SQL-Membership|mspsdemouser3", "zmy9t4NXjpaG9HM","SQL-Membership"); 
    
     //projContext.Credentials = new NetworkCredential("i:0#.f|SQL-Membership|mspsdemouser3", "zmy9t4NXjpaG9HM");
    
    //projContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("i:0#.f|SQL-Membership|mspsdemouser3", "zmy9t4NXjpaG9HM");

    None of them works. Each one of them gives 403 Forbidden error at the line ExecuteQuery() method ( code shown below)

    projContext.Load(projContext.Projects); 
    projContext.ExecuteQuery();  

    We have extended that web application to port 8007 which has only forms authentication enabled. So we need to be able to make this code work using Forms based user.

    But we need to make this functionality work using Forms Based Authentication. From the front end we are able to login as a Forms user but from the code we are not able to login into Project Server. We are getting 403 Forbidden error. 

    Even when we use only Forms Based Authentication we are getting same 403 Error and run code using credentials of a Forms user. When we enable both Windows and Forms Authentication we get 403 Error. Only when we have only Windows Authentication enabled we are able to run the code successfully using the credentials of an Active Directory user.

    Please tell us where we are going wrong. Is the format of providing credentials is wrong ?

    Thursday, December 26, 2013 10:42 AM

All replies

  • HI Rizwan,

    You have to call your PSI within OperationContextScope, it is required only for applications that run in a multiple authentication environment. If Project Server uses only Windows authentication, it is not necessary to set a scope and add a web request header that disables Forms authentication. For example as mentioned below.

    private bool isWindowsUser = true;
    
    public void DisableFormsAuth(bool isWindowsAuth)
    {
        WebOperationContext.Current.OutgoingRequest.Headers.Remove(
            "X-FORMS_BASED_AUTH_ACCEPTED");
    
        if (isWindowsAuth)
        {
            // Disable Forms authentication, to enable Windows authentication.
            WebOperationContext.Current.OutgoingRequest.Headers.Add(
                "X-FORMS_BASED_AUTH_ACCEPTED", "f");
        }
    }
    
    private void WcfSample()
    {
        // Limit the scope of WCF calls to the client channel. 
        using (OperationContextScope scope = new OperationContextScope(projectClient.InnerChannel))
        {
            // Add a web request header to enable Windows authentication in 
            // multiple authentication installations.
            DisableFormsAuth(isWindowsUser);
    
            // Add calls to the projectClient methods here:
            // . . .
        }
    }

    For further detail on prerequisites for developing Project Server custom application please go thorough this article


    Sachin Vashishth MCTS

    Friday, December 27, 2013 10:58 AM
  • Thanks Sachin.

    But our problem is thta we want to make the code work using only Forms Based Authentication. We are not supposed to use Windows Authentication as per the requirements. 

    In that case how would we proceed. Any pointers would be of great help.

    Regards

    Rizwan Shaikh.

    Friday, December 27, 2013 11:13 AM
  • Rizwan,

    Have you tried by putting isWindowsAuth flag false. In this case The above method  "DisableFormsAuth" will remove any header value that previously disabled Forms authentication, so that Forms authentication can proceed.

    Please try and let me know in case still face any issue.


    Sachin Vashishth MCTS

    Friday, December 27, 2013 5:25 PM