1

I built my bot using Direct Line and authentication works there. But when I deployed my bot to MS Teams, pressing the sign in button does nothing at all. I used the following code:

AddDialog(new OAuthPrompt(
    nameof(OAuthPrompt),
    new OAuthPromptSettings
    {
        ConnectionName = ConnectionName,
        Text = " Welcome! Please Sign In.",
        Title = "Sign In",
        Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5),
    })
);

I tried looking up documentation, but it seems they're using a different framework, or the v3 bot framework. How can I make OAuth work in web and ms teams?

I'm using Bot Framework v4.

AskYous
  • 4,332
  • 9
  • 46
  • 82

2 Answers2

6

How are you testing the Teams app? Did you side-load it into your Teams environment? When you are using Azure Bot Service for Authentication in Teams, you need to whitelist the domain in your Bot Manifest. This requirement applies to bots built with the v3 and v4 SDK.

You could use App Studio to add token.botframework.com to the validDomains section of the manifest file. (or you can build the manifest file manually)

Mick
  • 2,946
  • 14
  • 19
  • I just pressed the "channels" button in azure and pressed on MS Teams. I was able to start having a conversation with my bot instantly. It's just when I try to sign in, the signin button does nothing. I never made a manifest file or anything. Here's a screenshot: https://i.imgur.com/xqBlt46.png – AskYous Jul 30 '19 at 22:01
  • Also, I'm using Bot Framework v4. Not v3. Edited my initial post. – AskYous Jul 30 '19 at 22:03
  • 2
    @Mick is correct. You need to add `token.botframework.com` to the `validDomains` in the app manifest to enable the login button in Teams. – tdurnford Jul 31 '19 at 00:42
  • @AskYous sorry, I could have been more clear. My link went to a note on the v3 documentation, but that also applies to the v4 SDK. I just couldn't find any v4 documentation which mentioned this requirement... I created an issue in our bot-docs repository, hopefully this will be improved soon. – Mick Jul 31 '19 at 07:11
  • 1
    Thank @Mick, your info help me solve my problem. Beside adding token.botframework.com to the validDomains, I also have to match id and botid with my bot MicrosoftAppId. This is stated on Mick's docs link. Previously I generate the id, and that way it didn't work. – dchang Feb 20 '20 at 17:44
1

Some weeks ago, we faced the same problem.

Luckily, a few weeks ago, Microsoft uploaded a sample: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/46.teams-auth

The key here is to use TeamsActivityHandler (found inside teamsActivityHandler.js file) instead of ActivityHandler when extending your bot.

Hope it helps!

David
  • 31
  • 2
  • I added the equivalent file in C# but received the same response. Though I did this by copying the 2 functions (OnSigninVerifyStateAsync & OnInvokeActivityAsync) into my class that extends ActivityHandler and added some logging in the 2 functions to see if they run at all, but I got no response. Here is [my code](https://gist.github.com/AskYous/5ff488bf7f518634b0c4dff580f85f0e#file-dialogbot-cs-L72-L89). – AskYous Jul 31 '19 at 21:38
  • 1
    Here is [C# Sample](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth) for auth in Microsoft Teams. Make sure that you have created and sideloaded App Manifest. All the URLs which opens in a pop up needs be part of valid domain. If your pop up is not opening then it's not code issue, it's App Manifest. – Wajeed Shaikh Aug 01 '19 at 01:57
  • My bot is based on Enterprise bot template, which class should derive from Activityhandler, is it Dialog that calls OAuthPrompt? or the class that derived from IBot, where ActivityHandler should be implemented?, It displays the popup dialog, but i see the invoke with signin/verifyState is received, but it is not processed. – Snekithan Aug 23 '19 at 02:10