Get bearer token for "https://teams.microsoft.com/api/xx/xxx/xxxx-03/beta/users/...."
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:
- How to use the same API in our client application to get information for external user?
- How do I get the bearer tokens? What’s the scope of bearer tokens here?
- 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.
- 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?