botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Auth, Teams] OAuth Card not rendering in WebChat and sign in button doesn't work in Teams

Open tariksetia opened this issue 8 years ago • 41 comments

Bot Info

  • SDK Platform: Nodejs
  • SDK Version: 3.13.1
  • Active Channels: Teams,webchat
  • Deployment Environment: AzureBot Service

Issue Description

I am not able to see OAuth card in Azure's Test in webchat page. OAuth card renders in MS-Teams but sign in button didnt work image -> https://github.com/tariksetia/euc-Bot/blob/master/OAuth%20card.PNG

Code Example

I have Setup AzureADv2 integration using botservice docs https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-tutorial-authentication?view=azure-bot-service-3.0

my code: https://github.com/tariksetia/euc-Bot/blob/master/app.js which is similar to example -->https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/basics-oauth/app.js

Expected Behavior

Card should render in webchat and clicking sign-in in teams should open sigin window

tariksetia avatar Jun 19 '18 22:06 tariksetia

I deployed the bot on Skype channel and SignIn button worked. It opend the microsoft login window. Looks like the issue is only with Azure's "Test in webchat" page and MS Teams

tariksetia avatar Jun 22 '18 08:06 tariksetia

I still couldn't figure it out. Is there something wrong with OAuth Card?

tariksetia avatar Jun 29 '18 17:06 tariksetia

We see the same issue on our end.

amazaheri avatar Jul 08 '18 03:07 amazaheri

Hi @tariksetia and @amazaheri, I will begin looking into this today and will keep you posted.

stevkan avatar Jul 10 '18 19:07 stevkan

Hi @stevkan, any news on this ?

jeffaknine avatar Jul 12 '18 12:07 jeffaknine

WebChat - If you are using webchat via iFrame or in the azure portal's "test in webchat" the signin card will not render. If you use the CDN or NPM version it will render as long as you use 0.13.0 or higher, the card will render. You can find instructions on how to add webchat to your website using various methods in the webchat readme

Teams - The sign in card's button has an ActionType of signin and teams does not support this ActionType. In order to make this work as present time you need to go in and change the ActionType to ActionType.OpenUrl There are a few other issues discussing this one is #2104

JasonSowers avatar Jul 13 '18 13:07 JasonSowers

About changing the the OAuthCard ActionType, any example on how to do this? Thanks

jeffaknine avatar Jul 13 '18 14:07 jeffaknine

@jeffaknine There would be multiple ways to change the buttons action type from signIn to openUrl. Below is just one method I am using. For both Node and C# the strategy i am using is to basically catch the activity before it is sent to the user and changing the Button type to OpenUrl.

Note: you cannot copy and paste the magic code into teams, you must actually type it out.


Node.JS

add a method like this to your bot code:

bot.use({
    botbuilder: function(session, next) {
        next();
    },
    send: function(event, next) {
        if (event.source === "msteams" && event.attachments[0].contentType === "application/vnd.microsoft.card.signin") {
            event.attachments[0].content.buttons[0].type = "openUrl";
        }
        next();
    }
});

C#

You will need to first add a class like this that inherits from IMessageActivityMapper:

    public sealed class CustomActivityMapper : IMessageActivityMapper
    {
        public IMessageActivity Map(IMessageActivity message)
        {
            if (message.ChannelId == ChannelIds.Msteams)
            {
                if (message.Attachments.Any() && message.Attachments[0].ContentType == "application/vnd.microsoft.card.signin")
                {
                    var card = message.Attachments[0].Content as SigninCard;
                    var buttons = card.Buttons as CardAction[];
                    if (buttons.Any())
                    {
                        buttons[0].Type = ActionTypes.OpenUrl;
                    }
                }
            }
            return message;
        }
    }

next you will need to register that class in your global.asax like this:

                builder
                    .RegisterType<CustomActivityMapper>()
                    .AsImplementedInterfaces()
                    .SingleInstance();

JasonSowers avatar Jul 13 '18 21:07 JasonSowers

Is anyone still having issues with this that they need help with?

JasonSowers avatar Jul 17 '18 15:07 JasonSowers

Its on our task list for this sprint, I will update soon.

amazaheri avatar Jul 17 '18 15:07 amazaheri

Thank you @JasonSowers , indeed changing the button type opens the sign in in a web page. But now it also gives a magic code that i have to paste. The issue i'm having now is verifying the magic code. I'm using the example from https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/basics-oauth/app.js but i'm getting a "JWT validation failed: IDX10500: Signature validation failed. Unable to resolve"

Thanks Jeff

jeffaknine avatar Jul 17 '18 15:07 jeffaknine

Are you typing out the code or copy paste? There is a very annoying bug in teams in which you cannot paste the magic code in.

JasonSowers avatar Jul 17 '18 16:07 JasonSowers

Indeed i was copy pasting... thanks for you help the sign in works now. Suggestions and adaptive cards are not being displayed though

jeffaknine avatar Jul 17 '18 17:07 jeffaknine

Did anyone else still need help with this issue or are we all good to close this?

JasonSowers avatar Jul 19 '18 23:07 JasonSowers

I am running into an issue where the OAuth Card does not render when using "Visual Studio Services" -- could this be related to this issue?

Note: Azure AD and Github are working fine its only VSTS that is not so far

ravensorb avatar Jul 20 '18 02:07 ravensorb

@JasonSowers ,I too have this issue, but more related to MS Teams. The Sign In button doesn't seem to work when clicking on it.

I tried implementing your workaround, but there is one thing I'm unclear on:

  1. the builder in the global.asax.cs is it also missing something?

Rykimaruh avatar Jul 20 '18 02:07 Rykimaruh

@Rykimaruh apologies as I was running under the assumption that most bots will already be registering things and would already have the rest of the code, the full code that would need to be added would be this in your Application_Start() method, assuming you do not have any other code in there, if you do add this to it:

        protected void Application_Start()
        {
            Conversation.UpdateContainer(
                builder =>
                {
                    builder
                    .RegisterType<CustomActivityMapper>()
                    .AsImplementedInterfaces()
                    .SingleInstance();
                });
        }

JasonSowers avatar Jul 20 '18 23:07 JasonSowers

@ravensorb I am still unable to test with VSTS because of the issue I told you about on Stack Overflow with the callback URL. We are getting in contact with the VSTS app team to try to resolve this.

JasonSowers avatar Jul 20 '18 23:07 JasonSowers

The signin option does not work in 1:1 / private conversations. It works from within a teams channel. The signin card displays, but am not able to click the sign in button.

elizathomas avatar Aug 14 '18 18:08 elizathomas

I'm not sure why you are experiencing this, I have has success in bot 1:1 and in a channel. can you please share your code?

JasonSowers avatar Aug 14 '18 18:08 JasonSowers