13

While testing the EchoBot template from Azure in Bot Emulator I keep getting "Cannot post activity. Unauthorized." How can I protect against this? I am new to .NET, so don't understand the how authentication is working here. I can see the configuration settings being loaded, but I don't see how they get supplied or applied in the default EchoBot template from Azure.

I have found I only get Unauthorized, if I have the "MicrosoftAppID" and "MicrosoftAppPassword" defined in the appsettings.json. If I comment these out it works fine.

    [HttpPost]
    public async Task PostAsync()
    {
        // Delegate the processing of the HTTP POST to the adapter.
        // The adapter will invoke the bot.
        await Adapter.ProcessAsync(Request, Response, Bot);
    }

So I would like to understand how to avoid having to comment these lines out when testing the code locally. PostAsync returns the 401.

Mohit
  • 131
  • 1
  • 5
  • Did you define your Microsoft App ID and Microsoft App password in the emulator settings? This is an optional setting, however it is required when you configure them in your `appsettings.json`. – Mick Oct 19 '19 at 19:11
  • I came across this issue several times. All of these people who face this issue most likely provided correct app Id and password. Still it will show up and at some point it will start working. – roney May 08 '20 at 13:28
  • I am getting the same error. I have been working with bot framework ever since it came out. I know why this happens, I have removed app id and secret from appsettings.json and neither I have kept any secrets in emulator, but still the issue shows up. Is this a bug? – Manish Chitre May 28 '20 at 14:40

2 Answers2

18

Have you tried adding your Microsoft App ID and Microsoft App Password inside of the Emulator ?

It should work fine after you add those when you test the bot in the emulator, check picture below

enter image description here

Marc Asmar
  • 1,527
  • 1
  • 10
  • 22
10

Go to your appSettings.json file and check if you have provided Microsoft App ID and App Password. You will get it when you have registered your app on Azure. If you haven't register it on Azure, you won't get ID and password. In this case, you must left the Microsoft App Id and Password json string as blank. Something like this:

enter image description here

In the Bot Emulator, don't give any credentials. Just provide your app URL and click Connect.

By this way you can get rid of the error.

Hope this helps.

Rohan Rao
  • 2,505
  • 3
  • 19
  • 39