Skip to main content

Integrate Unity Google Play Games Sign-in with AGS Starter

Last updated on

Overview

You can integrate your Google Play Games sign-in with AGS Starter so that your players can log in to games using google credentials.

Prerequisites

To complete this procedure, you will need the following:

Unity Google Play Games Sign-in Integration with AGS Starter

Configure Google Play Games Services

Use the following steps to integrate Unity Google Play Games Sign-in with AGS Starter.

  1. Download the Google Play Games SDK for Unity and import it to Unity.
  2. Go to Google Play Console.
  3. Open Play Games Services setup.
  4. Select one of the Google API options. Choose the suitable options for your project. If this is your first time setting up Google APIs, choose No, My game doesn’t use Google APIs.

Unity Google Play Games Sign-in Integration with AGS Starter

  1. At this point, the next thing you'll need to do is configure the OAuth 2.0 Consent Screen. Click on the step marked in a red square.

Unity Google Play Games Sign-in Integration with AGS Starter

Follow the steps below to configure the OAuth2.0 screen:

  1. Define the intended User Type:
    • Choose Internal for internal testing using a developer account.
    • Choose External if you want to use an account other than a developer account to test.

Unity Google Play Games Sign-in Integration with AGS Starter

  1. Click Create. A wizard will appear to walk you through the configurations.

    In the App information section, fill in your App name and User support emails. App logo will be mandatory when the app wants to be published, but for testing, it’s better to ignore this, because if it is uploaded, you will have to wait for review to publish it.

    Unity Google Play Games Sign-in Integration with AGS Starter

  2. You can choose to ignore the App domain section. Unless you have the data, then feel free to fill out this section.

    Unity Google Play Games Sign-in Integration with AGS Starter

    NOTE

    The Authorized domains field will be automatically filled by the system once you have configured the OAuth web client.

  3. In the Developer contact information, fill the details of your developer email.

  4. Click SAVE AND CONTINUE. You will be redirected to the Scopes page.

  5. On the Scopes page, click ADD OR REMOVE SCOPES and make sure to select all of the following scopes :

    • .../auth/games
    • .../auth/games_lite
    • .../auth/drive.appdata

    Feel free to select additional scopes that your apps require.

    Unity Google Play Games Sign-in Integration with AGS Starter

  6. After you have added the scopes, click SAVE AND CONTINUE. The Test users page displays.

    Unity Google Play Games Sign-in Integration with AGS Starter

  7. To define which test users can access the OAuth 2.0 app, click ADD USER to add the user details.

    Unity Google Play Games Sign-in Integration with AGS Starter

    NOTE

    If you don't want to add test users, skip this step.

  8. Click SAVE AND CONTINUE.

  9. On the next screen, click Publish App to publish your consent screen.

Create credentials for Android

Follow the steps below to create the credentials for Android :

  1. On the Google Play Console page, go to Play Games Services configuration and click Create credentials.

    Unity Google Play Games Sign-in Integration with AGS Starter

  2. Configure your android credentials by clicking Add credential.

    Unity Google Play Games Sign-in Integration with AGS Starter

  3. The Add credential page appears. Fill in the Type field with Android and the app name field with the name you will be using. Then, you must create an OAuth Client by clicking Create OAuth Client in the Authorization section.

    Unity Google Play Games Sign-in Integration with AGS Starter

  4. Click the Create OAuth Client ID link in step 1 of the How to create an OAuth client.

    Unity Google Play Games Sign-in Integration with AGS Starter

    The Create OAuth Client ID page will be displayed on a new tab.

  5. Enter the Package name and SHA-1 certificate fingerprint of your app. If you have trouble finding the SHA-1 certificate fingerprint, please read the important note below.

    Unity Google Play Games Sign-in Integration with AGS Starter

    IMPORTANT

    There are two types of Certificate : Upload Certificate and Google App Signing Certificate. Please add both of them to Credentials and OAuth Client, so there will be two credentials and two OAuthClients with different certificates. (Repeat step number 2, but enter a different SHA-1 certificate fingerprint on step 5). You can find the certificate in the Google Play Developer page on App IntegrityApp Signing section (as shown in the image below). If you don't have it, you have to set up Internal testing and upload a blank project, with a designated keystore. See Upload Unity Project to Google Play Console section.

    Unity Google Play Games Sign-in Integration with AGS Starter

  6. After creating the OAuth Client ID, go back to the Add Credential page, scroll down to the Authorization section and select the correct OAuth Client ID that you've just created. Repeat this step one more time as you have two OAuth Client IDs.

    Unity Google Play Games Sign-in Integration with AGS Starter

  7. After you’ve added two credentials, Go back to Play Games Services configuration. The page now should look like the image below.

    Unity Google Play Games Sign-in Integration with AGS Starter

  8. Publish the changes in the Play Games Services configuration page by clicking Review and Publish.

    Unity Google Play Games Sign-in Integration with AGS Starter

Create credentials for Web

