English 中文(简体)
微软图示 : 获取用户加入哪个组
原标题:Microsoft Graph : get which groups a user is member of
  • 时间:2023-08-17 09:21:45
  •  标签:
  • c#
  • azure
我创建了一个我属于的集团; 我将在我的 C# app 和 MS Grap API 中获取该组 : 客户端安全 客户端安全 身份证明 = 新的客户端安全 身份证明( 租赁、 客户端用户端用户端用户端、 客户端用户端用户端、 客户端安全 ) ; 我已创建了一个我属于的组; 我将创建一个我属于的组; 我将在 C# app 和 MS 图 API 中获得该组的组 ; 我将获得该组的组 = 等待图形用户端点 。 GetAsync ( 请求 Configisation { 请求 Configriation. QueryParamets. Filter = " mail equalent InternetronmentalTest365@ kh.se " ; ; filter = " mail DescregardName and Mail ", 我得到了正确的组。 但是, 成员收藏是无效的。 AAAAD有几张 APPI AP授权, 例如. Read.
问题回答
I have one Azure AD group named Demo with below group members: When I ran below graph query in Graph Explorer by filtering with mail, I too got null results for members: GET https://graph.microsoft.com/beta/groups?$filter=mail+eq+ demo@xxxxxxxxx.onmicrosoft.com +&$select=displayName,mail,members Response: Note that, you need to use $expand parameter in the query to get members of group. To confirm that, you can check this MS Doc for reference. When I ran below modified query by including $expand parameter, I got group members too in response like below: GET https://graph.microsoft.com/beta/groups?$filter=mail+eq+ demo@xxxxxxxxx.onmicrosoft.com +&$select=displayName,mail,members&$expand=members($select=id,displayName) Response: To get the same via code, I registered one Azure AD application and granted below API permissions in it: Now, I ran below c# code to get group members Ids in the response like below: using Azure.Identity; using Microsoft.Graph; using Microsoft.Graph.Models; using Microsoft.Kiota.Abstractions; using Microsoft.Graph.Models.ODataErrors; using System; var scopes = new[] { "https://graph.microsoft.com/.default" }; var clientId = "appId"; var tenantId = "tenantID"; var clientSecret = "secret"; var options = new ClientSecretCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud, }; var clientSecretCredential = new ClientSecretCredential( tenantId, clientId, clientSecret, options); var graphClient = new GraphServiceClient(clientSecretCredential, scopes); try { var result = await graphClient.Groups.GetAsync((requestConfiguration) => { requestConfiguration.QueryParameters.Filter = "mail eq demo@M365x56209219.onmicrosoft.com "; requestConfiguration.QueryParameters.Select = new string[] { "displayName", "mail", "members" }; requestConfiguration.QueryParameters.Expand = new string[] { "members" }; }); Console.WriteLine("Group info:"); foreach(var group in result.Value) { Console.WriteLine(group.DisplayName); Console.WriteLine(group.Mail); Console.WriteLine(" Group Members:"); foreach (var member in group.Members) { Console.WriteLine(member.Id); } } } catch (ODataError odataError) { Console.WriteLine(odataError.Error.Code); Console.WriteLine(odataError.Error.Message); } Response:




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签