I using using the Client Credentials to get the access token and then use graphApi to make call to get users profile but running into issue. Not able to understand the actual error for method not found. Most of the example shows similar approach
Added the application registration - using single tenant orgranization.
Created App role to generate the client_id, secret_id and tenant_id.
//Code //
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("XXX")
.clientSecret("XXX")
.tenantId("XXXX")
.build();
List<String> scopes = new ArrayList<>();
scopes.add("User.Read.All");
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(scopes, clientSecretCredential);
GraphServiceClient<Request> graphClient = GraphServiceClient.builder().authenticationProvider(tokenCredentialAuthProvider).buildClient();
final User me = graphClient.me().buildRequest().get();
assert me != null;
System.out.println(me.employeeId);
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoSuchMethodError: com.azure.core.credential.TokenRequestContext.getTenantId()Ljava/lang/String;
at com.azure.identity.implementation.util.IdentityUtil.resolveTenantId(IdentityUtil.java:26)
at com.azure.identity.implementation.IdentityClient.lambda$authenticateWithConfidentialClientCache$29(IdentityClient.java:800)
at reactor.core.publisher.Mono.lambda$fromFuture$1(Mono.java:507)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1755)
at reactor.core.publisher.MonoCacheTime$CoordinatorSubscriber.signalCached(MonoCacheTime.java:320)
at reactor.core.publisher.MonoCacheTime$CoordinatorSubscriber.onNext(MonoCacheTime.java:337)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2317)
at reactor.core.publisher.MonoCacheTime$CoordinatorSubscriber.onSubscribe(MonoCacheTime.java:276)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoCacheTime.subscribeOrReturn(MonoCacheTime.java:132)
at reactor.core.publisher.Mono.subscribe(Mono.java:4203)
at reactor.core.publisher.Mono.subscribeWith(Mono.java:4329)
at reactor.core.publisher.Mono.toFuture(Mono.java:4663)
at com.microsoft.graph.authentication.TokenCredentialAuthProvider.getAuthorizationTokenAsync(TokenCredentialAuthProvider.java:59)
at com.microsoft.graph.httpcore.AuthenticationHandler.intercept(AuthenticationHandler.java:54)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at com.microsoft.graph.httpcore.TelemetryHandler.intercept(TelemetryHandler.java:69)