使用UsernamePasswordCredential提供程序的java列表Azure AD
我正在使用UsernamePasswordCredential provider连接到AAD,并使用msgraph sdk java(https://github.com/microsoftgraph/msgraph-sdk-java)获取de用户,代码如下:
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 楼答案
您的问题已通过评论解决。将其作为结束该线程的答案发布:
确保你的账户不是个人账户
确保启用
Allow public client flows