gpt4 book ai didi

java - 使用 UsernamePasswordCredential 提供程序列出 Azure AD

转载 作者:行者123 更新时间:2023-12-03 02:25:55 26 4
gpt4 key购买 nike

我正在使用 UsernamePasswordCredential 提供程序连接到 AAD 并使用 msgraph-sdk-java ( https://github.com/microsoftgraph/msgraph-sdk-java ) 获取用户,代码如下:

            final UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder()
.clientId("client_id")
.username("user_name")
.password("password")
.build();

final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(Arrays.asList("https://graph.microsoft.com/.default"), usernamePasswordCredential);

final GraphServiceClient graphClient =
GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();

UserCollectionPage userCollectionpage = graphClient.users().buildRequest().get();

我收到以下错误:

java.io.IOException: java.util.concurrent.ExecutionException: com.azure.core.exception.ClientAuthenticationException: Failed to acquire token with username and password

知道我是否需要在 Azure Active Directory 中配置某些内容吗?

最佳答案

您的问题已通过评论得到解决。将其作为答案发布以结束线程:

  1. 确保您的帐户不是个人帐户。

  2. 确保启用允许公共(public)客户端流

enter image description here

  • 使用 msal4j 库和 PublicClientApplication 类获取包含用户名、密码和范围的 token 。
  • 关于java - 使用 UsernamePasswordCredential 提供程序列出 Azure AD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66988712/

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