Error message: /me request is only valid with delegated authentication flow

Ameer K 15 Reputation points
2023-05-04T05:31:36.0133333+00:00

Hi Team,

We are trying implement Java SDK with Microsoft Team and Graph explorer.

But we are getting error and facing some difficulties.

Error message: /me request is only valid with delegated authentication flow

Even though we granted all permissions in API permissions still we getting this error.azure

Here we shared , Error screenshot also.java output

Kinldy help on this to sort out this error.

Thanks & regards

Ameer

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,039 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,538 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,834 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,418 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Vasil Michev 95,081 Reputation points MVP
    2023-05-04T06:30:21.9466667+00:00

    The problem here is not permissions, it's how you're authenticating. When using delegate permissions, you need to leverage the user-centric auth flows. You cannot use the client credentials flow (auth via client secret/certificate).

    Can you share how you're obtaining the token?


  2. CarlZhao-MSFT 36,811 Reputation points
    2023-05-04T06:44:51.34+00:00

    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();
    

    User's image

    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.


  3. Chauhan Gaurav 0 Reputation points
    2023-08-18T10:11:39.0266667+00:00

    How do i get the authorization code

    0 comments No comments

  4. Umar khalid 0 Reputation points
    2023-08-31T11:04:32.0566667+00:00

    How to fix it

    {
        "error": {
            "code": "BadRequest",
            "message": "/me request is only valid with delegated authentication flow.",
            "innerError": {
                "date": "2023-08-31T11:02:47",
                "request-id": "8c3082ad-7541-42fd-9780-f6fd2575e97b",
                "client-request-id": "8c3082ad-7541-42fd-9780-f6fd2575e97b"
            }
        }
    }
    

  5. tapeshwar Das 0 Reputation points
    2023-10-23T14:03:49.55+00:00

    No solution is available for this thread issue!
    Can anyone help?

    0 comments No comments