Android getServerAuthCode () without additional permissions

I am trying to authenticate an Android user using a server server:

  • the application calls getServerAuthCode()and forwards the authorization code using HTTPS to our BE
  • BE exchanges server authorization code for access token using GoogleAuthorizationCodeTokenRequest
  • BE passes the access token to www.googleapis.com/games/v1/applications, which returns playerId (all I really need is not interested in email and other user information).

The procedure is described here:

and here

If I use the instruction since 2017, I can get ServerAuthCode () without asking for additional permissions. The only permission: Google Play / Game management for this game. This is possible by specifying GoogleSignInOptions.DEFAULT_GAMES_SIGN_INwhich is available using play-service 10.2.1. I cannot use 10.2.1 due to third-party dependencies.

Article 2016 explains how the getServerAuthCode()"old" way (using the game services 9.6.1), but I can not do without asking for additional permissions.

If I do this like this, I will ask "Know who you are on google":

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestServerAuthCode(serverClientId)
    .requestScopes(Games.SCOPE_GAMES)
    .build();

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .build();

        ...

protected void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);

    if (request == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);

        if (result.isSuccess()) {
            GoogleSignInAccount acct = result.getSignInAccount();
            String authCode = acct.getServerAuthCode();
        }

If I .requestServerAuthCode(serverClientId)remove from gso, authCode is null.

One more thing I tried (using only Games.API login):

mGoogleApiClient = new GoogleApiClient.Builder(this, this, this)
    .addApi(Games.API)
    .build();

...

Games.GetServerAuthCodeResult result = Games.getGamesServerAuthCode(mGoogleApiClient, serverClinetId).await();

if (result.getStatus().isSuccess()) {
    String authCode = result.getCode();

I receive result.getStatus().isSuccess()=falseand result.getStatus().getStatusMessage()returns STATUS_CLIENT_RECONNECT_REQUIRED (2). In the logs I see:

[GetToken] GetToken failed with status code: NeedPermission
04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): Failed to retrieve the server auth code
04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission

Finnaly, , , - " ":

Scope scope = new Scope("https://www.googleapis.com/auth/userinfo.profile");

mGoogleApiClient = new GoogleApiClient.Builder(this, this, this)
    .addApi(Games.API)
    .addScope(scope)
    .build();

, - , 9.6.1, - (, 2017, 10.2.1, DEFAULT_GAMES_SIGN_IN).

- , , ( playerId) ?

+4
1

, . , , - ( ) auth playerId.

+1

Source: https://habr.com/ru/post/1674518/


All Articles