如何使用固定输入创建 GraphServiceClient 的 IAuthenticationProvider 对象

Sel*_*wwa 6 java sharepoint microsoft-graph-sdks microsoft-graph-api

我正在尝试从我的 Java 应用程序连接到 Microsoft Share Point。Microsoft Graph SDK for Java 的文档不是很清楚。

我正在尝试启动 Graph 客户端,同时通过自定义 GUI 或配置文件提供所需的凭据。

我正在尝试按照以下方式进行但可以

IGraphServiceClient client = GraphServiceClient.builder().authenticationProvider(authenticationProvider).buildClient();

Run Code Online (Sandbox Code Playgroud)

我需要“authenticationProvider”对象是一个实现 IAuthenticationProvider 的类,但是它不清楚要添加什么参数或如何创建这个对象。有没有人以前尝试过这个,构建客户端并提供所需凭据的正确方法是什么?

Vyr*_*yrd 6

Microsoft 有一个示例项目,其中有一个 IAuthenticationProvider 的简单实例

public class SimpleAuthProvider implements IAuthenticationProvider {

    private String accessToken = null;

    public SimpleAuthProvider(String accessToken) {
        this.accessToken = accessToken;
    }

    @Override
    public void authenticateRequest(IHttpRequest request) {
        // Add the access token in the Authorization header
        request.addHeader("Authorization", "Bearer " + accessToken);
    }    
}
Run Code Online (Sandbox Code Playgroud)


Dar*_*ler 1

实现各种不同 OAuth 流程的 AuthenticationProvider 在单独的包中提供。请参阅此处的 Github 存储库:
https ://github.com/microsoftgraph/msgraph-sdk-java-auth