簡體   English   中英

Azure Active Directory:Web API調用另一個Web API

[英]Azure Active Directory: web api call another web api

我有兩個不同的Web API應用程序( web-api-app1web-api-app2 )與Azure Active Directory身份驗證集成在一起。

我可以使用某些控制台應用程序分別調用這兩個API應用程序:

AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/[AD Tenent]");

var clientCredentials = new ClientCredential("app id", "app key");
AuthenticationResult ar = ac.AcquireTokenAsync("https://web-api-app1", clientCredentials).Result;

string result = string.Empty;

HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ar.AccessToken);

HttpResponseMessage response = httpClient.GetAsync("https://web-api-app1/odata").Result;

if (response.IsSuccessStatusCode)
{
    result = response.Content.ReadAsStringAsync().Result;
}

Console.WriteLine(result);

現在,我的要求是我需要從web-api-app1 (從Web API調用到Web API調用)調用web-api-app2 我怎么做? 謝謝!

您需要實現 比例(v1端點的文檔 )流。

app1應該使用通過用戶身份驗證獲取的自己的訪問令牌向app2請求訪問令牌。

app1清單應包括訪問app2權限。

如果應用程序位於不同的租戶中,則應首先由app1租戶管理員同意app2

官方.net示例應用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM