Microsoft Graph 获取显示名称的群组列表

huangapple go评论52阅读模式
英文:

Microsoft Graph Get list of groups with display name

问题

I need to return DisplayName as well as the id, how do I do this? 我需要同时返回DisplayName和ID,我该怎么做?

英文:

I am trying to get the group membership of a service principal using client credential flow. I have the following code:

var graphServiceClient = new Microsoft.Graph.GraphServiceClient(new Microsoft.Graph.DelegateAuthenticationProvider(async (requestMessage) =>
{
     var authResult = await _confidentialClientApp.AcquireTokenForClient(new string[] { "https://graph.microsoft.com/.default" }).ExecuteAsync();
     requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
}));

var groupMembership = await graphServiceClient.ServicePrincipals[userData.UniqueId].MemberOf.Request().GetAsync();

This returns:
groupMembership.CurrentPage[0].Id but none of the other properties are filled including the one I am interested in groupMembership.CurrentPage[0].DisplayName

I need to return DisplayName as well as the id, how do I do this?

答案1

得分: 0

解决方法是给应用程序注册授予Group.Read.All权限,然后显示名称将填充在groupMembership中。

英文:

It turns out the solution was to give the app registration the permission of Group.Read.All and then display name was populated in groupMembership

huangapple
  • 本文由 发表于 2023年4月6日 19:05:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75948795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定