Share via

I integrated microsft graph teams api with springboot but i m getting, Error message: /me request is only valid with delegated authentication flow.

Ali Sultan 0 Reputation points
2023-09-23T16:25:40.7166667+00:00

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

POST https://graph.microsoft.com/v1.0/me/onlineMeetings

SdkVersion : graph-java/v5.70.0

SdkVersion : graph-java/v5.70.0

[...]

400 : Bad Request

Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,431 Reputation points
    2023-09-26T10:01:40.1033333+00:00

    Hi @Ali Sultan

    The /me endpoint represents the logged in user and only supports delegated permissions, so you should use the delegated authentication flow (ROPC flow or auth code flow) to obtain the access token, as stated in the error message.

     final UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder()
             .clientId("xxxxxxxxxxxxxxxxxxxxx")
             .username("xxxxxxxxxxxxxxxxxxxx")
             .password("xxxxxxxx")
             .build();
     final List<String> scopes = Arrays.asList("OnlineMeetings.ReadWrite");
     final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(scopes, usernamePasswordCredential);
     final GraphServiceClient graphClient =
             GraphServiceClient
                     .builder()
                     .authenticationProvider(tokenCredentialAuthProvider)
                     .buildClient();
     OnlineMeeting onlineMeeting = new OnlineMeeting();
     onlineMeeting.startDateTime = OffsetDateTimeSerializer.deserialize("2023-10-12T21:30:34.2444915+00:00");
     onlineMeeting.endDateTime = OffsetDateTimeSerializer.deserialize("2023-10-12T22:00:34.2464912+00:00");
     onlineMeeting.subject = "User Token Meeting";
     onlineMeeting = graphClient.me().onlineMeetings()
             .buildRequest()
             .post(onlineMeeting);
     System.out.println(onlineMeeting.id + "\n" + onlineMeeting.joinWebUrl);
    

    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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.