【问题标题】:GoogleTokenResponse does not contain ID token, intermittentlyGoogleTokenResponse 不包含 ID 令牌,间歇性地
【发布时间】:2016-04-08 11:18:34
【问题描述】:

有时,GoogleTokenResponse.parseIdToken() 具有 NullPointerExpection,因为令牌响应不包含 ID 令牌。在不更改任何代码的情况下,有时会有 ID 令牌,有时则没有。请注意,GoogleTokenResponse.getAccessToken() 始终有效。

在不更改任何代码的情况下,即使访问令牌始终可用,ID 令牌也会从一分钟到下一分钟丢失。

我该如何调试呢?去哪里看?

我在使用 Google Play Games API 的 Android 客户端中使用此代码获取服务器身份验证代码:

PendingResult<Games.GetServerAuthCodeResult> pendingResult =
                    Games.getGamesServerAuthCode(mGoogleApiClient, Constants.web_client_ID);
            pendingResult.setResultCallback(new ResultCallback<Games.GetServerAuthCodeResult>() {
                @Override
                public void onResult(Games.GetServerAuthCodeResult getTokenResult) {    
                    sendToServer(getTokenResult.getCode());
                }
            });

在服务器端(Google Cloud Endpoints),我使用此代码将代码交换为令牌:

try {
     tokenResponse = new GoogleAuthorizationCodeTokenRequest(
                    transport,mJFactory,
                    "https://www.googleapis.com/oauth2/v4/token",
                    web_client_ID,web_client_secret,
                    authCode,
                    "")
                    .execute();
        } ...
        String accessToken = tokenResponse.getAccessToken();
        GoogleIdToken idToken = null;
        try {
            idToken = tokenResponse.parseIdToken();  //-- FAILES HERE INTERMITTENTLY!!!!
        } ...

【问题讨论】:

    标签: android google-cloud-endpoints google-play-games google-authentication


    【解决方案1】:

    由于 Play 游戏服务似乎不保证使用 Games.getGamesServerAuthCode 的 ID 令牌,因此应遵循此 post 中的说明并按照它的建议获取 ID 令牌:

    获得访问令牌后,您现在可以调用 www.googleapis.com/games/v1/applications//verify/ 使用它 访问令牌。在标头中传递身份验证令牌,如下所示: “授权:OAuth”响应值将包含 用户的玩家 ID。

    有关完整示例,请参阅 this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-17
      • 2020-03-08
      • 2012-03-27
      • 2012-08-08
      • 2020-08-30
      • 2015-12-20
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多