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

Shashikant Sharma 45 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
Microsoft Teams
A Microsoft customizable chat-based workspace.
8,989 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,444 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,813 questions
{count} votes