Google APIのOAuth2認証でinvalid grantと出る件
現象
ソース
google = require 'googleapis' CLIENT_ID = '...' CLIENT_SECRET = '...' oauth2Client = new google.auth.OAuth2 CLIENT_ID, CLIENT_SECRET, 'postmessage' if error console.log 'authorize error:', util.inspect(error) return ...
ただ認証するだけです。
しかし、実行するとこんなエラー
error=invalid_grant
しかも、ローカル(Mac)で実行すると動くのにサーバーだとエラーになって???となった。
原因
公式に書いてあったわ。
Invalid Grant
If you receive an invalid_grant error response when attempting to use a refresh token, the cause of the error may be due to the following reasons:
- Your server's clock is not in sync with NTP.
Core Reporting API - Authorization - Google Analytics — Google Developers
あい、すいません、NTP入ってませんでした……
Macは標準でNTP動いてますもんね……
NTPを入れる
$ sudo aptitude install ntp
これで動きました。
Ansibleの設定から完全に抜けてたわ……