10

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?

Selim Alawwa
  • 742
  • 1
  • 8
  • 19

2 Answers2

6

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);
    }    
}
Vyrd
  • 172
  • 2
  • 12
1

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

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • I have checked this, but Is it possible to access SharePoint without an access token. I can access it via Apache HttpClient using a username and password and SharePoint site URL, is it possible to do that via Microsoft Graph? – Selim Alawwa Apr 18 '19 at 12:11
  • 1
    It is not possible to access SharePoint using Microsoft Graph without an access token. Microsoft Graph access is only enabled with an access token. – Michael Mainer Apr 19 '19 at 14:42