Android Google+ Integration - Repeated Userrecoverableauthexception

Always getting UserRecoverableAuthException for NEED_PERMISSION even when verify app from device?

This question has also been asked here:

Android Google+ integration - repeated UserRecoverableAuthException

No solution has been found yet, but the investigation is ongoing.

Always getting NEED_PERMISSION Exception even after giving permission

Use GoogleAuthUtil.getToken to retrieve the exchange code.

final private String CLIENT_ID = "abc123.apps.googleusercontent.com";
final private List<String> SCOPES = Arrays.asList(new String[]{
"https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/drive"
});

String scope = String.format("oauth2:server:client_id:%s:api_scope:%s", CLIENT_ID, TextUtils.join(" ", SCOPES));
String exchangeCode = GoogleAuthUtil.getToken(context, accountName, scope);

A working sample is on https://github.com/googledrive/crossclientoauth2-android and it's more in detail explained on https://developers.google.com/drive/auth/android#cross-client_identity

Android Google+ unable to get auth code

I don't know if you modified the line to post the question but looking at the code you posted, this line is wrong:

String scopes = "oauth2:server:client_id:<My server client ID>:scopesString";

It should be:

String scopes = "oauth2:server:client_id:" + SERVER_CLIENT_ID + ":api_scope:" + scopeString;

Google Plus Single Sign On Server Flow - Google_AuthException Error fetching OAuth2 access token, message: 'invalid_grant'

This issue is now resolved. This was due to the implementation on the One Time Code exchange with the server

As specified in the my issue above, I used the photohunt example to do the exchange with my server. The Android code can be found on the below link

https://github.com/googleplus/gplus-photohunt-client-android/blob/master/src/com/google/plus/samples/photohunt/auth/AuthUtil.java

One line 44 it reads this

byte[] postBody = String.format(ACCESS_TOKEN_JSON, sAccessToken).getBytes();

This will only work if on the server side you handle the JSON. I did not.

When calling up $client->authenticate($code); in php, $code had a JSON string and therefore when calling https://accounts.google.com/o/oauth2/token the authorization code was wrong.

So it was easy as I was not sending the code in the right format.

I found this out when digging and testing https://accounts.google.com/o/oauth2/token and created a manual cURL to test the token.

As provided in the Google+ API it was stated that all examples included a One Time Code exchange, but I think the code across all platform are not consistent and one has to double check themselve to make sure everything flows correctly, which was my mistake.



Related Topics



Leave a reply



Submit