我有一個標記爲「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