Search code examples
c#botframework

Refresh access token failed with status code: 401


I'm trying to test botframework server on my localhost. I followed the steps in https://learn.microsoft.com/en-us/azure/bot-service/bot-service-troubleshoot-authentication-problems?view=azure-bot-service-4.0#step-3-enable-security-and-test-on-localhost- .

First I changed app config with the MicrosoftAppId and MicrosoftAppPassword passed the test of https://learn.microsoft.com/en-us/azure/bot-service/bot-service-troubleshoot-authentication-problems?view=azure-bot-service-4.0#step-2 . Then I started my bot on localhost and the web page shows it was running on http://localhost:3979/ . But when I tried to test it on the Bot Framework Emulator, it returned 400 directline.postActivity with the message of "Refresh access token failed with status code: 401".

The screenshot is on https://i.loli.net/2019/06/06/5cf88ea120b9973175.png .

My botframework version is 3.13.1. My Bot Framework Emulator version is 4.3.3.

What should I do to solve this problem? Thanks for any help.

{
  "error": {
    "code": "ServiceError",
    "message": "Refresh access token failed with status code: 401"
  }
}
[11:42:22]POST 201 directline.start Conversation
[11:42:22]Emulator listening on http://localhost:49840
[11:42:22]ngrok listening on https://082d32c4.ngrok.io
[11:42:22]ngrok traffic inspector:http://127.0.0.1:4040
[11:42:22]Will bypass ngrok for local addresses
[11:42:25]->message hi
[11:42:26]POST 400 directline.postActivity

Solution

  • "Refresh access token failed with status code: 401" errors are almost always an issue with appId/appPass.

    Please verify:

    1. You have the correct appId/appPass from the App Registration Portal

    enter image description here

    enter image description here

    Note: If you didn't save your password, just click "New client secret" to generate a new one.

    1. Verify you set the correct appId/appPass in web.config

    enter image description here

    1. Verify that you entered the correct app/Id/appPass in Emulator:

    enter image description here


    You should also upgrade Emulator to the latest release. There was a bug in Emulator long before 4.3.3 that caused this error, but I guess there could be something similar with V3 bots, since we rarely use them.

    If this is a new bot, you should really be using V4. V3 will be deprecated July 1, 2019. Existing bots will work, but users will no longer be able to create them.