Hi @Ameer K
You're probably trying to call /me
endpoint with the unattended client credentials flow, and that's what's causing the problem. The /me
endpoint only supports user tokens, so you must use a delegated authentication flow to obtain an access token, such as the auth code flow or ROPC flow.
final AuthorizationCodeCredential authCodeCredential = new AuthorizationCodeCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.authorizationCode(authorizationCode)
.redirectUrl(redirectUri)
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(scopes, authCodeCredential);
final GraphServiceClient graphClient =
GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
final User me = graphClient.me().buildRequest().get();
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.