我们的前端使用PKCE流并获取访问令牌。按照旧的实现(microsoft-graph@2.8.1版本),下面的代码段使用现有的访问令牌获取Graph。现在,我无法在新的中完成同样的工作。
IGraphServiceClient client = GraphServiceClient.builder()
.authenticationProvider( request -> request.addHeader("Authorization", "Bearer " + tokenAuthentication.getToken().getTokenValue()) )
.buildClient(); 已添加到项目中的依赖项
<dependency>
<!-- Include the sdk as a dependency -->
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>5.13.0</version>
</dependency>
<dependency>
<!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.5</version>
</dependency>发布于 2022-02-10 14:48:48
终于起作用了..。见下文片段..。
IAuthenticationProvider authProvider = new IAuthenticationProvider() {
@Override
public CompletableFuture<String> getAuthorizationTokenAsync(URL requestUrl) {
CompletableFuture<String> future = new CompletableFuture<>();
future.complete(yourToken);
return future;
}
};
GraphServiceClient<Request> graphClient = GraphServiceClient
.builder()
.authenticationProvider(authProvider)
.buildClient();
return graphClient.me().buildRequest().get();https://stackoverflow.com/questions/71057550
复制相似问题