Search in sources :

Example 1 with IClientConfig

use of com.microsoft.graph.core.IClientConfig in project msgraph-sdk-java by microsoftgraph.

the class TestBase method GetAuthenticatedClient.

private void GetAuthenticatedClient() {
    if (graphClient == null) {
        try {
            accessToken = GetAccessToken().replace("\"", "");
            IAuthenticationProvider mAuthenticationProvider = new IAuthenticationProvider() {

                @Override
                public void authenticateRequest(final IHttpRequest request) {
                    request.addHeader("Authorization", "Bearer " + accessToken);
                }
            };
            IClientConfig mClientConfig = DefaultClientConfig.createWithAuthenticationProvider(mAuthenticationProvider);
            graphClient = GraphServiceClient.fromConfig(mClientConfig);
        } catch (Exception e) {
            throw new Error("Could not create a graph client: " + e.getLocalizedMessage());
        }
    }
}
Also used : IHttpRequest(com.microsoft.graph.http.IHttpRequest) IAuthenticationProvider(com.microsoft.graph.authentication.IAuthenticationProvider) IClientConfig(com.microsoft.graph.core.IClientConfig)

Aggregations

IAuthenticationProvider (com.microsoft.graph.authentication.IAuthenticationProvider)1 IClientConfig (com.microsoft.graph.core.IClientConfig)1 IHttpRequest (com.microsoft.graph.http.IHttpRequest)1