Hi @Jin Nguyen , to create a Graph Client from a String accessToken using Java, you can use the following code snippet:
import com.microsoft.graph.authentication.IAuthenticationProvider;
import com.microsoft.graph.authentication.TokenCredentialAuthProvider;
import com.microsoft.graph.models.User;
import com.microsoft.graph.requests.GraphServiceClient;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
public class GraphClient {
public static GraphServiceClient<Request> createGraphClient(String clientId, String clientSecret, String tenantId) {
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();
IAuthenticationProvider authProvider = new TokenCredentialAuthProvider(clientSecretCredential);
return GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
}
}
Replace clientId
, clientSecret
, and tenantId
with your own values.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James