.net-core - 在 Graph API 中列出组成员的权限不足
问题描述
我正在构建一个由 SPA(角度)调用的 API。用户使用 Azure AD 进行身份验证,API 使用 AzureAdBearer 进行身份验证。
我需要后端代表用户调用图形 api 以列出 AD 组的成员。
根据此文档,我需要以下权限之一:
User.ReadBasic.All, User.Read.All, Group.Read.All, Directory.Read.All
因此,我在后端的应用程序注册中将 User.ReadBasic.All 添加到了我的 api 权限列表中。
我IAuthenticationProvider
使用以下代码处理身份验证:
var app = ConfidentialClientApplicationBuilder.Create("{my client id}")
.WithAuthority("https://login.microsoftonline.com/{my tenant id}")
.WithClientSecret({my backend secret})
.WithLogging(Log, Microsoft.Identity.Client.LogLevel.Info, true)
.Build();
var token = await _httpContextAccessor.HttpContext.GetTokenAsync("access_token");
var userAssertion = new UserAssertion(token);
var result = await app.AcquireTokenOnBehalfOf(new[] { "https://graph.microsoft.com/.default" }, userAssertion)
.ExecuteAsync();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
结果是成功的,当我使用 jwt.ms 检查我的令牌时,一切似乎都是正确的,这是它的摘录:
"aud": "https://graph.microsoft.com",
"iss": "https://sts.windows.net/{my tenant id}/",
[...]
"app_displayname": "My app",
"appid": "{my client id}",
[...]
"scp": "User.ReadBasic.All profile openid email",
[...]
但是在使用 GraphApiClient 的这个调用中:
var client = new GraphServiceClient(authProvider);
var users = await client.Groups["group guid"].Members.Request().GetAsync();
我收到此错误:
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
解决方案
推荐阅读
- css - Bootstrap CSS - 关于调整大小的第 2 列下的第 3 列
- php - 为 Codeigniter 4 创建作曲家包
- dynamics-crm - Business Central 夫妇未同步 CRM 帐户 - Business Central 客户
- flutter - 在 Flutter 上的 TextField 上键入时滚动到顶部
- javascript - 想要为显示的日期列表添加删除功能
- c++ - 在 C++ 中使用 FFmpeg 覆盖视频帧
- android - Java.lang.IllegalStateException:应为 BEGIN_OBJECT,但在要将数据获取到 recyclerview 时为 BEGIN_ARRAY
- react-native - 反应本机 Webview 进程终止
- python - 合并共享属性的节点
- processmaker - 无法将屏幕分配给任务