【发布时间】:2020-02-05 18:46:30
【问题描述】:
我已经在 Azure AD 中注册了一个本机应用程序并授予所有委托访问图形 API 的权限。我正在尝试使用控制台解决方案 (exe) 测试此解决方案,其中包含以下代码,该代码使用客户端 ID 和密码
private static async void AcquireTokenAsync() {
AuthenticationContext context = new AuthenticationContext("https://login.windows.net/xxxxxx-xxxx-485b-a40f-xxxxxxxx/oauth2/token", true);
var result = await context.AcquireTokenAsync("https://graph.microsoft.com",
new ClientCredential("xxxxxx-32cf-xxxx-8888-555555555555",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxV89cWfH0w="
)
);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + result.AccessToken);
HttpResponseMessage response = await client.GetAsync("https://graph.microsoft.com/v1.0/users/");
string retResp = await response.Content.ReadAsStringAsync();
string token = result.AccessToken;
Console.WriteLine(token + "\n" + restResp);
}
检索令牌没有问题。我正在获取访问令牌,但在使用令牌的图形 api 调用中出现以下错误/响应
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "cb7aaaa9-d9a0-485a-7777-b5bfe68ba771",
"date": "2017-07-22T11:01:49"
}
}
}
请提出问题所在
【问题讨论】:
标签: azure azure-active-directory microsoft-graph-api azure-ad-graph-api