我有一个标记为“Public(authenticated)”的Azure API应用程序,并在关联的网关中设置了Azure Active Directory身份,详见Protect an API App。使用ADAL对Azure API应用程序进行身份验证
然后,我在同一个Azure Active Directory租户中创建了本机应用程序,并添加了以委派权限访问网关的权限。
使用ADAL和下面的代码,我能够成功地进行身份验证并获取访问令牌,但我无法弄清楚如何使用它来访问我的API应用程序。
string Tenant = "[xxx].onmicrosoft.com";
string Authority = "https://login.microsoftonline.com/" + Tenant;
string GatewayLoginUrl = "https://[gateway].azurewebsites.net/login/aad";
string ClientId = "[native client id]";
Uri RedirectUri = new Uri("[native client redirect url]");
async Task<string> GetTokenAsync()
{
AuthenticationContext context = new AuthenticationContext(Authority);
PlatformParameters platformParams = new PlatformParameters(PromptBehavior.Auto, null);
AuthenticationResult result = await context.AcquireTokenAsync(GatewayLoginUrl, ClientId, RedirectUri, platformParams);
return result.AccessToken;
}
我测试过的API应用程序手动输入x-zumo-auth header
我在Chrome得到和它的作品的话,但不能与我开始使用ADAL令牌。我也尝试过他们的sample code中描述的浏览器表单,但它并不提供刷新标记。
如何设置我的验证码,以便我的API应用程序可以使用TokenCache
和ADAL?
授权:承载ThisIsTheAccessTokenYouRecievedFromADAL
我有同样的问题。使用ADAL收到的accessToken总是给我一个403:禁止的响应。我已经尝试了Windows控制台.NET客户端和Cordova客户端。两者都是相同的结果。当API应用程序是公共匿名时,没有Probs,但403使用公开身份验证。这个问题你有什么进展吗? – Mark
@Mark我决定延迟使用api网关,直到它得到更好的支持,并使用owin openid和承载认证。这意味着身份验证逻辑回到了api应用程序中,但它起作用。 – jeffaudio