Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API return invalid_grant in production but not in local

I have a very strange exception using google API in python. The goal is to check on server side the validity of a token corresponding to an in-app subscription from an Android application.

So to do that, we have a service account attached to our Google Play account and we try to authentify our request using oauth through the p12 key (converted into a pem certificate in order to remove the pass phrase):

from apiclient.discovery import build
from httplib2 import Http
from oauth2client.client import SignedJwtAssertionCredentials

with open("googleplay.pem") as f:
    private_key = f.read()
credentials = SignedJwtAssertionCredentials(GOOGLE_CLIENT_EMAIL, private_key, scope=['https://www.googleapis.com/auth/androidpublisher'])
http_auth = credentials.authorize(Http())
client = build('androidpublisher', 'v2', http=http_auth)

And this works perfectly on my computer. But the last line triggers an exception on my servers: invalid_grant

I don't understand where does that could come from! If you can help we with that, it would we marvelous!

some additional code I used to convert the p12 certificate to a pem certificate:

openssl pkcs12 -in privatekey.p12 -nodes -nocerts > privatekey.pem

Then I removed the first 4 lines.

Thanks in advance!

like image 354
arthur Avatar asked Aug 13 '15 16:08

arthur


1 Answers

I had exactly the same issue.

I fixed it by syncing the system time using NTP

This will only work on a root server. Not on a virtual server. Contact your server hosting provider if you rent a vServer.

I hope this helps :)

like image 157
Tim Woocker Avatar answered Nov 03 '22 06:11

Tim Woocker