简体   繁体   中英

Bot Framework portal - "Test connection to your bot" 401 Unauthorized

I created a bot application which I've successfully been able to test locally via the emulator.

Following https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html I published the Bot Application to Azure. (which is created as http://mybotappname.azurewebsites.net )

I then went to the Microsoft Bot Framework portal at https://dev.botframework.com and registered the bot, and made sure to set the messaging endpoint to

http s ://mybotappname.azurewebsites.net /api/messages

After successfully registering, I updated the MicrosoftAppId & MicrosoftAppPassword keys in web.config.

However, when I try to "Test connection to your bot", all I'm seeing is a message saying

"Unauthorized"

How can I debug where this is coming from?

I've tried running the Bot Framework Channel Emulator, setting the Bot Url to the same url as my Bot has set for Messaging endpoint. This gives me a "401 Unauthorized" message as well, but I can't figure out how/where to debug the reason.

Has anyone experienced this or know what I can do to debug?

Thanks

Figured it out:

In web.config, the default appSetting keys are

<add key="AppId" value="ID" />
<add key="AppSecret" value="SECRET" />

And in the documentation, we set:

<add key="MicrosoftAppId" value = "ID" />
<add key="MicrosoftAppPassword" value = "SECRET" />

My issue was not updating these appSetting keys to MicrosoftAppId and MicrosoftAppPassword. Once I did this, it worked.

The getting started guide is a little misleading on this. In step 5 it tells you:

The AppId and AppPassword from the Bot Framework registration page have to be recorded in the project's web.config

Later on in the Emulator section it specifically tells you to not put an appid or password into the boxes within the emulator tool when running locally. This part is incorrect, if you have values in your web.config file, then you must put the same values into the emulator. You can leave the values blank in the emulator but then you also need to remove them from your web.config file.

This page is very helpful in troubleshooting auth issues: https://docs.botframework.com/en-us/support/troubleshooting-bot-framework-authentication/

I also faced this error "Error: Unauthorized. Invalid AppId passed on token" while trying to access a bot deployed in Azure. The solution was to go to Bot registration>Access control> I added myself as the owner of the bot. And it started working for me in the emulator. I gave http://localhost:port and did not provide the MicrosoftAppId and MicrosoftAppPassword in the emulator and I was able to debug the bot locally.

Just to add for others (and possibly my future self), don't forget to check which appsettings.json file you are using.

In Properties/launchSettings.json , the setting ASPNETCORE_ENVIRONMENT defines which version you are using.

eg,

"environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },

In the above, you need to update the MicrosoftAppId & MicrosoftAppPassword in the file appsettings.Development.json and not appsettings.json .

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