Share via

Get bearer token for "https://teams.microsoft.com/api/xx/xxx/xxxx-03/beta/users/...."

Shashikant Sharma 105 Reputation points
2023-03-16T11:54:14.83+00:00

I am trying to get a federated user information without registering my application on external tenant. See the thread https://learn.microsoft.com/en-us/answers/questions/1166664/

I tried MS Teams Search API “https://teams.microsoft.com/api/mt/xxx/xxx/beta/users/<user-id>/externalsearchv3?includeTFLUsers=true”, after logging into MS Teams, in a Browser, toggling developers tools. API ran successfully and fetched the results as shown.

[{"tenantId":"xxx-xxx-xxx-xxx","isShortProfile":false,"accountEnabled":true,"featureSettings":{"coExistenceMode":"TeamsOnly"},"userPrincipalName":"<user-id>","givenName":"<user-id>","surname":"","email":"<user-id>","tenantName":"xxx","displayName":"xxx xxx","type":"Federated","mri":"xxxx-xx","objectId":"xxx-xxxx-xxxx-xxxxx"}]

I then tried the same API in Postman and specified bearer tokens from the Team User logged in Developer Tools web page. It ran successfully there as well. Few questions here:

  1. How to use the same API in our client application to get information for external user?
  2. How do I get the bearer tokens? What’s the scope of bearer tokens here?
  3. AFAIK, Graph API is supposed to be the official Teams API by Microsoft. We are using Graph APIs to fetch user info from the tenant. Similar Graph API “https://graph.microsoft.com/beta/users/<user-id>/externalsearchv3” did not worked in Graph Explorer.
  4. We tried to specify the Bearer Tokens that we could retrieve with Graph APIs, scopes: ['https://graph.microsoft.com/User.Read.All'], and used them with Teams API, it failed with obvious reasons.

How can I use the MS Teams Search API "https://teams.microsoft.com/api/mt/...." in my client application? How can I get bearer tokens for MS Teams?

Microsoft Teams | Development
Microsoft Teams | Development

Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs

Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other

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.