microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.49k stars 2.44k forks source link

[.NET SDK] During OAuth Flow For 3rd Party Auth Provider, Sign In Button Does Not Launch Website #4970

Closed mkonkolowicz closed 5 years ago

mkonkolowicz commented 6 years ago

Bot Info

Issue Description

During oauth flow for 3rd party oauth provider, clicking on the button which provides the login link, does not bring up a new browser window to be used for login.

Code Example

await SendOAuthCardAsync(context, (Activity)context.Activity);

Reproduction Steps

  1. Send message to bot in MS Teams
  2. Attempt to authenticate
  3. Click on button

Expected Behavior

button click launches browser window that redirects to authentication entry point.

Actual Results

button click does not bring up any window. *NOTE, upon hover over of button, there seems to be a link that exists.

teamsbuttonclick

JasonSowers commented 6 years ago

RIght now there are workarounds for this, but we have work items to deal with all of this we hope to get knocked out very soon.

Try the workaround I mention in #4768:

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();

If you copy and paste the magic code in teams you will get extra characters like "\r\n123456\r" Below is a way to deal with this from #4899:

In my messages controller I put a check for the magic code copy paste like this:

            if (activity.Type == ActivityTypes.Message)
            {
                if (activity.ChannelId == ChannelIds.Msteams && activity.Text.StartsWith("\r\n"))
                {
                        activity.Text = CustomCode.SanatizeMagicCodeForTeams(activity.Text);
                }
                await Conversation.SendAsync(activity, () => new RootDialog());
            }

Then I wrote this simple static class to handle it:

    public static class CustomCode
    {
        public static string SanatizeMagicCodeForTeams(string magicCode)
        {
            Regex regex = new Regex(@"\r\n(\d{6})\n");
            var match = regex.Match(magicCode);
            if (match.Success)
            {
                magicCode = magicCode.Substring(2, 6);
            }
            return magicCode;
        }
    }
mkonkolowicz commented 6 years ago

@JasonSowers in the work arounds posted for the other (sms/slack) channels, I get to the sign in page, and am able to get a re-direction back to the conversation flow before it fails. In MS Teams, I can't even launch the login page, since clicking on the button does not launch a browser window.

Will the work around handle this as well?

Cheers, Maciek

JasonSowers commented 6 years ago

Sorry for the delay I was out yesterday.

Yes the workaround I posted in #4897 will also take care of the issue in teams. That workaround actually takes care of like 80% of the channel specific problems with Auth. Just remember to add the correct channels to your if statement. Or always run the SignInDialog instead of the GetTokenDialog.

But you are saying the workaround in #4897 is not working for you?

mkonkolowicz commented 6 years ago

I will try the workaround tomorrow or Monday. Not sure if it works. Thanks for the response jason

JasonSowers commented 6 years ago

@mkonkolowicz I have a sample that has OAuth working on every channel (except email and cortana) in this repo. Feel free to use the project as a reference while we sort things out in the SDK. It's an adaption of the AADv2 Sample, but the concepts will transfer to 3rd party.

johnataylor commented 5 years ago

Thank you for opening an issue against the Bot Framework SDK v3. As part of the Bot Framework v4 release, we’ve moved all v3 work to a new repo located at https://github.com/microsoft/botbuilder-v3. We will continue to support and offer maintenance updates to v3 via this new repo.

From now on, https://github.com/microsoft/botbuilder repo will be used as hub, with pointers to all the different SDK languages, tools and samples repos.

As part of this restructuring, we are closing all tickets in this repo.

For defects or feature requests, please create a new issue in the new Bot Framework v3 repo found here: https://github.com/microsoft/botbuilder-v3/issues

For Azure Bot Service Channel specific defects or feature requests (e.g. Facebook, Twilio, Teams, Slack, etc.), please create a new issue in the new Bot Framework Channel repo found here: https://github.com/microsoft/botframework-services/issues

For product behavior, how-to, or general understanding questions, please use Stackoverflow. https://stackoverflow.com/search?q=bot+framework

Thank you.

The Bot Framework Team