Google API invalid_grant problem

14 Jun 2015

When changing a server, I've got an authorisation error from Google API that looks like this:

{ "error" : "invalid_grant" }

This is because the date/time on the server is not correct. Google API uses OAuth, which signs request based on system's clock.

Fixing the system's clock resolves the issue.

Here is how I fix the system clock on FreeBSD:

  1. pkg install ntp
  2. service ntpd stop
  3. ntpdate -u
  4. service ntpd start

We use NTP to update the system's clock and also start NTP as a service in order to keep the clock in sync.