Selim Alawwa
Selim Alawwa

Reputation: 762

How to create an object of IAuthenticationProvider of GraphServiceClient with fixed inputs

I am trying to connect to Microsoft Share Point from my Java application. The documentation for Microsoft Graph SDK for Java is not so clear.

I am trying to initiate the Graph client, while providing the credentials needed via a custom GUI or configuration file.

I am trying to do as follow but can

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

I need the "authenticationProvider" object to be of a class implementing IAuthenticationProvider, however its not clear what parameters to add or how to create this object. Has anyone tried this before and what is the correct way to build the client and provide the required credentials?

Upvotes: 10

Views: 14250

Answers (2)

Vyrd
Vyrd

Reputation: 172

Microsoft has an example project where they have a simple instance of 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);
    }    
}

Upvotes: 6

Darrel Miller
Darrel Miller

Reputation: 142094

The AuthenticationProviders that implement a variety of different OAuth flows are available in a seperate package. See this Github repo here:
https://github.com/microsoftgraph/msgraph-sdk-java-auth

Upvotes: 1

Related Questions