401 when calling Azure website programmatically

814 views Asked by At

I have an Azure website running with active directory enabled. I am able to log in to the website just fine with various accounts by going through the Azure login page.

I get a 401 when attempting to call an API on that website from a .net client with any account I try.

var request = WebRequest.Create(url);

request.Method = "GET";
request.Credentials = new NetworkCredential("[email protected]", "password");
request.GetResponse();

Is there a way to hit the website without going through the actual azure login page?

1

There are 1 answers

0
theadriangreen On BEST ANSWER

You're going to have to use an Azure Active Directory Authentication Library (ADAL). See https://msdn.microsoft.com/en-us/library/azure/dn151135.aspx

See for example the code samples on Web Application to Web API. This one looks like it would be useful for your application: https://github.com/AzureADSamples/WebApp-WebAPI-OAuth2-UserIdentity-Dotnet