Follow the steps below to create the credentials for Web :

  1. On the Google Play Console page, go to Play Games Services configuration and click Create credentials.

    Unity Google Play Games Sign-in Integration with AGS Starter

  2. Configure your game server credentials by clicking Add credential.

    Unity Google Play Games Sign-in Integration with AGS Starter

  3. The Add credential page appears. Fill in the Type field with Game Server, and the app name with the name you will be using. Then, you must create an OAuth Client by clicking Create OAuth client in the Authorization section.

    Unity Google Play Games Sign-in Integration with AGS Starter

  4. Click the Create OAuth Client ID link in step 1 of the How to create an OAuth client.

    Unity Google Play Games Sign-in Integration with AGS Starter

  5. Select Application Type as Web application and fill in the name type as desired. You can leave the Authorized JavaScript origins field empty.

    Unity Google Play Games Sign-in Integration with AGS Starter

  6. Add the following urls to Redirect URI by using the following formats:

    • URI 1: https://{namespace}.dev.gamingservices.accelbyte.io
    • URI 2: https://{namespace}.dev.gamingservices.accelbyte.io/iam/v3/platforms/google/authenticate

    Unity Google Play Games Sign-in Integration with AGS Starter

  7. Click Save. You will then receive Client ID and Client Secret. Please write them down as you will use them later.

  8. After creating the OAuth Client ID, please add the credentials by opening the Add credential page on step 3, select the OAuth Client ID that you have already created.

    Unity Google Play Games Sign-in Integration with AGS Starter

  9. Publish the changes in the Play Games Services configuration page.

Configure Accelbyte Google Login

Follow the steps below to Configure Accelbyte Google Login :

  1. Go to Admin Portal, and go to the designated game, expand User Management, click Login Methods and select Google.

    Unity Google Play Games Sign-in Integration with AGS Starter

  2. The Create Configuration form appears.

    Unity Google Play Games Sign-in Integration with AGS Starter

    • Enter the Client ID and Client Secret that you received when creating credentials for web (step number 7).
    • Add the Redirect URI using the following format: https://{namespace}.dev.gamingservices.accelbyte.io
  3. Click Create.

Configure Google Login Setup on Unity Project

Follow the steps below to configure google login setup on Unity project :

  1. Open Play Games Services configuration page.

  2. Copy the resources from Google Play Games Services configuration panel by clicking Get Resources.

    Unity Google Play Games Sign-in Integration with AGS Starter

  3. The Resources page appears. Copy the XML resources.

    Unity Google Play Games Sign-in Integration with AGS Starter

  4. Open Unity.

  5. Navigate to Window -> Google Play Games -> Setup -> Android Setup.

  6. Paste the XML resources that you copied earlier and add the Client ID on the bottom panel from Create credentials for Web section (step number 7).

    Unity Google Play Games Sign-in Integration with AGS Starter

  7. Click Setup.

  8. Add Unity Script named Login.cs (this name can be anything).

  9. Add the following snippet on your Login script.

    This is an example of the full code:

    public class Login : MonoBehaviour
    {
    void Awake()
    {
    InitPlayGames();
    }

    //This code will be used for initialization
    void InitPlayGames()
    {
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    .RequestServerAuthCode(true)
    .Build();

    PlayGamesPlatform.InitializeInstance(config);

    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.Activate();
    }

    //Code to Google Sign In, should be called when click google sign in button
    public void GoogleSignIn()
    {
    Social.localUser.Authenticate((isAuthenticate, debug) =>
    {
    if (isAuthenticate)
    {
    //It means success
    ConnectToAccelbyteUsingGoogle(PlayGamesPlatform.Instance.GetServerAuthCode());
    }
    else
    {
    //It means failed
    }

    });
    }

    //Code to pass AuthCode to Accelbyte service, should be called when google sign in succeeded
    void ConnectToAccelbyteUsingGoogle(string Token)
    {

    User user = AccelBytePlugin.GetUser();

    user.LoginWithOtherPlatform(PlatformType.Google, Token, (Result<TokenData, OAuthError> result) =>
    {
    Debug.Log(result.ToJsonString());
    Debug.Log(result.Value.ToJsonString());
    Debug.Log(result.Value.user_id);
    });
    }
    }
  10. Attach the Login script to any GameObject in the active scene.

  11. Build the AAB project using the right keystore

Upload Unity Project to Google Play Console

  1. Build Unity Project in AAB format with designated keystore. It can be a blank project if you still have yet to configure your Google Login to Unity project.

  2. Navigate to Google Play Developer ConsoleTestingInternal Testing.

  3. Select Create New Release.

    Unity Google Play Games Sign-in Integration with AGS Starter

  4. Upload your AAB files.

    Unity Google Play Games Sign-in Integration with AGS Starter

  5. After the files are successfully uploaded, you have to review the releases by clicking the Review Release button in the bottom right corner.

  6. You will be prompted to fill the mandatory fields about the app details. Then press Publish in the upper right corner.

    Unity Google Play Games Sign-in Integration with AGS Starter

  7. You can try to test the Login on your android devices. Click this link to read how to set up a testing user that can access the published app on the Internal testing track.

    If everything went correctly, the result should look like in the video below.