Access token on behalf of user

Azizkhon Ishankhonov 540 Reputation points
2025-02-11T15:07:04.91+00:00

How to get access token for for ms teams user with Teams.AccessAsUser.All scope?

I want send POST request to via Bot Framework REST API to display "Typing Indicator" since there no other API for sending Typing Indicator on behalf of user:

curl --location 'https://smba.trafficmanager.net/teams/v3/conversations/19:1da1f9852c3b4d32918162d17f4c99e6@thread.v2/activities' --header 'Content-Type: application/json' --header 'Authorization: Bearer TOKEN' --data '{"type":"typing"}'

I tried copy token from Web Teams Client and use it to Bot Framework REST API and its works.

Also, I tried use Q&A Assistant response: AADSTS90072: User account '{EUII Hidden}' from identity provider 'https://sts.windows.net/MY_TENANT_ID/' does not exist in tenant 'Bot Framework' and cannot access the application 'MY_APP_ID'(botan-test) in that tenant. The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different Azure Active Directory user account Trace ID: b64a7930-d6e4-4b8b-b30d-ff4092bb0a00 Correlation ID: 19cbf685-e99e-4d14-abdf-f0a356ab545e Timestamp: 2025-02-11 15:02:23Z

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.
3,558 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-02-11T15:07:04.94+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To obtain an access token for a Microsoft Teams user with the Teams.AccessAsUser.All scope, you need to follow these steps:

    1. Register your bot with the Bot Framework to obtain its App ID and password.
    2. Request an access token from the Microsoft Entra ID account login service. You will need to use the bot's App ID and password in the request. The request should look like this:
         POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
         Host: login.microsoftonline.com
         Content-Type: application/x-www-form-urlencoded
         grant_type=client_credentials&client_id=MICROSOFT-APP-ID&client_secret=MICROSOFT-APP-PASSWORD&scope=https%3A%2F%2Fapi.botframework.com%2F.default
      
    3. Specify the JWT token in the Authorization header of your requests to the Bot Connector service. The format should be:
         Authorization: Bearer ACCESS_TOKEN
      
    4. Once you have the access token, you can use it to send the POST request to display the "Typing Indicator" in Microsoft Teams.

    Make sure to handle the access token securely and refresh it as needed to maintain your bot's performance.


    References:

    0 comments No comments

Your answer

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