I'm trying to follow this flow to sign-in a user on an android app using a python server backend:
https://developers.google.com/+/web/signin/server-side-flow
I'm successful in getting the authorization code from the Android app, but when I try to exchange this code for an access token from the server, I'm getting an "invalid_request" error.
From the Android app, I'm using the same client_id as the one on the server which is listed under "Client ID for web application" in my console. I've verified the redirect_uri is correct. Is it not possible to generate an authorization code from an Android client and use a server to exchange for the access token?
My python code is:
def auth_params(self):
client_id, client_secret = self.get_key_and_secret()
return {
'grant_type': 'authorization_code',
'code': self.data.get('code', ''), # auth code from app
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': self.get_redirect_uri()
}
@classmethod
def auth_headers(cls):
return {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
def auth_complete(self, *args, **kwargs):
params = self.auth_params()
request = Request('https://accounts.google.com/o/oauth2/token', data=urlencode(params),
headers=self.auth_headers())
try:
response = simplejson.loads(urlopen(request).read())
except HTTPError, e:
print 'fml'