All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.plugin.msgraph.CustomAuthenticationProvider Maven / Gradle / Ivy

package com.xlrit.gears.plugin.msgraph;

import java.net.URL;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

import org.jetbrains.annotations.NotNull;

import com.microsoft.aad.msal4j.ClientCredentialParameters;
import com.microsoft.aad.msal4j.ConfidentialClientApplication;
import com.microsoft.aad.msal4j.IAuthenticationResult;
import com.microsoft.graph.authentication.BaseAuthenticationProvider;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class CustomAuthenticationProvider extends BaseAuthenticationProvider {
	private static final String SCOPE = "https://graph.microsoft.com/.default";

	private final ConfidentialClientApplication app;

	// With client credentials flows the scope is ALWAYS of the shape "resource/.default", as the
	// application permissions need to be set statically (in the portal), and then granted by a tenant administrator
	private final ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(Collections.singleton(SCOPE)).build();

	@NotNull
	@Override
	public CompletableFuture getAuthorizationTokenAsync(@NotNull URL requestUrl) {
		return app.acquireToken(clientCredentialParam)
			.thenApply(IAuthenticationResult::accessToken);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy