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.
This Cannot post activity. Unauthorized might happen while bot debugging. One easy check need to be done before testing locally: Either remove your credentials (MicrosoftAppId / MicrosoftAppPassword) from appsettings.json file or provide them to Bot Emulator. Otherwise first message to your bot will throw this error.
Bot is currently running in Azure. If you connect to the bot in the emulator, it gives you 401 Unauthorized If you use the same AppID and password in the emulator for a Node.js bot running locally, the authentication works and you can talk to the Node.js bot in the emulator.
Debug with the emulator. The Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots, either locally or remotely. Using the emulator, you can chat with your bot and inspect the messages that your bot sends and receives.
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: 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With