gpt4 book ai didi

azure - 使用 Azure API 调用列出 Azure Active Directory 中用户的所有组

转载 作者:行者123 更新时间:2023-12-03 01:40:44 29 4
gpt4 key购买 nike

用于从 Spring boot 应用程序列出 Azure Activedirectory 中的所有组的 Rest API 是什么?

(目前谷歌搜索出现以下两个API,如下所示,一个是“Azure Active Directory Graph API”,另一个是“Azure API Management REST API Group实体”

不确定到底使用哪个 API 来获取 Azure AD 组列表?

最佳答案

最好的方法是调用 Microsoft Graph API (尽管您也可以使用 Azure AD Graph API 执行此操作)。

list all groups ,请求将是:

GET https://graph.microsoft.com/v1.0/groups

在Java中,您可以使用Microsoft Graph SDK for Java ,这是如何检索所有组的示例(这包括对多页结果进行分页,如果您有超过 999 个组):

// Set up the Graph client
IGraphServiceClient graphClient =
GraphServiceClient
.builder()
.authenticationProvider(authProvider)
.logger(new NotALogger())
.buildClient();

// Set up the initial request builder and build request for the first page
IGroupCollectionRequestBuilder groupsRequestBuilder = graphClient.groups();
IGroupCollectionRequest groupsRequest = groupsRequestBuilder
.buildRequest()
.top(999);

do {
try {
// Execute the request
IGroupCollectionPage groupsCollection = groupsRequest.get();

// Process each of the items in the response
for (Group group : groupsCollection.getCurrentPage()) {
System.out.println(group.displayName);
}

// Build the request for the next page, if there is one
groupsRequestBuilder = groupsCollection.getNextPage();
if (groupsRequestBuilder == null) {
groupsRequest = null;
} else {
groupsRequest = groupsRequestBuilder.buildRequest();
}

} catch(ClientException ex) {

// Handle failure
ex.printStackTrace();
groupsRequest = null;
}
} while (groupsRequest != null);

list all groups the signed-in user is a member of (包括嵌套组):

POST https://graph.microsoft.com/v1.0/me/getMemberGroups
Content-type: application/json

{
"securityEnabledOnly": true
}

关于azure - 使用 Azure API 调用列出 Azure Active Directory 中用户的所有组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53881002/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com