Forum Discussion

XDeveloper29's avatar
XDeveloper29
Copper Contributor
Jul 18, 2024

How to get access token for Graph API in Teams bot-based message extension?

I'm developing a Teams bot-based message extension application using the Teams Toolkit in TypeScript. I need to retrieve all the replies for a message in the current channel. According to the documentation, I need to use the Graph API to get the replies. However, to use the Graph API, I need an access token.

 

My questions are:

  1. How can I implement OAuth to get the token in a bot-based message extension?
  2. Are there any specific permissions or configurations needed in the Azure portal to enable this?
  3. Is there an alternative way to get the access token or retrieve the replies without using the Graph API?
  • Hi XDeveloper29 - Thanks for raising the query.
    We will look into it and let you know the updates.

    Update: Your questions about implementing OAuth and accessing the Graph API in your Teams bot-based message extension. To address your queries:

    1. Implementing OAuth: You can implement OAuth in a bot-based message extension by sending an OAuth Card to the Teams client, which is used to get the access token from Microsoft Entra ID using tokenExchangeResource. Upon the user's consent, the Teams client sends the token received from Microsoft Entra ID to the bot app using token exchange.

    2. Permissions and Configurations: Specific permissions are required in the Azure portal to enable access to the Graph API. You must register your app and ask for specific permission scopes to obtain the access tokens upon the app user's consent.

    3. Alternative Methods: If you're looking for an alternative way to retrieve the replies without using the Graph API, currently, the Graph API is the primary method provided by Microsoft to interact with Teams data programmatically.

    For a detailed guide on implementing authentication and obtaining access tokens, please refer to the official Microsoft documentation:

    If you need any further assistance or have additional questions, please feel free to ask.

    • XDeveloper29's avatar
      XDeveloper29
      Copper Contributor
      We have created an app using Teams Toolkit and registered a bot on dev.botframework.com. Can we implement OAuth with this setup, or do we need Azure Bot Service for OAuth?
      • Dinesh-MSFT's avatar
        Dinesh-MSFT
        Icon for Microsoft rankMicrosoft
        Hi XDeveloper29, you can implement OAuth with your current setup using Teams Toolkit and a bot registered on dev.botframework.com. While Azure Bot Service provides built-in support for OAuth and simplifies the process, it is not strictly necessary for OAuth implementation. You will need to handle the OAuth flow manually, which involves registering your app with an identity provider, setting up the necessary OAuth 2.0 endpoints, and managing tokens within your application.

Resources