Search code examples
botframeworkmicrosoft-graph-apimicrosoft-graph-teams

Get refresh tokens of Microsoft Graph API with OAuthPrompt


I'm creating a MS Teams bot which periodically checks the users' Outlook calendar by background threads spawned after the user logs in via OAuthPrompt.

To implement the feature, it seems that I have to configure an OAuth connection setting and an app registration supporting offline_access. Then, get a refresh token when getting an access token, according to Get access on behalf of a user.

But as long as I tried the example bot, the result of OAuthPrompt doesn't contain a refresh token. And I couldn't find the documented way to get it.

How can I achieve the goal? Do I need some hack on OAuthPrompt or some related classes? Do I have to build cards from scratch?


Solution

  • I concluded that we can't get refresh_token with OAuthPrompt from investigation. So I made up with a different way to achieve the goal. The key idea is creating a tiny web app just for the "Sign in with Microsoft account" feature, which can easily get refresh_token as ordinary web apps.

    Here is the example app: https://github.com/igrep/example-teams-bot-with-ms-account-refresh-token