Forum Discussion
Sunil Guntupalli
May 08, 2018Copper Contributor
Project Online/SharePoint Online "401 Unauthorized" error when accessing oData URLs programatically
Hi All, I couldn't authenticate Project Online oData URLs using the below piece of code in a C# console application. It was working fine till yesterday from past 1 year. SecureString passWord =...
- May 09, 2018
Hi All,
Another work around is to generate a SharePoint client context and then grab the auth cookie from those credentials and pass it to the rest api request.
authCookie = creds.GetAuthenticationCookie()
req.Headers.Add(HttpRequestHeader.Cookie, authCookie);
Let me know if you need more details
Thanks
Dan
Daniel Colarossi
May 09, 2018Copper Contributor
Hi Sunil,
Something has recently changed and you're not alone in this issue. It's been slowly rolling out to tenants this week :(
The issue is isolated to the rest apis, so if you can switch your code over to use the CSOM libraries then it will authenticate correctly.
ProjectContext pc = new ProjectContext(url)
We have escalated to Microsoft, if we hear of anything I'll update this post. Please let us know if you hear anything.
Thanks
Dan
- JOÃO LEITE BRAGANÇAMay 09, 2018Copper Contributor
It is curious you mentioned that things are changing. From last weekend to today (9 May 2018) I am also getting the 'The Remote server returned an error: (401) Unauthorized' System.Net.WebException error, where the detail status tells "ProtocolError". The unmodified, proven-tested and working until today CSOM code I tried to run (repeat: always worked fine) with SharePoint Online was:
ClientContext context = new ClientContext(serverUrl);
SecureString securestringpassw = new SecureString();
foreach (char c in password) { securestringpassw.AppendChar(c); }SharePointOnlineCredentials creds = new SharePointOnlineCredentials(username, securestringpassw);
context.Credentials = creds;
context.RequestTimeout = 60000; // msWeb web = context.Web;
var list = web.Lists.GetByTitle(Library);
context.Load(list.Fields);
context.ExecuteQuery(); // Error 401 hereI really curious on what is going on... Any clues?
Many thanks!
- Joe FedorowiczMay 09, 2018Iron Contributor
I'm seeing something similar with a REST call in a workflow that creates a subsite. Get a "Forbidden."
So it has worked forever, and works on some sites...but not on new ones.
- Daniel ColarossiMay 09, 2018Copper Contributor
Hi All,
Another work around is to generate a SharePoint client context and then grab the auth cookie from those credentials and pass it to the rest api request.
authCookie = creds.GetAuthenticationCookie()
req.Headers.Add(HttpRequestHeader.Cookie, authCookie);
Let me know if you need more details
Thanks
Dan
- JOÃO LEITE BRAGANÇAMay 09, 2018Copper ContributorBut yes, Daniel, your suggestion does work!
Still I am curious on what is going on!