Microsoft Graph - Memberof 字段为空
Microsoft Graph - Memberof fields are null
我试图在 C# 中获取用户所属的组。为此,我一直在使用 /memberOf 端点,如下所示:
public async Task<IUserMemberOfCollectionWithReferencesPage> Test()
{
var graphClient = GetGraphClient(config);
return await graphClient
.Users["user@contoso.com"]
.MemberOf
.Request()
.GetAsync();
}
获取图形客户端函数是:
public static GraphServiceClient GetGraphClient(Config config)
{
var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
// get an access token for Graph
var accessToken = GetAccessToken(config).Result;
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
return graphClient;
}
问题是响应只是:
[
{
"deletedDateTime":null,
"id":"48215c29-5442-4fbe-b6b4-ce3e1b09157a",
"oDataType":"#microsoft.graph.group",
"additionalData":{
"deletedDateTime":null,
"classification":null,
"createdDateTime":null,
"creationOptions":[
],
"description":null,
"displayName":null,
"expirationDateTime":null,
"isAssignableToRole":null,
"mail":null,
"mailEnabled":null,
"mailNickname":null,
"membershipRule":null,
"membershipRuleProcessingState":null,
"onPremisesDomainName":null,
"onPremisesLastSyncDateTime":null,
"onPremisesNetBiosName":null,
"onPremisesSamAccountName":null,
"onPremisesSecurityIdentifier":null,
"onPremisesSyncEnabled":null,
"preferredDataLocation":null,
"preferredLanguage":null,
"renewedDateTime":null,
"resourceBehaviorOptions":[
],
"resourceProvisioningOptions":[
],
"securityEnabled":null,
"securityIdentifier":null,
"theme":null,
"visibility":null
}
}
]
该应用拥有以下权限:
Directory.AccessAsUser.All
User.Read.All
User.ReadWrite.All
UserAuthenticationMethod.Read.All
UserAuthenticationMethod.ReadWrite.All
Directory.Read.All
Directory.ReadWrite.All
Group.Read.All
GroupMember.Read.All
User.Read
我使用的所有其他端点、增量、用户、订阅都按预期工作,但由于未知原因,它们与 /memberOf 为空。
我真的希望你们能帮助我,我做错了什么,因为我已经用头撞墙太久了:)。
提前致谢。
要获取用户 MemberOf,请在下面的示例中使用下面的查询
var result = await graphClient.Users[upn].MemberOf .Request() .GetAsync();
使用页面迭代器获取所有目录对象
protected async Task<List<T>> GetAllPagesAsType<T>(
GraphServiceClient graphClient,
ICollectionPage<DirectoryObject> page) where T : class
{
var allItems = new List<T>();
var pageIterator = PageIterator<DirectoryObject>.CreatePageIterator(
graphClient, page,
(item) => {
// This code executes for each item in the
// collection
if (item is T)
{
// Only add if the item is the requested type
allItems.Add(item as T);
}
return true;
}
);
await pageIterator.IterateAsync();
return allItems;
}
请参考此示例
我试图在 C# 中获取用户所属的组。为此,我一直在使用 /memberOf 端点,如下所示:
public async Task<IUserMemberOfCollectionWithReferencesPage> Test()
{
var graphClient = GetGraphClient(config);
return await graphClient
.Users["user@contoso.com"]
.MemberOf
.Request()
.GetAsync();
}
获取图形客户端函数是:
public static GraphServiceClient GetGraphClient(Config config)
{
var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
// get an access token for Graph
var accessToken = GetAccessToken(config).Result;
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
return graphClient;
}
问题是响应只是:
[
{
"deletedDateTime":null,
"id":"48215c29-5442-4fbe-b6b4-ce3e1b09157a",
"oDataType":"#microsoft.graph.group",
"additionalData":{
"deletedDateTime":null,
"classification":null,
"createdDateTime":null,
"creationOptions":[
],
"description":null,
"displayName":null,
"expirationDateTime":null,
"isAssignableToRole":null,
"mail":null,
"mailEnabled":null,
"mailNickname":null,
"membershipRule":null,
"membershipRuleProcessingState":null,
"onPremisesDomainName":null,
"onPremisesLastSyncDateTime":null,
"onPremisesNetBiosName":null,
"onPremisesSamAccountName":null,
"onPremisesSecurityIdentifier":null,
"onPremisesSyncEnabled":null,
"preferredDataLocation":null,
"preferredLanguage":null,
"renewedDateTime":null,
"resourceBehaviorOptions":[
],
"resourceProvisioningOptions":[
],
"securityEnabled":null,
"securityIdentifier":null,
"theme":null,
"visibility":null
}
}
]
该应用拥有以下权限:
Directory.AccessAsUser.All
User.Read.All
User.ReadWrite.All
UserAuthenticationMethod.Read.All
UserAuthenticationMethod.ReadWrite.All
Directory.Read.All
Directory.ReadWrite.All
Group.Read.All
GroupMember.Read.All
User.Read
我使用的所有其他端点、增量、用户、订阅都按预期工作,但由于未知原因,它们与 /memberOf 为空。 我真的希望你们能帮助我,我做错了什么,因为我已经用头撞墙太久了:)。
提前致谢。
要获取用户 MemberOf,请在下面的示例中使用下面的查询
var result = await graphClient.Users[upn].MemberOf .Request() .GetAsync();
使用页面迭代器获取所有目录对象
protected async Task<List<T>> GetAllPagesAsType<T>(
GraphServiceClient graphClient,
ICollectionPage<DirectoryObject> page) where T : class
{
var allItems = new List<T>();
var pageIterator = PageIterator<DirectoryObject>.CreatePageIterator(
graphClient, page,
(item) => {
// This code executes for each item in the
// collection
if (item is T)
{
// Only add if the item is the requested type
allItems.Add(item as T);
}
return true;
}
);
await pageIterator.IterateAsync();
return allItems;
}
请参考此示例