I get error 401 (or 403) when trying to connect to Project Online with CSOM in a console app. (This is not on-premise. It is Microsoft Project Online 2013.) Here is the code.
ProjectContext projContext = new ProjectContext(pwaPath); projContext.Credentials = new NetworkCredential("myUserID", "mypwd", "xxx.onmicrosoft.com"); projContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(projContext_ExecutingWebRequest); projContext.Load(projContext.Projects); projContext.ExecuteQuery(); // Error 401 Unauthorized static void projContext_ExecutingWebRequest(object sender, WebRequestEventArgs e) { e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); }
And another try, without ExecutingWebRequest:
ProjectContext projContext = new ProjectContext(pwaPath); projContext.Credentials = new NetworkCredential("myUserID", "mypwd", "xxx.onmicrosoft.com"); projContext.Load(projContext.Projects); projContext.ExecuteQuery(); // Error 403 Forbidden
Q1: Are there any problems with the code?
Q2: Is there a setting in Project Online that I'm missing?
ScoutwestInc