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

38,160

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

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

Solution 5

I was stumped on this for hours. I even posted this question. Turns out I had overlooked something that should have been somewhat obvious. My dev server is a Linux virtual machine. The clock on my VM was 8 days behind my local system clock. So while my local clock was correct, I overlooked the fact that my VM was several days delayed. Hopefully, this can save the absent-minded some time.

Share:
38,160
wataru
Author by

wataru

Software developer with 5 years of professional experience in an IT company. I am a passionate engineer, who loves learning technology. My goal is to work with fellow professionals, while positively influencing each other. Making the world a better and more efficient place through technology is what I strive for.

Updated on November 23, 2020

Comments

  • wataru
    wataru over 3 years

    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?

  • wataru
    wataru about 8 years
    It is possibly the answer, because I have seen my server's clock is not in sync sometimes. I appreciate that
  • plowman
    plowman over 7 years
    This appears to be the solution. Specifically, the Docker container I'm using has a busted clock even though my system clock is fine.
  • Caique Moreira
    Caique Moreira about 7 years
    had the exact same problem here. My computer's clock was 5 minutes out of sync. Thanks for the answer
  • Zulqarnain Mustafa
    Zulqarnain Mustafa almost 7 years
    I was facing that issue with Xcode, but after reseting the time, my project run successfully.
  • Sergio Gonzalez
    Sergio Gonzalez over 6 years
    just running ntpdate ntp.ubuntu.com worked for me, thanks!
  • gustavoanalytics
    gustavoanalytics over 6 years
    So this keeps on happening how can I make sure that the server time is matched up all the time? I keep on getting the same error...
  • dieend
    dieend over 5 years
    I was receiving this when I run unit tests and forgot that I also patch the time (yes, I have mock, but I was testing it without mock to check credentials)
  • Dilushan
    Dilushan about 4 years
    ya. me too. probably because Im hibernating my machine. So its eventually confusing docker
  • Saeed El Dah
    Saeed El Dah about 4 years
    same here with containerized .net core app.
  • Liam
    Liam about 4 years
  • Liam
    Liam about 4 years
  • Ismail El Moudni
    Ismail El Moudni over 3 years
    after I tried everything, I found your answer, and it worked for me!
  • I Stand With Israel
    I Stand With Israel over 3 years
    That solved it for me. My computer's clock was off by a few hours. Readjusted it and the error went away.