简体   繁体   中英

How do I resolve a 401 on my azure web app bot?

I've been working on this problem for a week now and I've got no further and was hoping someone had encountered this before. The documentation around this is frustratingly sparse and glosses over the particular issues i'm having trouble with.

So I have a bot I wish to integrate into a teams application, but before that I wanted to test it in the emulator and ensure it works in Azures Test in Webchat feature. The Web App Bot is hosted on Azure, as is the App Bot Service, which is what I deploy to. When I test it in web chat, There is an error in my browsers console, and in the Channel there is a listed issue stating "There was an error sending this message to your bot: HTTP status code Unauthorized"

What I assume is happening is that my Web App Bot is sending a malformed request to my web app service. But I don't understand why.

在此处输入图像描述

So, looking around here and other places, it looks like the cookie cutter answers for this are a combination of check your AppId and AppPassword are correct, make sure your endpoint is correct, make sure the admin has consented, test it in the emulator, update your bot framework nugets, make sure you subscribed your bot correctly, delete and resubscribe your bot etc etc, naturally all of these I've done.

I'm sure the Id and Password, endpoint, and consent are all correct, as I can connect to the bot fine in the emulator.

在此处输入图像描述

What I'm not clear on is the consent process. I think I've consented to everything I need to, but it might be worth double checking.

I've also tried remote debugging to see if it hits my code, and it does, but the postAsync() controller just throws out the request

[HttpPost, HttpGet]
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);
}

Is there anything I need to configure, or any thing I can look into here? Azure can be a confusing place so it would be nice to have some advice from someone more knowledgeable.

So that's my question. Why am I not authorised to test this in Test Web Chat on Azure? And why do I get the same errors when I include the bot ID in my teams manifest?

Make sure these things:

  1. When you connect your Bot just mention the URL of the Bot Channel.

  2. The UnAuthorized message comes when you have (unintentionally) mentioned MicrosoftAppId and MicrosoftAppPassword in your appSettings.json. Make sure you don't mentioned them. Pass empty string.

  3. If you have created your Bot in Azure Portal you will get the MicrosoftAppId (in Overview section) and MicrosoftAppPassword (in Keys or may be Security on left side of the Azure Portal Bot pane). Use these credentials when you Connect to a BOT and also in your appSettings.json

Note: Step-3 only applies if you have created a Web bot in Azure Portal. Ignore otherwise.

You can also visit this link: https://stackoverflow.com/a/49377915/6029001

For those who stumble onto this thread, the answer was that I just had to delete my app service and deploy it again.

I originally created the service manually, and then used continuous deployment to deploy onto it, but I found that just deleting the app service, and having visual studio create the service for me, the bot suddenly began authorizing.

As far as I know, no configuration was different, so it must've been something to do with setup. Marking as solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM