【发布时间】:2021-02-13 01:54:10
【问题描述】:
我已将 Web 应用程序部署到 Azure 应用服务并设置应用服务身份验证以使用 Active Directory。
在控制台应用程序中,我有以下代码。
string baseUrl = "https://testapp.azurewebsites.net/Admin/GetCustomers";
string sAuthority = "https://login.microsoftonline.com/{tennant ID}“;
string sClient = “{“Client ID};
string sClientSecret = “{“ClientSecret};
IConfidentialClientApplication app;
app = ConfidentialClientApplicationBuilder.Create(sClient)
.WithClientSecret(sClientSecret)
.WithAuthority(new Uri(sAuthority))
.Build();
string[] scopes = new string[] { "https://testapp.azurewebsites.net/Admin/.default" };
AuthenticationResult result = null;
result = app.AcquireTokenForClient(scopes).ExecuteAsync().Result;
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = httpClient.GetAsync(baseUrl).Result;
if (response.IsSuccessStatusCode)
{
string json = response.Content.ReadAsStringAsync().Result;
JObject resultData = JsonConvert.DeserializeObject(json) as JObject;
Console.WriteLine("Finished Loading Data!");
}
else
{
Console.WriteLine("Error Happened");
}
根据您的指南,我在 ActiveDirectory 中注册了 2 个应用程序
- 服务器应用程序具有公开的 API https://testapp.azurewebsites.net/Admin/ 范围为 GetCustomers
- Web URI - https://testapp.azurewebsites.net/auth-response 和 https://testapp.azurewebsites.net
客户端应用对此范围有权限 作为管理员,我授予它并创建了一个 ClinetSecret
我忘了做什么? 史蒂夫
【问题讨论】:
标签: c# azure microsoft-identity-platform