Reputation: 647
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
https://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
Upvotes: 2
Views: 5122
Reputation: 109
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.
e.g.,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
In the above, you need to update the MicrosoftAppId & MicrosoftAppPassword in the file appsettings.Development.json and not appsettings.json.
Upvotes: 0
Reputation: 233
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.
Upvotes: 0
Reputation: 385
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/
Upvotes: 5
Reputation: 647
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.
Upvotes: 6