Android 游戏服务返回的玩家ID能被黑客攻击吗

Android 游戏服务返回的玩家ID能被黑客攻击吗,android,google-play-services,google-play-games,Android,Google Play Services,Google Play Games,我已经在我的游戏中实现了谷歌游戏服务,我想知道游戏服务返回的玩家ID是否可以被黑客攻击 我将使用该ID从数据库检索播放器数据。我知道我可以请求ID令牌,并通过将其发送到服务器并在那里验证来使用它来验证玩家身份。但是,请求ID令牌将要求用户允许应用程序“知道你在谷歌上是谁”,我不想显示该权限 您真正想要使用的是服务器身份验证代码。流程是: 用户在设备上正常登录您的游戏。当你 构建客户端连接,请求ServerAuthCode。成为 生成 String webclientId = getString(

我已经在我的游戏中实现了谷歌游戏服务,我想知道游戏服务返回的玩家ID是否可以被黑客攻击


我将使用该ID从数据库检索播放器数据。我知道我可以请求ID令牌,并通过将其发送到服务器并在那里验证来使用它来验证玩家身份。但是,请求ID令牌将要求用户允许应用程序“知道你在谷歌上是谁”,我不想显示该权限

您真正想要使用的是服务器身份验证代码。流程是:

  • 用户在设备上正常登录您的游戏。当你 构建客户端连接,请求ServerAuthCode。成为 生成

    String webclientId = getString(R.string.webclient_id);
    // Request authCode so we can send the code to the server.
    GoogleSignInOptions options = new GoogleSignInOptions
                      .Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                      .requestServerAuthCode(webclientId)
                      .build();
    
    
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Games.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API, options)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    
  • 登录完成后获取身份验证代码,并将身份验证代码发送到服务器

    @Override
    protected void onActivityResult(int requestCode, int responseCode,
                                Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        Log.d(TAG, "onActivityResult RC_SIGN_IN, responseCode="
                + responseCode + ", intent=" + intent);
        GoogleSignInResult result =
                Auth.GoogleSignInApi.getSignInResultFromIntent(intent);
        if (result.isSuccess()) {
            sendToServer(result.getSignInAccount().getServerAuthCode(););
        } else {
            showSignInError(result.getStatus().getStatusCode());
        }
    
  • 在服务器上,为该用户的访问令牌交换身份验证代码

         GoogleTokenResponse tokenResponse =
                new GoogleAuthorizationCodeTokenRequest(
                        HTTPTransport,
                        JacksonFactory.getDefaultInstance(),
                        "https://www.googleapis.com/oauth2/v4/token",
                        clientSecrets.getDetails().getClientId(),
                        clientSecrets.getDetails().getClientSecret(),
                        authCode,
                        "")
                        .execute();
    
  • 然后,服务器可以验证访问令牌以获取用户ID 安全地

        ApplicationVerifyResponse resp = gamesAPI.applications().verify
            (applicationId).execute();
        Log.d(TAG, "The player id is " + resp.getPlayerId());
    
  • 有一个示例演示了如何在GitHub中执行此操作: