"Cannot post activity. Unauthorized" When testing from Bot Emulator

Viewed 6310

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.

2 Answers

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

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.

Related