Skip to main content
Version: 5.11.8

Using Google Play Game Service V2 (GPGS2)

Incompatible with GPGS V2 (11.01 or later)

Due to Google's policy change, the next-generation player ID is applied mandatorily starting March, 2024. If you have been using GPGS V1 (-v10.14), make sure to change to GPGS V2(v11.01).

However, for GPGS V1 authentication, BACKND has been using openid instead of Play Game Services's games_lite to collect information about Google accounts. As GPGS V2 can no longer access openid, GPGS V2 has now become incompatible with the previous Google login.

As such, customers who used GPGS for BACKND's federation login must use Google login instead of GPGS V2 to proceed with the federation login.
If you are using functions such as achievements and leaderboard inside GPGS or require Play Game Service login (not Google Login), please proceed using GPGS V2.

Flow of the Process
  1. Sign in with Google account via Google Play Game Service
  2. Acquire Google Auth Code
  3. Use this Google Access Code in the Backend.BMember.GetGPGS2AccessToken() method
  4. Google access token is issued
  5. Use the Google access token to call Backend.BMember.AuthorizeFederation("accessToken", FederationType.GPGS2)

Initial Settings

1. Register the application to Google Play

Google Play Console > Create app > Release > Production or (Open, Closed, Internal) testing > Create new release

  • 1) From Google Play App Signing, click Continue to register the app signature and issue the App Signing Key Certificate.

  • 2) Upload APK or App Bundle to issue Upload Key Certificate.

  • 3) The issued app signature can be checked from Setup > App Integrity on the left. It is later used to register the app to Google Game Service.

2. Register to Google Game Service

  • 1) On the left menu, from Play Game Service > Setup and management > Configuration, select 'No, my game doesn't use Google APIs' to create a new Play Game Service project.
  • Then, in the user authentication information, click Configure OAuth consent screento enter Google Cloud Platform.

  • 2) In Google Cloud Platform, configure the OAuth consent screen.

  • 4) After configuring the consent screen, click the user authentication information in the left menu to configure User Authentication Information.
    Select Create User Authentication Information > OAuth Client ID > Android.
    Repeat this process for both App Signature > App Signing Certificate and Upload Certificate registered in Step 1 (Figure 4).

  • In Google Cloud Platform, a total of 2 OAuth 2.0 client IDs must be registered as follows.
  • 5) Add user authentication information to Play Game Service Add 2 pieces of Android user authentication information added to Google Cloud Platform in No. 4.

  • In Google Console, 2 pieces of user authentication information must be added as follows:

3. Set tester

To test GPGS, the tester must be registered in Google Console.

In the left menu, from Play Game Service > Tester > Release track, click Add trackto add a track where the app is published.

  • After that, in the Testers field, click Add tester to add a tester.

4. Set Unity

1) Unity Project - Add Google Play Games Services Plugin https://github.com/playgameservices/play-games-plugin-for-unity

Download GPGS version 11 > [current-build] folder > Import unitypackage

After importing, move to the top of Unity and click Windows > Google Play Games > Setup > Android Setup

2) Set Resources Definition

  • From Play Game Service > Setup and management > Configuration > Credentials, click View resource on the right.
  • Copy Android (XML) and paste into Unity GPGS Setting Window - Resources Definition.

3) Set Client ID

  • In the relevant project, click Google Cloud Platform > Credentials > +Create credentials.
  • Set the application type as web application and create it.
  • Copy the client ID of the created web application and paste it to Unity GPGS Setting Window - Client ID.

5. Configure BACKND Console

For communication with the BACKND server, BACKND Console requires you to enter https://auth0.thebackend.io in Authorized redirect URIs.
Additionally, in Authentication Information > Google Login Authentication Information, you must enter the client ID and client secret of GPGS-linked GCP's web client ID.

1) Google Cloud Platform > APIs & Services > Credentials > Select web client

2) Add https://auth0.thebackend.io to Authorized redirect URIs

https://auth0.thebackend.io/google/token is a URI that is registered when using withdrawal web site URL, and it is not required when implementing GPGS v2.

3) Copy the client ID and client security password

4) BACKND Console > Authentication Information > Google Login Authentication Information > Fill out the client ID and client secret

Complete

All settings required to obtain the ID token are finished.
You can now obtain the auth code using the ID registered in Google Play Console.


GetGPGS2AccessToken

public BackendReturnObject GetGPGS2AccessToken(string authCode);
public BackendReturnObject GetGPGS2AccessToken(string authCode, string redirectUri);

Parameters

ValueTypeDescription
authCodestringThe code value that is obtained after logging in with GPGS and calling the PlayGamesPlatform.Instance.RequestServerSideAccess method
redirectUristringThe redirectUri for the webClientId configured in GCP

Description

After logging in with GPGS, use the GPGS plugin to receive an authentication code that can make a request to the server.
Use the authentication code value to load the access token value used for federation login.

How to log in with GPGS V2

After getting the access token via GetGPGS2AccessToken, you must use the access token in AuthorizeFederation("access_token", FederationType.GPGS2) to log in!

The descriptions for AuthorizeFederation are as follows:

Example


string google_code = "4/0AeaYSHCuDcNr-Kai7Hx42BpreFACh3wLVEe5u7ZF-phOY8qv6lAHQ2R7a5Y3zWOqkfqocw";

BackendReturnObject bro = Backend.BMember.GetGPGS2AccessToken(google_code);

if(bro.IsSuccess()) {
string accessToken = googleCallback.GetReturnValuetoJSON()["access_token"].ToString();
}

Asynchronous

string google_code = "4/0AeaYSHCuDcNr-Kai7Hx42BpreFACh3wLVEe5u7ZF-phOY8qv6lAHQ2R7a5Y3zWOqkfqocw";

Backend.BMember.GetGPGS2AccessToken(google_code, callback => {
if(callback.IsSuccess()) {
string accessToken = googleCallback.GetReturnValuetoJSON()["access_token"].ToString();
}
});

SendQueue

string google_code = "4/0AeaYSHCuDcNr-Kai7Hx42BpreFACh3wLVEe5u7ZF-phOY8qv6lAHQ2R7a5Y3zWOqkfqocw";

SendQueue.Enqueue(Backend.BMember.GetGPGS2AccessToken, google_code, callback => {
if(callback.IsSuccess()) {
string accessToken = googleCallback.GetReturnValuetoJSON()["access_token"].ToString();
}
});

Sample Code

using BackEnd;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{

void Start() {
PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}


void ProcessAuthentication(SignInStatus status) {
if (status == SignInStatus.Success) {
GetAccessCode();
// Continue with Play Games Services
} else {
// Disable your integration with Play Games Services or show a login button
// to ask users to sign-in. Clicking it should call
// PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
}
}

public void GetAccessCode()
{
PlayGamesPlatform.Instance.RequestServerSideAccess(
/* forceRefreshToken= */ false,
code => {
Debug.Log("Google authentication code : " + code);

Backend.BMember.GetGPGS2AccessToken(code, googleCallback =>
{
Debug.Log("GetGPGS2AccessToken method call result " + googleCallback);

string accessToken = "";

if (googleCallback.IsSuccess())
{
accessToken = googleCallback.GetReturnValuetoJSON()["access_token"].ToString();
}
});
});
}
}

ReturnCase

Success cases

When the token is issued successfully
statusCode : 200

returnValue :

{
"access_token": "ya29.a0AfB_byAGc2xHeWWevNzeLGmzbOKJC5ydCpf_GaboF1PziwI6ZF3i8UqttxPM_sxJu9d76rIVH0IdPGdRLYsHySae-TdmsUUlG9-TNEuZYRQwz8CHsENfcX9hHnzvbA-JqqzLxuglfTwwV_RPvTgORgHxNsxGd5whGgaCgYKAaoSARESFQHGX2Mi7KDxujEBmU_9QeEKMUsw6A0169",
"expires_in": 3598,
"scope": "https://www.googleapis.com/auth/games_lite https://www.googleapis.com/auth/drive.appdata",
"token_type": "Bearer"
}

Error cases

When an invalid Google login information is entered in BACKND Console
statusCode : 404
errorCode : NotFoundException

When an invalid Google login information is entered in BACKND Console
statusCode : 400
errorCode : GoogleOAuthException

When an invalid client secret is entered in BACKND console
statusCode : 401
errorCode : GoogleOAuthException

When redirect URI authorized by the GCP project is not entered
statusCode : 400
errorCode : GoogleOAuthException

When the Android client is not added to the GCP project
statusCode : 400
errorCode : GoogleOAuthException


AuthorizeFederation

public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type);
public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type, string ect);

Parameters

ValueTypeDescription
federationTokenstringToken value created via each login plugin
federationTypeFederationTypeTypes of federations (FederationType.GPGS2)
ectstring(Optional) The piece of information desired to be saved from the additional information

Description

An attempt is made to sign up or log in using the Google Play Game Services member information token value.

Incompatible with GPGS V1 & Sign in with Google

GPGS V2 uses the information of Play Game Services to log in, while GPGS V1 and Sign in with Google use the information of the Google account to log in.
As such, GPGS V2 login is not compatible with users who proceeded with federation login using GPGS V1 or Sign in with Google.

using BackEnd;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{

void Start() {
PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}


void ProcessAuthentication(SignInStatus status) {
if (status == SignInStatus.Success) {
GetAccessCode();
// Continue with Play Games Services
} else {
// Disable your integration with Play Games Services or show a login button
// to ask users to sign-in. Clicking it should call
// PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
}
}

public void GetAccessCode()
{
PlayGamesPlatform.Instance.RequestServerSideAccess(
/* forceRefreshToken= */ false,
code => {
Debug.Log("Google authentication code : " + code);

Backend.BMember.GetGPGS2AccessToken(code, googleCallback =>
{
Debug.Log("GetGPGS2AccessToken method call result " + googleCallback);

string accessToken = "";

if (googleCallback.IsSuccess())
{
accessToken = googleCallback.GetReturnValuetoJSON()["access_token"].ToString();
}

Backend.BMember.AuthorizeFederation(accessToken, FederationType.GPGS2, callback =>
{
Debug.Log("BACKND login was successful. " + callback);
});
});
});
}
}

ReturnCase

Success cases

When the login is successful
statusCode : 200

When signing up as a new member is successful
statusCode : 201

Error cases

When the account is blocked
statusCode : 403
errorCode : Reason for blocking entered in the console


GPGS Login Error Case

Please refer to the GPGS github for errors that occur from GPGS login failures.

When the app closes upon trying to sign in to GPGS

Application ID(1040339826718) must be a numeric value. Please verify that your manifest refers to the correct project ID.

If the above error occurs, go to Assets > GooglePlayGames > Plugins > Android > GooglePlayGamesManifest > AndroidManifest.xml, find meta-data android:name="com.google.android.gms.games.APP_ID", and change the corresponding value's \ to \u003.