'Error while activating the gcloud service account from command line

I'm referring to this URL https://cloud.google.com/speech/docs/getting-started to get started with the google speech API. As the site suggests,I followed the following steps

  • Create or select a project.
  • Enable the Cloud Speech API for that project
  • Create a service account
  • Download a private key as JSON

I have the gcloud installed on my command-line. Now when i try to activate service account using the below command,

gcloud auth activate-service-account --key-file=my-service-account-key-file

i'm getting the below error.

ERROR: (gcloud.auth.activate-service-account) There was a problem refreshing your current auth tokens: invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values and use a clock with skew to account for clock differences between systems.

I suspect it's the problem with the time zone. I'm running the command from my AWS EC2 instance.



Solution 1:[1]

I think there is a cache with this somewhere, after around 10 minutes it resolved itself.

I ran into this error when I created a new key for a service account and deleted the old one.

Solution 2:[2]

In my case fixing the date solved the issue. If you are in linux, you can change the date by executing

date -s "Thu Feb 24 22:32:36 EET 2022"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris Stryczynski
Solution 2 Jeremy Caney