Retrieving Refresh Token with OAuthPrompt in Microsoft Teams Bot

Palak Agarwal 20 Reputation points
2024-05-30T09:04:57.85+00:00

I am currently developing a Microsoft Teams bot and using the OAuthPrompt in my DialogSet to obtain the access token. The token retrieval works as expected, but I am facing an issue where the refresh token is not being retrieved along with the access token.

Is there any way to retrieve the refresh token using the OAuthPrompt? Are there specific settings or configurations that need to be enabled to obtain the refresh token in addition to the access token?

 AddDialog(new OAuthPrompt(
                   nameof(OAuthPrompt),
                   new OAuthPromptSettings {
                       ConnectionName = "xyz",
                       Text = "Let’s get started!",
                       Title = "Connect to your Account",
                       Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5)
                   }));
--
await stepContext.BeginDialogAsync(nameof(OAuthPrompt), cancellationToken: cancellationToken);
--
var 

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
774 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,450 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,993 questions
{count} votes

Accepted answer
  1. Gowtham CP 3,730 Reputation points
    2024-05-30T09:20:36.6866667+00:00

    Hello Palak Agarwal ,

    Thanks for reaching out in the Microsoft Q&A!

    Retrieving refresh tokens directly with Microsoft Teams bot's OAuthPrompt isn't possible. For long-lived access, explore creating a separate web app using Azure Active Directory v2 (AADv2). This app handles sign-in and retrieves both access and refresh tokens, sending them back to your bot for secure storage and use in refreshing access tokens when they expire.

    Additionally, you might find this Stack Overflow thread helpful, as it addresses a similar issue: Get refresh tokens of Microsoft Graph API with OAuthPrompt

    For practical implementation guidance, check out this example app: example-teams-bot

    Please let me know if you have further questions.

    If the response helped, do "Accept Answer" and up-vote it to close the thread! Thanks!


0 additional answers

Sort by: Most helpful