Intermittently getting ERROR: ChatConnector: receive - invalid token. Check bots app ID & Password.
Using BotBuilder with Node.js, I am intermittently (every 3-6 success, I get 1 failure) getting
ERROR: ChatConnector: receive - invalid token. Check bots app ID & Password.
I get this error interacting with my bot through FB Messenger and the "Test connection to your bot" button on the bot framework site but not through Skype. I looked into the code to see where this error is coming from.
In the botbuilder/lib/bots/ChatConnector.js line 118
if (decoded.payload.aud != _this.settings.appId || decoded.payload.iss != issuer || now > decoded.payload.exp || now < decoded.payload.nbf) {
I printed both "now" and "decoded.payload" and found the issue to be that the error occurs when now < decoded.payload.nbf
A sample failed call will have now = 1468635156.905 and decoded.payload.nbf = 1468635157 I made sure that the time on my server was synced with NTP and still ran into the problem.
A quick fix is to do what @raphael2711 mentioned in #710 and go to line 117 of botbuilder/lib/bots/ChatConnector.js and add + 100 like so:
var now = new Date().getTime() / 1000 + 100;
However, you need to do 1 more step to avoid getting the following error:
NotBeforeError: jwt not active at Object.module.exports as verify at /root/nodeserver/bot/demoBotApp/msbf/node_modules/botbuilder/lib/bots/ChatConnector.js:140:43 at ChatConnector.ensureCachedKeys (/root/nodeserver/bot/demoBotApp/msbf/node_modules/botbuilder/lib/bots/ChatConnector.js:81:13) at ChatConnector.verifyBotFramework (/root/nodeserver/bot/demoBotApp/msbf/node_modules/botbuilder/lib/bots/ChatConnector.js:114:18) at IncomingMessage.
(/root/nodeserver/bot/demoBotApp/msbf/node_modules/botbuilder/lib/bots/ChatConnector.js:39:27) at emitNone (events.js:86:13) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:934:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9)
You need to change line 133 to the following:
decoded = jwt.verify(token, secret,{clockTolerance:100});
The reason for this is that inside jsonwebtoken's verify.js, they do one more comparison of the payload's nbf value and the server time and it is running into the same issue.
The above issue occurred in v3.0.1 I have verified it is now fixed in v3.1.1. Thx @Stevenic
It looks like this is still happening in v3.1.1.
I had to remove the entire jwt token validation check because the timestamp i receive seems to be too far off from the system clock, which seems to be correct to me...
Adding Dan who can hopefully help with this.
I think I figured out why this was happening to me. I had my whole setup in docker containers (app.js, backend, db etc.) and forwarded traffic to the nodeJS container through ngrok. I think there is some issue with certificates on Native Docker for Mac. The solution (or rather workaround) was to move the nodeJS app outside the container.
What type of network did you run your docker container with? I recently had a different issue where I had to run my docker network as host for my bot to work correctly.
Glad you found the issue...Good to know that can cause issues
Hi Team! I followed the instructions mentioned in the Getting Started section and I am still finding the mentioned error. Please advise. Sagar
Hi @sagarsea, we have a troubleshooting guide for errors like these: https://docs.botframework.com/en-us/support/troubleshooting-bot-framework-authentication/#navtitle
If you follow the steps in the guide and are still seeing problems, please open a new issue and we can take a closer look. Thanks --Dan
TAGS (to assist Search Indexing) 403 Forbidden "name": "NotBeforeError" 403 Forbidden "message": "jwt not active" JWT Timeout NTP SYNCHRONIZATION
Hello- This issue recurs in "botbuilder": "3.14.0" ; exact same conditions (1) - BOT running on a localhost (CentOS7) behind a FW; (2) therefore, we use NGROK tunnel (3) from my MacBook, sitting in Starbucks, using BOT Emulator the BOT on CentOS 7 (which is behind the Firewall) is reachable and responses are being received in the BOT Emulator (4) when I use WebChat on Azure Portal, I get the "NotBeforeError", "message":"jwt not active" and "date": "2018-02-06T01:33:42.000Z" is the timestamp from the WebChat client on Azure.
[5] Upon deeper investigation, I found that the localhost (behind the F/w) running the BOT is six-and-half minutes behind the UTC; next step is to re-synchronize , since this is an experimental VM and NTP is OFF right now. THANKS to "oztheozoz" for writing down NTP hint.
[6] SYNCHRONIZING the timestamp to UTC via NTP fixed the clock time mis-match due to drift of the VM. Thanks a TON to all the folks who commented.
Thanks to everyone for their comments;