0
votes

I'm building a teams bot and in it I have an OAuthPrompt to gather credentials for an external service. After initially logging in, I would like to display a "You are now logged in" message. The problem I have is determining if the login is the initial login (or a token refresh which I have to handle manually since the service doesn't provide token life or refresh abilities) or if it is gathering an existing token. I was checking for the activity "invoke" which worked initial, but as my bot gets more complicated, this method is no longer working.

I have a waterfall dialog the follows the flow:

GetServiceTokenStep (calls GetServiceTokenDialog) -> DoSomethingWithTokenStep

In DoSomethingWithTokenStep, one of my actions redirects to another dialog VerifyRequestDialog. In that dialog, I call GetServiceTokenDialog again to retrieve the token I got earlier (or get a new one if needed). The problem is if they had to get the token in GetServiceTokenStep, then when it reaches VerifyRequestDialog then the activity is still "invoke" so it shows the "Hello" message again, even though is already has the token.

What can I check to see if the OAuthPrompt returned an existing token or got one from a new login?

1

1 Answers

2
votes

Teams behaves slightly differently than other channels in this regard. Specifically, an Invoke Activity is sent to the bot rather than the Event Activity used by other channels. This Invoke Activity must be forwarded to the dialog if the OAuthPrompt is being used. This is done by subclassing the ActivityHandler and this sample includes a reusable TeamsActivityHandler. Have you tried using the sample 46.teams-auth?

The sample uses the bot authentication capabilities in Azure Bot Service, providing features to make it easier to develop a bot that authenticates users to various identity providers such as Azure AD (Azure Active Directory), GitHub, Uber, etc. The OAuth token is then used to make basic Microsoft Graph queries. Using this sample, you get an option to view your token.

Hope this helps!!