Setting up PlayFab authentication using Google Play games sign-in in Unity

Tutorial video


The audio portion of the following video is currently unavailable. A new recording is pending, and will be available in the immediate future.

HowTo: Use Google SignIn (GPG) + PlayFab (Unity)

This tutorial illustrates the steps to successfully add Google Play Games sign-in to your PlayFab games, built with the Unity SDK.

However, finding all the required information can be tricky. So we'll try to centralize all the steps you need to get this feature working.

You can also download the sample for this tutorial here.


Getting started

First, we'll start by setting up some basic things in Google Play. There are a few good guides on how to do this, so we aren't going to reinvent the wheel.

  1. Create an Application - If you haven't done so already, you'll need to create an application in the Google Play Developer Console.
  2. Build your game APK, and upload it as an Alpha Build.
    • Select Manage Releases.
    • Select Manage Alpha.
    • Select Upload APK.
  3. Set up Google Play Games services following the instructions on this page: Setting Up Google Play Games Services.
  4. Download the Google Play Games SDK (if you haven't done so already) and install it.
  5. Install the PlayFab Unity SDK (if you do not know how to do this, follow the Unity3D quickstart guide).

Configuring Google Play Games

You can configure Google Play Games from the toolset that is installed with the Google Play Games SDK. You can get to these tools by:

  • Going to the Window tab.
  • Selecting Google Play Games.
  • Going to Setup.
  • Then accessing Android Setup.

Google Play Games toolset Android setup

  • Copy your Application ID from the Linked apps section of Game Services in the Google Play Developer Console, as shown in the example provided below.

Google Play Developer Console Linked apps

  • Then, populate your app_id and package_name in the resource definition, as shown below.
<?xml version="1.0" encoding="utf-8"?>
<string name="app_id">[your app_id]</string>
<string name="package_name">[package name]</string>


The Client ID that is generated for you when you link the App (shown in this image) is NOT the correct one!

Google Play Developer Console Web App Client ID

In order to get the Google Sign-In working with PlayFab, you need to use a Web Client ID. To obtain your Web Client ID, you must link a Web Application in the Game Services section of the Google Play Console under the Services and API section.

Google Play Developer Console game services

Then configure your app for the web.

Google Play Developer Console link to Web app configuration

From here, you enter your API Endpoint which can be found in PlayFab:

  • Look under Settings.
  • Select the API tab.
  • Go to the API endpoint field.

Google Play Developer Console enter API endpoint

  • Enter this endpoint https://<titleid> in the Launch URL field.
  • Select the Save button.
  • This will provide you with the proper Client ID.

To obtain your secret key, follow the link to your API Console.

Link to API Console

  • Select your Web Application (Type).
  • The Client Secret is at the top.


You must change the default callback for Authorized redirect URIs. The proper URI is If you do not do this step you will get a mismatch redirect_uri error.

PlayFab Google Sign-In setup

PlayFab has its own process for setting up a Google sign-in. You can do this in your PlayFab developer account. If you don't have one, you can sign up for a free developer account.

To set up Google in PlayFab:

  • Navigate to the Add-ons section in your dashboard.
  • Go to the Google Add-On.
  • From there, select the Install Add-on button.

There are a few things you need to enter into this form:

  • The Google App Package ID - This is the name of your Android package. For example, our sample uses com.playfab.gpgexample.
  • The Google App License Key - While this is a required field, it isn't related to the Google Sign-In. This field is for setting up a Receipt Validation using our Receipt Validation APIs.


You can get this License Key from the Google Developer Console under the Services & APIs section. Look for a section entitled YOUR LICENSE KEY FOR THIS APPLICATION. Copy and paste the Base64-encoded RSA Public Key into this field.

  • The Google OAuth Client ID - This is the Web Client ID that you used in the Google Play Games SDK setup in Unity.
  • The Google OAuth Client Secret - This is the secret key that you obtained in the last step.


Be sure to Save Settings!

Adding Google sign-in to your Unity Game

The code to get Google sign-in working is fairly minimal. There's the initialization code, which you'll put in your Start (or anywhere you're initializing or starting up your app).

This can be in different places, depending on the architecture and framework of your game or app. In any case, the code below will initialize Google Play Games.


Make sure that you don't forget the using statements, so that you can use the Google Play Games SDK.

// These using statements are required.
using GooglePlayGames;
using GooglePlayGames.BasicApi;
// The following grants profile access to the Google Play Games SDK.
// Note: If you also want to capture the player's Google email, be sure to add
// .RequestEmail() to the PlayGamesClientConfiguration
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()

// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;

// Activate the Google Play Games platform

The next set of code, the OnSignInButtonClicked() function shown in the example provided below, is bound to a Sign In button in the UI in our example.

Google Sign-In button screen

    private void OnSignInButtonClicked()
        Social.localUser.Authenticate((bool success) => {

            if (success)

                GoogleStatusText.text = "Google Signed In";
                var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
                Debug.Log("Server Auth Code: " + serverAuthCode);

                PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
                    TitleId = PlayFabSettings.TitleId,
                    ServerAuthCode = serverAuthCode,
                    CreateAccount = true
                }, (result) =>
                    GoogleStatusText.text = "Signed In as " + result.PlayFabId;

                }, OnPlayFabError);
                GoogleStatusText.text = "Google Failed to Authorize your login";



The OnSignInButtonClicked() code can be a bit overwhelming, so let's break down exactly what is happening:

  • First, we log in with Social.localUser.Authenticate - This will return a boolean if we're able to successfully login. Be aware that if you haven't added your test account to your app, this will always return False when testing.
  • When this happens - important step here - add your test account.
  • The link will take you to instructions on adding testers to your Google application.


This is what will trigger the Google Play Games sign-in dialog to pop-up.

  • Next, if we have a successful login, we make a call to PlayGamesPlatform.Instance.GetServerAuthCode, and store it in a variable.
  • Lastly, we make the LoginWithGoogleAccount call, and pass the AuthCode we just got from Google in as the ServerAuthCode parameter.

There is a callback which will have the results of your login to PlayFab. At this point, you should see a successful login in your dashboard!

Google Play Games Sign-In Auth Example

Hopefully, this guide has helped you. But if you have questions, feel free to ask them in our community forums.

You can download the sample for this tutorial here.