【发布时间】:2021-04-17 09:37:57
【问题描述】:
Net 核心应用程序,我正在尝试做一些基于操作的组和用户。下面的代码我有
public async Task<GraphServiceClient> GetGraphApiClient()
{
var credentials = new ClientCredential(_authenticationConfig.ClientId, _authenticationConfig.ClientSecret);
var authContext = new AuthenticationContext("https://login.microsoftonline.com/mytenantid");
var token = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", credentials);
var accessToken = token.AccessToken;
var graphServiceClient = new GraphServiceClient(
new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.CompletedTask;
}));
return graphServiceClient;
}
我正在尝试如下查询
GraphServiceClient graphClient = await _myRepository.GetGraphApiClient();
var user = await graphClient.Me.Request().GetAsync();
这是抛出异常。
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
我还在我的 azure 广告应用中设置了所需的权限。我附上了截图。 此外,我也已授予管理员同意。有人可以帮助我在这里缺少什么吗?任何帮助将不胜感激。谢谢
【问题讨论】:
-
谢谢。请问我为什么要更改申请权限?哦,对了,没有我,即使我也这么想。我可以尝试列出所有组吗?
-
如果你想使用
/me端点,你应该确保使用用户名和密码进行身份验证,而不是clientId/clientSecret。 -
嗨 Nsevens,请确认我是否必须使用应用程序或委派权限?
-
不需要用户认证。
-
@Shiva 说的是正确的。
标签: azure asp.net-core azure-active-directory microsoft-graph-api