It about ms team app js auth token

Smithiam 0 Reputation points
2023-08-22T08:16:24.84+00:00

I did my project in laravel and graph api so it works fine.

but now i already created MS team app and authenticate using msteam.js lib this is also works well, i am able to generate access_token using library,.

Main problem is : I am unable to validate that token using this below code. So how can i authenticate that token ?

Request: 

$accessToken=$request->token;
$graph = new Graph();
$graph->setAccessToken($accessToken);
$graph_user = $graph->createRequest("GET", "/me")->setReturnType(Model\User::class)->execute();

Response:
Client error: `GET https://graph.microsoft.com/v1.0/me` resulted in a `401 Unauthorized` response:


Response is:

Client error: `GET https://graph.microsoft.com/v1.0/me` resulted in a `401 Unauthorized` "message":"Access token validation failure. Invalid audience." 

Thank you very much!

Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Smithiam 0 Reputation points
    2023-08-22T08:51:51.2733333+00:00

    User's image

    0 comments No comments

  2. CarlZhao-MSFT 46,406 Reputation points
    2023-08-22T09:09:23.1366667+00:00

    Hi @Smithiam

    The audience of this token seems to be Web API instead of graph API, so this token can only be used to call your custom Web API.

    But I noticed that your script is using the graph SDK, so try to get an access token for the graph API:

    'scope' => 'https://graph.microsoft.com/.default'
    

    To parse the token:

    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.