Microsoft Graph API V3 - Identity Provider

Viewed 518

Is there a way of using the V3 Microsoft Graph Java SDK with the Authorization Header? In the V1 and V2, i had this:

IAuthenticationProvider authenticationProvider = new IAuthenticationProvider() {
    @Override
    public void authenticateRequest(IHttpRequest request) {
        request.addHeader(AUTHORIZATION_HEADER_NAME, OAUTH_BEARER_PREFIX + accessToken);
    }
};
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authenticationProvider).buildClient();

But using the V3 SDK and the ICoreAuthenticationProvider , the only client I can create is the OKHTTP one, and not the IGraphServiceClient , and I lose all the "Microsoft API" (i get a string response, that I need to "unmarshall"... )

Thanks,

1 Answers

The Microsoft Graph Java SDK now leverages azure-identity to improve the authentication experience. To integrate with the Microsoft Identity platform use Microsoft Authentication Library for Java (MSAL4J). This library provides support for more authentication flows and improves the configuration experience. To upgrade your application do the following:

  • Remove any dependency on microsoft-graph-auth and replace them by one of the providers available in MSAL4J
  • Reconsider the need for custom authentication providers (implementation of IAuthenticationProvider or ICoreAuthenticationProvider) that might be part of your project and use a provider available in azure-identity whenever possible.

In your case for example, if you were using client credential flow, you would replace the above sample with this:

final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(CLIENT_ID)
.clientSecret(CLIENT_SECRET)
.tenantId(TENANT_GUID)
.build();
final TokenCredentialAuthProvider authProvider = new TokenCredentialAuthProvider(SCOPES, clientSecretCredential);
final GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();

Please see here for more examples to upgrade your authentication providers:

Let me know if this helps and if you have further questions.

Related