Skip to main content

Set up Google Play Games as an identity provider

Last updated on July 2, 2024

Overview

This guide helps developers connect Google Play accounts to AccelByte Gaming Services (AGS). Depending on your game, you may need to set up additional features within Google Play services that we haven't listed here. For more information about setting up Google Play services, we recommend contacting your Google representative and reviewing the Google Play documentation directly.

important

This guide is intended for public use and contains limited information due to confidentiality. We recommend you refer to the full confidential guide first. To request a copy of the confidential guide, contact your AccelByte Technical Producer.

Goals

To enable the Google Play authentication method for your game with the AGS SDK.

Prerequisites

Set up Google Play

For Unreal Engine in-game login

Create a Google Android app

Create a Google App. Follow the Create and set up your app guide.

Create an Unreal Engine project app

Build your blank Unreal project in AAB format with a designated keystore. For more details about generating a keystore for your Unreal project, please read the Signing Projects for Release page.

Create a release for your Unreal Engine project

Create a release for your app. Follow the Prepare and roll out a release guide.

Set up Google Play Games Services (Unreal)

Setting up your Google Play Games Services. Follow the Setting Up Google Play Games Services guide. You will need to:

  • Create a Play Games Services project. 0 Create an OAuth consent screen in the Google Cloud Platform. On the OAuth consent screen, add these four scopes to your app:
    • openid
    • .../auth/games
    • .../auth/games_lite
    • .../auth/drive.appdata
  • Create Android and Game Server credentials.

After you're done setting it all up, review and publish.

For Unity in-game login

Create a Google Android app (Unity)

Create a Google app. Follow the Create and set up your app guide.

Set up Google Play Games Services (Unity)

Set up your Google Play Games Services. Follow the Setting Up Google Play Games Services guide. You will need to:

  • Create a Play Games Services project.
  • Create an OAuth consent screen in the Google Cloud Platform. On the OAuth consent screen, add these four scopes to your app:
    • openid
    • .../auth/games
    • .../auth/games_lite
    • .../auth/drive.appdata
  • Create Android and Game Server credentials.

After you're done setting it all up, review and publish.

Set up a Google Play Games login method

Use the following steps to set up Google Play login for your game. This will allow your players to sign in to the game using their Google Play accounts.

  1. Log in to the AGS Admin portal and choose your game namespace.

  2. On the sidebar menu, go to Game Setup > 3rd Party Configuration > Auth & Account Linking.

    Image shows the Add new login method button

  3. On the Login Methods page, click on the + Add New button. The Login Platform Configuration page appears.

  4. From the available login platforms, click on Google Play Games. The Create Configuration form appears.

    Image shows the Google Play Games platform option

  5. Fill in the form with your Google Cloud Console credentials. Fill Client ID with your Google OAuth Client ID, Client Secret with your Google OAuth Client Secret, and Redirect URI with http://127.0.0.1 (localhost).

    Image shows the Configuration form

  6. Click Create. The details page of the configuration appears.

  7. On the details page, click on the Activate button next to integration and again on the pop-up to confirm.

    Image shows the Activate confirmation message

Create an IAM client

An IAM client is a representation of the game client that you want to release on your target platform. Learn more about IAM Clients in Manage access control for applications.

In-game login instructions

By following this documentation, you can integrate your game sign-in process using the AGS SDK so your players can log in to games using their Google Play Accounts. For a player to log in to your game or platform with Google credentials, the game needs to pass the Auth token from the Google platform that has the credentials the player is using to the publisher platform.

The setup for each game engine is different. Choose your game engine from the available tabs.

In-game login integration (Unreal)

Create Unreal Engine Project

After creating a new Unreal Engine project you will need to set and configure several things inside your project

