列出使用java的azure广告用户

列出使用java的azure广告用户,java,azure,sdk,azure-active-directory,Java,Azure,Sdk,Azure Active Directory,使用java使用用户名和密码连接azure ad的方法是什么 我使用python打印azure目录的所有用户,但在java中找不到使用用户名和密码连接的方法 from azure.common.credentials import UserPassCredentials from azure.graphrbac import GraphRbacManagementClient credentials = UserPassCredentials("username", "password",

使用java使用用户名和密码连接azure ad的方法是什么 我使用python打印azure目录的所有用户,但在java中找不到使用用户名和密码连接的方法

from azure.common.credentials import UserPassCredentials 
from azure.graphrbac import GraphRbacManagementClient

credentials = UserPassCredentials("username", "password", resource="https://graph.windows.net")

tenant_id = 'tenant id'
graphrbac_client = GraphRbacManagementClient(credentials,tenant_id)
users = graphrbac_client.users.list()
for user in users:
    print(f"Display name={user.display_name}UserPrincipleName={user.user_principal_name}")
任务是通过连接用户名和密码打印目录中的所有用户

Microsoft Graph支持Azure AD Graph公开的所有功能,建议使用Microsoft Graph

通过Gradle安装依赖项:

将microsoft graph auth的存储库和编译依赖项添加到项目的build.gradle中

repository {
    jcenter()
    jcenter{
        url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
    }
}

dependency {
    // Include the sdk as a dependency
    compile('com.microsoft.graph:microsoft-graph-auth:0.1.0-SNAPSHOT')
}
以下是供您参考的工作示例:

public static void main(String [] rags){
        UsernamePasswordProvider authProvider = new UsernamePasswordProvider("{client_id}", Arrays.asList("https://graph.microsoft.com/User.Read.All") , "{username}", "{password}", NationalCloud.Global, "{tenant}", "{cient_secret}");
        IGraphServiceClient graphClient = GraphServiceClient
                .builder()
                .authenticationProvider(authProvider)
                .buildClient();
        IUserCollectionPage userCollectionPage = graphClient.users().buildRequest().get();
        List<User> userList=userCollectionPage.getCurrentPage();
    }
注意:请记住在门户中添加Microsoft graph api权限并授予管理员许可

参考:


当我应用上面提出的解决方案时,我收到以下错误消息。知道为什么会发生错误吗?? 我正在使用此版本的library->com.microsoft.graph:microsoft graph auth:0.3.0

com.microsoft.graph.http.GraphServiceException:错误代码:InvalidAuthenticationToken 错误消息:CompactToken解析失败,错误代码:80049217

得到 SdkVersion:graph java/v2.7.1 授权:[PII_已修订]