Imagine a client and service application registered in Windows Azure.
The client is a console and runs unattended on-premise (e.g. performing tests overnight) The service is a WebAPI service protected by oAuth and normally accessed using OpenID Connect, hosted in Azure.
How can the client authenticate to the service WITHOUT any sort of user login interaction (i.e. the app authenticates itself to the service using ADAL .Net)?
I tried the ADAL .Net Daemon to WebAPI sample but it still pops up an authentication dialog...
Thanks!
[edit] Here's some code to show very roughly how I communicate from the client. All the app ids etc. are correct.
var authContext = new AuthenticationContext("https://login.windows.net/common");
var result = await authContext.AcquireTokenAsync(ServiceAppId, ClientCredential);
var client = new HttpClient
{
BaseAddress = new Uri("https://localhost:44301/"),
};
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
AuthenticationHeaderScheme.Bearer,
result.AccessToken);
var response = await client.GetAsync("api/something");
var jsonString = response.Content.ReadAsStringAsync().Result;
That just produces login page HTML...
I've also tried adding [HostAuthentication("OAuth2Bearer")]
etc. to the service api controller and adding in OWIN startup logic but to no avail, e.g:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = myRealm,
},
Tenant = "mytenant.onmicrosoft.com",
AuthenticationType = BearerAuthenticationType.OAuth2Bearer,
});