从Azure AD获取用户详细信息



我在Azure Active Directory中创建了一个用户,我正在尝试读取它的属性/属性,但我遇到了一个错误。

这是我的代码:

UsernamePasswordProvider authProvider = new UsernamePasswordProvider(clientId, Collections.singletonList("https://graph.microsoft.com/.default"),
username, password, NationalCloud.Global, tenantId, clientSecret);
GraphServiceClient<Request> graphClient = GraphServiceClient
.builder()
.authenticationProvider(authProvider)
.buildClient();
User user = graphClient.me().buildRequest().get();
System.out.println(user.companyName);

我得到的错误是:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/microsoft/graph/httpcore/ICoreAuthenticationProvider] with root cause

以下是我使用的依赖项:

<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>5.34.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>2.0.0</version>
</dependency> 
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-auth</artifactId>
<version>0.3.0</version>
</dependency>

谢谢。

请检查文档以获取UsernamePasswordProvider-https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=Java#usernamepassword-提供商。

最终用户名密码凭据用户名密码凭据=新用户名密码凭据生成器((.clientId(clientId(.username(用户名(.password(密码(.build((;

final TokenCredentialAuthProvider tokenCredential AuthProvider=新的TokenCreentialAuthProvider(scopes,usernamePasswordCredential(;

最终GraphServiceClient graphClient=GraphServiceClient.builder((.authenticationProvider(tokenCredentialAuthProvider(.buildClient((;

最终用户me=graphClient.me((.buildRequest((.get((;

希望这能帮助

感谢

相关内容

  • 没有找到相关文章

最新更新