Nodejs-dialogflow: Invalid JWT when running inside Docker

Created on 28 Jan 2020  路  6Comments  路  Source: googleapis/nodejs-dialogflow

I created a simple fulfillment server that takes user input and gets/forwards the appropriate response from Dialogflow. The code is pretty simple, it's all contained in the index.js file of the master branch of this repository. When I ran this through Heroku (at https://metbot-fulfillment.herokuapp.com/), everything worked fine. If you send a POST request to that URL with this body:

 {
  "session": "8d13aa8-2999-4f71-b233-39cbf3a824a0",
  "queryResult": {
    "queryText": "Hello"
  }
}

you should receive a valid response. However, I needed to move the app off of Heroku and onto a standard Ubuntu server, so I wanted to use Docker to make the future process of moving between servers simple. Yet when I send the same body to my Docker container, I receive this error:

(node:1) UnhandledPromiseRejectionWarning: Error: 400 undefined: Getting metadata from plugin failed with error: invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.
    at Object.callErrorFromStatus (/usr/src/app/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Http2CallStream.call.on (/usr/src/app/node_modules/@grpc/grpc-js/build/src/client.js:96:33)
    at Http2CallStream.emit (events.js:203:15)
    at process.nextTick (/usr/src/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:75:22)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

I tried searching for solutions and saw that the system clock being off could be a culprit, and indeed my clock was off by a few minutes (but that shouldn't have affected the validity of 60 minute token right?). Regardless, I had the offset corrected and I continue to get the same error. Is this an issue with Docker? Or perhaps the base container I'm using? This is my Dockerfile.

Environment details

  • OS: 14.04
  • Node.js version: 10 (Docker)
  • npm version: Same as above
  • dialogflow version: ^0.12.2

Steps to reproduce

  1. Clone the docker branch, build and run the container
  2. Try sending the above POST request
p2 bug dialogflow

Most helpful comment

I'm not sure what's changed (hence why I'm hesitant to close this before getting any insight) but my container started working. All I've done is leave it alone for a day, is it possible that due to the initial time sync issues the tokens were off but giving it time to reset solved the issue?

I found this while looking into a similar error, and people have said this can happen if the server clock is out of sync for some reason, so restarting your docker container may have fixed it, or something else might have happened to fix that discrepancy. Just an FYI in case that was your issue too!

All 6 comments

I'm not sure what's changed (hence why I'm hesitant to close this before getting any insight) but my container started working. All I've done is leave it alone for a day, is it possible that due to the initial time sync issues the tokens were off but giving it time to reset solved the issue?

I'm not sure what's changed (hence why I'm hesitant to close this before getting any insight) but my container started working. All I've done is leave it alone for a day, is it possible that due to the initial time sync issues the tokens were off but giving it time to reset solved the issue?

I found this while looking into a similar error, and people have said this can happen if the server clock is out of sync for some reason, so restarting your docker container may have fixed it, or something else might have happened to fix that discrepancy. Just an FYI in case that was your issue too!

I had my hour bad configured, 1 hour offset in Windows. I adjust the time and worked

@ROODAY would yo be able to check whether you were running in to a clock drift issue?

@bcoe Unfortunately not as now the app is being run as a systemctl service without docker so I don't have the original environment anymore.

@ROODAY I'm going to close this issue out for now, as I think clock drift is the most likely culprit. Please feel free to follow up if you do bump into issues again with Docker.

Was this page helpful?
0 / 5 - 0 ratings