azure - How can I perform unattended oauth / openid authentication to WebAPI? -


imagine client , service application registered in windows azure.

the client console , runs unattended on-premise (e.g. performing tests overnight) service webapi service protected oauth , accessed using openid connect, hosted in azure.

how can client authenticate service without sort of user login interaction (i.e. app authenticates service using adal .net)?

i tried adal .net daemon webapi sample still pops authentication dialog...

thanks!

[edit] here's code show very how communicate client. app ids etc. 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 produces login page html...

i've tried adding [hostauthentication("oauth2bearer")] etc. service api controller , adding in owin startup logic no avail, e.g:

app.usewindowsazureactivedirectorybearerauthentication(     new windowsazureactivedirectorybearerauthenticationoptions     {         tokenvalidationparameters = new tokenvalidationparameters         {             validaudience = myrealm,         },          tenant = "mytenant.onmicrosoft.com",         authenticationtype = bearerauthenticationtype.oauth2bearer,     }); 

edit: re-reading original post, think understand what's going on. mention have openid connect on app, , when hit web api html. suspect openid connect middleware being triggered when hit web api, instead of oauth2 middleware. if case, recommend taking @ http://www.cloudidentity.com/blog/2014/04/28/use-owin-azure-ad-to-secure-both-mvc-ux-and-web-api-in-the-same-project/ instructions on how have redirect-based middleware , oauth2 protected resource middleware coexist on same project.

original answer: have tried https://github.com/azureadsamples/nativeclient-headless-dotnet? should you looking for. sorry terseness, on phone :-) hth v.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -