私はユニティアプリを持っており、google * .aarバージョン9.4.0のgoogle-play-gamesプラグインを使用しています。私は最近、バックエンド(Google App Engine)をphpからjavaに変更しました。私の問題は次のとおりです:php serverauthcodeは、ユーザーデータ(JWT形式)を取得するために使用されます - うまくいきました。だから私はJavaサーブレットに変更し、有効なidtokenを取得するために2日以来失敗しています。私は自分のアプリからサーバーの認証コードを受け取ることができ、GoogleAuthorizationCodeTokenRequest(コードスニペット参照)によって有効なトークンレスポンスが作成されています。残念ながら、idtokenの内容は含まれていませんが、有効なauth_tokenはありません。だから、私はユーザーIDを取得することはできません。私がtokenResponse.parseIdToken()を呼び出すと、 NullPointerExceptionが発生して失敗しています。Unity/Android ServerAuthCodeにバックエンドのidTokenがありません
サーブレットコード(AUTHCODEは、私はGAEにユニティ内部のプレイゲーム - プラグインから送信serverAuthCodeです):
// (Receive authCode via HTTPS POST)
// Set path to the Web application client_secret_*.json file you downloaded from the
// Google Developers Console: https://console.developers.google.com/apis/credentials?project=_
// You can also find your Web application client ID and client secret from the
// console and specify them directly when you create the GoogleAuthorizationCodeTokenRequest
// object.
String CLIENT_SECRET_FILE = "/mypath/client_secret.json";
// Exchange auth code for access token
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(
JacksonFactory.getDefaultInstance(), new FileReader(CLIENT_SECRET_FILE));
GoogleTokenResponse tokenResponse =
new GoogleAuthorizationCodeTokenRequest(
new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
clientSecrets.getDetails().getTokenUri(),
clientSecrets.getDetails().getClientId(),
clientSecrets.getDetails().getClientSecret(),
authCode,
REDIRECT_URI) // Specify the same redirect URI that you use with your web
// app. If you don't have a web version of your app, you can
// specify an empty string.
.execute();
String accessToken = tokenResponse.getAccessToken();
// Get profile info from ID token -> HERE IT THROWS AN EXCEPTION.
GoogleIdToken idToken = tokenResponse.parseIdToken();
GoogleIdToken.Payload payload = idToken.getPayload();
String userId = payload.getSubject(); // Use this value as a key to identify a user.
String email = payload.getEmail();
boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
String name = (String) payload.get("name");
String pictureUrl = (String) payload.get("picture");
String locale = (String) payload.get("locale");
String familyName = (String) payload.get("family_name");
String givenName = (String) payload.get("given_name");
トークン応答は(今その無効)のようになります。
{
"access_token" : "ya29.CjA8A7O96w-vX4OCSPm-GMEPGVIEuRTeOxKy_75z6fbYVSXsdi9Ot3NmxlE-j_t-BI",
"expires_in" : 3596,
"token_type" : "Bearer"
}
私のPHP GAEでは、私はいつも私の暗号化されたデータを含んでいたこのconstuctの中にidTokenを持っていました。しかし、それは今行方不明です!だから私はJavaで何か別のことをするか、Googleコンソールで新しいOAuth 2.0クライアントを作成するのに間違いを犯しました。
私は手動経由accessTokenチェック:私は見ていない何かが https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.CjA8A7O96w-vX4OCSPm-GMEPGVIEu-RTeOxKy_75z6fbYVSXsdi9Ot3NmxlE-j_t-BI
{
"issued_to": "48168146---------.apps.googleusercontent.com",
"audience": "48168146---------.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/games_lite",
"expires_in": 879,
"access_type": "offline"
}
ありますか?ヘルプは非常に高く評価されています...