I have a client and server app that needs to access a users g+ profile after on the SERVER side once they've validated on the client (android)
I'm gettin an ID token on the client side by this
@Background
void getAccessToken() {
String scopes = "audience:server:client_id:xxxxxxxxxxxxx.apps.googleusercontent.com";
Log.d(TAG,scopes);
try {
accessToken = GoogleAuthUtil.getToken(this,mPlusClient.getAccountName(),scopes);
Log.d(TAG,accessToken);
getPlusFriends();
}
catch (IOException transientEx) {
Log.e(TAG, transientEx.getMessage());
return;
}
catch (UserRecoverableAuthException e) {
Log.e(TAG, e.getMessage());
accessToken = null;
}
catch (GoogleAuthException authEx) {
Log.e(TAG, authEx.getMessage());
return;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
Which will give me a long ID token as described in this blog http://www.tbray.org/ongoing/When/201x/2013/04/04/ID-Tokens
I think I'm supposed to send that token to my server where I need to do something to turn it into an access_token. I can verify that the id token? is good by sending a curl request to
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
which gives back a json string like this
{
"issuer": "accounts.google.com",
"issued_to": "xxxxxxxxxxxxxx.apps.googleusercontent.com",
"audience": "xxxxxxxxxxxxxx.apps.googleusercontent.com",
"user_id": "123456",
"expires_in": 3362,
"issued_at": 1382577073,
"email": "myemail@something",
"verified_email": true
}
php server
\Config::load('google_api', 'google');
$key = Config::get('google.client_id');
$secret = Config::get('google.client_secret');
$scopes = Config::get('google.scopes');
$client = new Google_Client();
$client->setClientId($key);
$client->setClientSecret($secret);
$client->setScopes($scopes);
$client->setState('offline');
$client->authenticate($token);
where the issued_to is my client id for the Android app in the Google APIs console and the audience is the client is of my web app, seems right so far I think.
So now I'm using the php client and not really sure what to do from there. I tried to validate the api client using the id token but I just get the error 400 - Error fetching OAuth2 access token, message: 'invalid_grant'
I'm not sure if I'm supposed to try to authenticate the PHP Google+ client using that ID token or some how exchange it for an access token