我有两个不同的Web API应用程序(web-api-app1
和web-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-app2
调用web-api-app1
(web API调用web API调用)。我怎么做?谢谢!
你需要实现on-behalf-of(docs for v1 endpoints)流程。
app1
应使用在用户身份验证时获取的自己的访问令牌向app2
请求访问令牌。
app1
的清单应包括访问app2
的许可。
如果应用程序位于不同的租户中,app2
应首先由app1
租户管理员同意。