【问题标题】:List all groups of a user in Azure Active directory using the Azure API call使用 Azure API 调用列出 Azure Active Directory 中用户的所有组
【发布时间】:2018-12-21 07:50:23
【问题描述】:

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

(目前google搜索到以下两个API,一个是“Azure Active Directory Graph API”,另一个是“Azure API Management REST API Group entity”

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

【问题讨论】:

    标签: azure azure-active-directory


    【解决方案1】:

    最好的方法是调用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
    }
    

    【讨论】:

    猜你喜欢
    • 2021-11-27
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2023-01-26
    相关资源
    最近更新 更多