botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Node.js SDK] Error "Refresh access token failed with status code: 400" when talking to bot

Open carvalThi opened this issue 8 years ago • 4 comments

Bot Info

  • SDK Platform: Node.js
  • SDK Version: 3.13.1
  • Active Channels: web console
  • Deployment Environment: Web app bot on Azure

Issue Description

When talking to my chatbot, i keep getting the following error message : Error: Refresh access token failed with status code: 400 at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder\lib\bots\ChatConnector.js:697:36) at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:185:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (D:\home\site\wwwroot\node_modules\request\request.js:1157:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (D:\home\site\wwwroot\node_modules\request\request.js:1079:12) at IncomingMessage.g (events.js:291:16) at emitNone (events.js:91:20)

This keeps happening for a week now.

Code Example

I've tried the basic web app bot code and it still gives me the same issue.

Reproduction Steps

  1. Talk to bot
  2. Get the error message

Expected Behavior

Reply anything instead of getting error message

carvalThi avatar Jun 10 '18 14:06 carvalThi

To complete the issue, i ran a postman request : curl -X POST
https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
-H 'Cache-Control: no-cache'
-H 'Content-Type: application/x-www-form-urlencoded'
-H 'Postman-Token: 766d0732-a60d-4d57-ad95-0dee20fedd3c'
-d 'grant_type=client_credentials& client_id=xxxx& client_secret=yyyy &scope=https%3A%2F%2Fapi.botframework.com%2F.default'

but got an error saying that my app id was not found in the directory botframework ...

carvalThi avatar Jun 10 '18 15:06 carvalThi

-d 'grant_type=client_credentials&
client_id=xxxx&
client_secret=yyyy
&scope=https%3A%2F%2Fapi.botframework.com%2F.default'

This doesn't look right based on this Stack Overflow post, have you tried formatting your curl request the way they mention in the post?


To complete the issue, i ran a postman request :

Are you using Postman or curl?


Have you tried updating the version of the bot to the latest version?

Is it possible the appId or appPassword changed and is no longer valid? This would however normally result in a 401. Did you change any of the logic in the ChatConnector class for token refreshes?

stevengum avatar Jun 12 '18 16:06 stevengum

Closing issue due to inactivity.

stevengum avatar Jun 21 '18 22:06 stevengum

I am facing the same error. I am using Bot framework ver 4 /Nodejs.I tried to call the curl. I am getting the same error

"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'fb7bedbc-b786-47e7-89b7-26b2b44c0d14' was not found in the directory 'botframework.com'.

C:\Users\de>curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id=fb7bedbc-b786-47e7-89b7-26b2b44c0d14&client_secret=abcd123&&scope=https%3A%2F%2Fapi.botframework.com%2F.default" {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'fb7bedbc-b786-47e7-89b7-26b2b44c0d14' was not found in the directory 'botframework.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant\r\nTrace ID: 790383e5-df47-48c1-9d82-506295280700\r\nCorrelation ID: b92be278-3858-4602-a7ab-c7117f61edfc\r\nTimestamp: 2018-11-01 23:09:54Z","error_codes":[700016],"timestamp":"2018-11-01 23:09:54Z","trace_id":"790383e5-df47-48c1-9d82-506295280700","correlation_id":"b92be278-3858-4602-a7ab-c7117f61edfc"}

deepanigi avatar Nov 01 '18 23:11 deepanigi