微软图示 : 获取用户加入哪个组
原标题:Microsoft Graph : get which groups a user is member of
我创建了一个我属于的集团; 我将在我的 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:
相关问题
What is the use of `default` keyword in C#?
What is the use of default keyword in C#?
Is it introduced in C# 3.0 ?
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 ...
ADO.NET Entity Framework Association of Entities by Value Range
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber.
I want to create a many to many association ...
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, ...
What is the most efficient keyvalue pair for ordering?
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
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.
...