Enable OnlineSubsystemGoogle Plugins and Service Configurations

  1. Enable Plugins on .uproject file.

    {
    "Plugins": [
    {
    "Name": "AccelByteUe4Sdk",
    "Enabled": true
    },
    {
    "Name": "OnlineSubsystemAccelByte",
    "Enabled": true
    },
    {
    "Name": "OnlineSubsystemGooglePlay",
    "Enabled": true
    },
    {
    "Name": "OnlineSubsystemGoogle",
    "Enabled": true
    }
    ]
    }
  2. Inside DefaultEngine.ini, set and add the credentials from the Google Cloud platform.

    [OnlineSubsystem]
    DefaultPlatformService=GooglePlay
    NativePlatformService=Google

    [OnlineSubsystemGoogle]
    bEnabled=True
    ClientId=123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com
    ServerClientId=123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com
    ClientSecret=abcdefghijklmnopqrstuvwxyz123456789

    [OnlineSubsystemGoogle.OnlineIdentityGoogle]
    +ScopeFields="email"
    +ScopeFields="profile"
    +ScopeFields="https://www.googleapis.com/auth/userinfo.email"
    +ScopeFields="https://www.googleapis.com/auth/userinfo.profile"

    [OnlineSubsystemGooglePlay]
    bEnabled=True

    [OnlineSubsystemGooglePlay.Store]
    bSupportsInAppPurchasing=True
    bUseStoreV2=False

    [/Script/AccelByteUe4Sdk.AccelByteSettings]
    ClientId=abcdefg12345
    ClientSecret=abcdefg12345
    Namespace=test
    PublisherNamespace=accelbyte
    BaseUrl="https://prod.gamingservices.accelbyte.io"
    QosPingTimeout=0.6
  3. Add the following code to your <PROJECT>.Build.cs file.

      if (Target.Platform == UnrealTargetPlatform.Android)
    {
    PrivateDependencyModuleNames.AddRange(new string[]
    {
    "OnlineSubsystemGoogle",
    "OnlineSubsystemGooglePlay",
    });
    }
  4. In Platforms - Android, match the package name defined in this project setting and on the Google console.

  5. In Platforms - Android Distribution Setting, configure the distribution signing. For more information, refer to Signing Projects for Release.

  6. In Platforms - Android - Google Play Service, obtain the Games App ID and Google Play License Key from the Google Play Console.

    • Games App ID is located at Play Games Services > Configuration
    • Google Play License Key is located at Monetize > Monetization Setup > Licensing
  7. In Platforms - Android SDK, configure the fields based on your engine version. For more information, see Unreal Engine Version History.

Google Play Native Login and AGS Access implementation

  1. Initialize the necessary subsystems and interfaces.

    const IOnlineSubsystem* OnlineSubsystemNativePtr = IOnlineSubsystem::GetByPlatform();
    const IOnlineIdentityPtr OnlineIdentityNativePtr = OnlineSubsystemNativePtr->GetIdentityInterface();
    const IOnlineExternalUIPtr NativeExternalUI = OnlineSubsystemNativePtr->GetExternalUIInterface();
  2. Implement the login UI for login with Google Play.

    FDelegateHandle NativeOnLoginCompleteDelegateHandle;
    const FOnLoginCompleteDelegate NativeLoginComplete = FOnLoginCompleteDelegate::CreateLambda(
    [&](int32 LoggedInLocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, FString Error)
    {
    // Put your next implementation here.

    OnlineIdentityNativePtr->ClearOnLoginCompleteDelegate_Handle(0, NativeOnLoginCompleteDelegateHandle);
    });
    NativeOnLoginCompleteDelegateHandle = OnlineIdentityNativePtr->AddOnLoginCompleteDelegate_Handle(0, NativeLoginComplete);

    NativeExternalUI->ShowLoginUI(0
    , true
    , false
    , FOnLoginUIClosedDelegate::CreateLambda([this, &OnlineIdentityNativePtr, &NativeOnLoginCompleteDelegateHandle, &Result, &bNativeLoginSuccess](FUniqueNetIdPtr UniqueId, const int ControllerIndex, const FOnlineError& Error)
    {
    // Put your next implementation here.
    }));
  3. Get the Auth ID Token once the user has finished the Google Play login.

    FString GooglePlayToken = TEXT("");
    if (!NativeUserAccountPtr->GetAuthAttribute(AUTH_ATTR_ID_TOKEN, GooglePlayToken))
    {
    // Do something when Google Play failed to retrieve the Auth Id Token
    }
  4. To complete the implementation, log in to AGS with the token that we obtained earlier.

    const IOnlineIdentityPtr OnlineIdentityABPtr = OnlineSubsystemABPtr->GetIdentityInterface();

    FDelegateHandle ABOnLoginCompleteDelegateHandle;
    {
    const FOnLoginCompleteDelegate ABLoginComplete = FOnLoginCompleteDelegate::CreateLambda(
    [&](int32 LoggedInLocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, FString Error)
    {
    // Put your next implementation here.
    OnlineIdentityABPtr->ClearOnLoginCompleteDelegate_Handle(0, ABOnLoginCompleteDelegateHandle);
    });
    ABOnLoginCompleteDelegateHandle = OnlineIdentityABPtr->AddOnLoginCompleteDelegate_Handle(0, ABLoginComplete);
    }

    FOnlineAccelByteAccountCredentials OnlineAccountCredentialsNative(
    EAccelByteLoginType::GooglePlayGames,
    "",
    GooglePlayToken,
    true);

    OnlineIdentityABPtr->Login(0, OnlineAccountCredentialsNative);