[Auth, Teams] OAuth Card not rendering in WebChat and sign in button doesn't work in Teams
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
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
I still couldn't figure it out. Is there something wrong with OAuth Card?
We see the same issue on our end.
Hi @tariksetia and @amazaheri, I will begin looking into this today and will keep you posted.
Hi @stevkan, any news on this ?
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
About changing the the OAuthCard ActionType, any example on how to do this? Thanks
@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();
Is anyone still having issues with this that they need help with?
Its on our task list for this sprint, I will update soon.
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
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.
Indeed i was copy pasting... thanks for you help the sign in works now. Suggestions and adaptive cards are not being displayed though
Did anyone else still need help with this issue or are we all good to close this?
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
@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:
- the builder in the global.asax.cs is it also missing something?
@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();
});
}
@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.
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.
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?