I've implemented the OAuth flow in a Teams bot similar to the sample, and I'm able to get a user token and make calls against the graph, but I'm running into an issue with changing permissions. Here's what I did:
- Created a bot and gave it mail.read
- Add the bot for a user and trigger the OAuth dialog. User is prompted for consent, and signed in.
- Successfully read mail
- In AAD, added the Mail.ReadWrite and Mail.Send permissions to the app
- Next time the OAuthPrompt was triggered, token was returned immediately. No prompt for consent.
- Got an access denied exception when trying to write or send mail
So the issue is that changing permissions on the app does not automatically trigger the consent flow again in the OAuthPrompt. I also tried these troubleshooting steps:
- I manually signed the user out (botAdapter.SignOutUserAsync) and signed back in, but was not prompted for consent again.
- Same as above, but signed out of Teams as well. Launched the web client in a new incognito window, and still no prompt for consent.
- Uninstalled and re-installed the bot on the user's account. No change.
- Tried the above after waiting a few hours, but still no change.
The only way I found to trigger the consent flow again was to have the user go to https://account.activedirectory.windowsazure.com/r#/applications and delete the consent from there. Even then I had to call botAdapter.SignOutUserAsync (since the bot service still returned a token with the old permissions). Once I did that, and triggered the OAuth prompt again, I was able to get the consent flow with the new permissions to trigger.
So my question is, is there a better way to handle this? If a new version of the bot requires new permissions, shouldn't the OAuthPrompt from Microsoft.Bot.Builder.Dialogs and the bot service handle re-prompting for consent?
SignOutUserAsync
and signing back in? – Nafis Zaman