microsoft / botframework-sdk

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

Token not being cached for bot authentication with users and magic numbers don't work #4899

Closed Rykimaruh closed 6 years ago

Rykimaruh commented 6 years ago

Hello,

I am getting the same problem as my previous one with token no caching as it should. This happens in the emulator though. It was able to hold the cached token before, but now it doesn't. This happened before the following issue happened.

The other issue is that whenever I paste the authentication number to chat, the bot tells me an error message as follow:

image

JasonSowers commented 6 years ago

Are you using teams? If not what channel?

Rykimaruh commented 6 years ago

@JasonSowers , yes I am using Teams

JasonSowers commented 6 years ago

You have to type in the code for teams, copying and pasting will make the text input be like “\r\n804230\n” or something similar. I wrote a regex that can handle this programmatically I can post shortly.

JasonSowers commented 6 years ago

This is just one way to handle this in your code. You could probably find a better way of doing this.

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;
        }
    }
JasonSowers commented 6 years ago

@Rykimaruh let me know if that helps

Rykimaruh commented 6 years ago

@JasonSowers it works! Thank you!

Were you able to check up on other issue pertaining the cached token and the emulator?

JasonSowers commented 6 years ago

@Rykimaruh can you remind me which issue you are talking about specifically?

Rykimaruh commented 6 years ago

"I am getting the same problem as my previous one with token no caching as it should. This happens in the emulator though. It was able to hold the cached token before, but now it doesn't. This happened before the following issue happened."

It would seem token caching is having issues again. Can this be verified?

JasonSowers commented 6 years ago

Ahh yes, this issue resurfaced, it should be fixed now. Apologies, as I am trying to help resolve many Auth issues and I know I had been talking to you on other threads. Someone else pointed this out earlier and I was able to get the team to deploy a temporary fix until we have a more permanent one in our next release. When this happens, try to check another channel, if it doesn't happen on another channel it's an issue with the emulator and please let us know as you did.

If you start seeing trouble with the emulator and you have had it running for a while(~8 hours), restart the emulator. The emulator uses ngrok, and ngrok sessions expire after 8 hours.

Rykimaruh commented 6 years ago

@JasonSowers , it was working for a short while, but it seems the issue came back once again.

JasonSowers commented 6 years ago

It should be fixed again, it will be permanently fixed in our next deployment. Thanks for reporting.

JasonSowers commented 6 years ago

Going to close this issue. Please open a new one if you experience anything else we can help with.