0

I'm trying to access the REST api calls from an external application on my local machine, the SharePoint instance is hosted in AZURE, not SP Online.

I've followed numerous blogs stating that I need a token issued via calling the /contentinfo route first, however, this also gives me a 401 Unauthorized.

I've Googled, Stackoverflow'd, tried numerous blogs on the topic and it just does not seem possible. From my understanding is that the REST api's where added specifically so that iOS / Android apps could interact with SharePoint, so building an application outside of the installation of SharePoint would seem possible?

Here's a snippet I tried, based on what I've Googled. I have tried using the WebClient but this does not work either:

var request = (HttpWebRequest)HttpWebRequest.Create("http://sharepoint-tyrano.northeurope.cloudapp.azure.com/_api/contextinfo");

request.Method = "POST";
request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";
request.ContentLength = 0;
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(@"tyrano\apitest: ThisisacerysecurePwd123"));
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

var response = request.GetResponse();

This is called from within the home controller's Index() action, just as a simple test run. I've also tried to get this going on my local inside a console application and still 401.

I've added this user under the user policy for the web application with Full Read, in Central Admin, but still nothing.

Any ideas why this will fail?

1 Answer 1

0

You'll have to have the code provide credentials to the code (via secure store, pulled from a web config, part of the code, etc) as the system executing code a default credentials on behalf of someone else is considered a double hop and isn't allowed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.