Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Token must be a short-lived token and in a reasonable timeframe

I am having the same error as this. In my case it is happening when the app is trying to upload a file via Google Cloud Client API.

POST https://www.googleapis.com/oauth2/v4/token
400 Bad Request
Invalid JWT: Token must be a short-lived token and in a reasonable timeframe

How I load the token is reading a service-account json file, and attach it to CURLOPT_HTTPHEADER in PHP. It did work properly for the past one month, so I am guessing that Google changed the way of authorization.

Has anyone faced & solved this?

like image 562
wataru Avatar asked Mar 23 '16 22:03

wataru


4 Answers

I stumbled upon the same issue at roughly the same time, so I expected a generic bug of Google but here is what had happened on my computer :

raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe

was caused in my case by a poor synchronisation of the computer's clock where the code was executed that had a lag of 5 minutes (due to a faulty battery for the internal clock). It started working again when I manually changed the internal time of my computer to the correct one.

This solution was mentionned here, but not with the full error message

like image 113
WNG Avatar answered Nov 11 '22 12:11

WNG


I had the same issue, I found that my server was delayed by 8 minutes. I configurated the NTP server and magically it was solved

like image 32
Eddy López Avatar answered Nov 11 '22 11:11

Eddy López


For those getting that error for a containerized app and ending up here,

I had the same issue when using my token from a containerized app. Rebooting Docker Desktop (Windows) did it for me.

I had this setup for weeks before getting that issue for the first time.

like image 7
Dave Avatar answered Nov 11 '22 10:11

Dave


Same problem encountered....manually reset my computer's clock to the current time....problem resolved.

like image 6
Gurdeep Singh Avatar answered Nov 11 '22 11:11

Gurdeep Singh