2

Using Microsoft Bot Framework, I created a Chat Bot and I am able to test the Bot using local Emulator. Bot service also deals with LUIS and everything again works just fine. My Bot Service has MicrosoftAppId and MicrosoftAppPassword in web.config.

I deployed the service to Azure. Then embedded a web chat in browser (Github) but it doesn't work. The error say

Buffer="{
  "message": "An error has occurred.",
  "exceptionMessage": "Unauthorized",
  "exceptionType": "Microsoft.Bot.Connector.MicrosoftAppCredentials+OAuthException",
  "stackTrace": "   at Microsoft.Bot.Sample.LuisBot.MessagesController.<Post>d__0.MoveNext()

......

    "innerException": {
        "message": "An error has occurred.",
        "exceptionMessage": "Response status code does not indicate success: 401 (Unauthorized).",
        "exceptionType": "System.Net.Http.HttpRequestException",
        "stackTrace": "   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()\r\n   at Microsoft.Bot.Connector.MicrosoftAppCredentials.<RefreshTokenAsync>d__26.MoveNext()"

I believe when I pass my Web Chat Secret Key (I have also tried to pass generated Token but no luck), then it should be authorized (passing App Id and Password) automatically. Is it not?

  1. Browser embedded web chat gives Unauthorized error.
  2. Test in Web Chat windows gives same error.

I have also tried to deploy Bot service by removing MicrosoftAppId and MicrosoftAppPassword but nothing changes.

Its all very new to me. Could someone please help me to get some clarity on this issue? Also is it fine to give away my Microsoft App Id publicly?

Edit 1

Implementation of Web Chat control in Browser.

  1. Created ASP.Net empty website and have a HTML page (index.html).
  2. Following code is written in index.html page.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

    <div id="bot" />
    <hr />

    <iframe width="400" height="300" src='https://webchat.botframework.com/embed/#Web_App_Bot_Name#?s=Web_Chat_Secret_Key'></iframe>
</body>
</html>
  1. Microsoft App Id = f0f7297e-7a95-4a8f-afc1-eb3d19906cd0
  2. Screen rendered via my code looks like this. And when I send message, it says Couldn't Send. In Azure Diagnostics for App Service, I see error as Unauthorized. enter image description here
Sandy
  • 11,332
  • 27
  • 76
  • 122
  • Also a side comment. In my office laptop, IT team doesn't allow me to install ngrok for security issues. And hence I am unable to debug my service locally. – Sandy Mar 19 '18 at 11:08
  • Yes, you can share your Microsoft App Id publicly without concern (just don't share any secrets, or Microsoft App Passwords). Please provide the code (without the secret) that you are using to embed the webchat control. Also, please provide your Microsoft App Id. – Eric Dahlvang Mar 19 '18 at 18:35

2 Answers2

2

401 (Unauthorized)

You can try the following steps to troubleshoot the issue:

  1. Please check if you specify the correct MicrosoftAppID and MicrosoftAppPassword for your bot on Application Settings blade.

    enter image description here

  2. Please check if you specify the correct message endpoint for the bot on the Settings blade.

    enter image description here

    Note: You can also try to Manage your MicrosoftApp and Generate New Password for that app, and specify MicrosoftAppPassword with new generated password on Application Settings blade and check if it works with new password.

  3. Please try to create a new bot on Azure portal, and publish your bot application to corresponding web application that you specified as messaging endpoint, and check if that new bot works fine.

Besides, if it still does not work as expected even if you set correct configuration, you can try to create support request to report it.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • Worked Worked Worked....I forgot to change MIcrosoftAppPassword in Web Chat when I regenerated it. Thanks a ton dude!! – Sandy Mar 20 '18 at 07:11
1

I also faced this error "Error: Unauthorized. Invalid AppId passed on token" while trying to access a bot deployed in Azure from the bot emulator. 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 didnt provide the MicrosoftAppId and MicrosoftAppPassword in the emulator and I was able to debug the bot locally.

sam
  • 203
  • 3
  • 10