azure - Azure AAD - 本地服务的应用程序代理
问题描述
我一直在尝试使用应用程序代理从 Azure 中的另一个 Api 调用本地 Api。我已经按照下面列出的几个示例进行了操作,结果相似。我可以成功获取访问令牌,但是当我通过应用代理对本地 Api 进行 http 调用时,即使我添加了带有承载令牌的授权标头,我总是会被重定向到登录页面。有人对我可能缺少的东西有想法吗?
这是我正在运行的代码,它是从引用的示例中复制而来的。我不是 100% 了解的一件事是 todoListResourceId 和 todoListBaseAddress。我将它们设置为相同的值,即配置的应用程序代理应用程序的“主页 URL”。
AuthenticationContext authContext;
private static string aadInstance = "https://login.microsoftonline.com/{0}";
private static string tenant = "xxx.onmicrosoft.com";
private static string clientId = "my app id";
Uri redirectUri = new Uri("http://replyurl");
private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
private static string todoListResourceId = "https://xxx.msappproxy.net";
private static string todoListBaseAddress = "https://xxx.msappproxy.net";
private async void GetTodoList()
{
AuthenticationResult result = null;
HttpClient httpClient = new HttpClient();
authContext = new AuthenticationContext(authority);
result = await authContext.AcquireTokenAsync(todoListResourceId, clientId, redirectUri, new PlatformParameters(PromptBehavior.Auto));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
// Call the To Do list service.
HttpResponseMessage response = await httpClient.GetAsync(todoListBaseAddress + "/api/values/4");
//MessageBox.Show(response.RequestMessage.ToString());
string s = await response.Content.ReadAsStringAsync();
MessageBox.Show(s);
}
解决方案
推荐阅读
- html - 如何使用 Bootstrap 在页面上垂直和水平居中卡片元素?
- android - Admob 插页式广告自动关闭
- jquery - 无法用逗号和点格式化数字
- javascript - 在原生 JS 上以不同的方式调用函数
- javascript - Air Datepicker 中的英语
- c# - 在 nancy 自托管中创建动态内容
- visual-studio - unity Character Controller 尝试完成流畅的移动和跳跃
- javascript - 如何使用 javascript 从页面代码中获取值?
- google-apps-script - 如何在我的 google-apps-script 中使用动态变量创建 QUERY 函数
- security - wasm 存储客户端机密是否安全?