Documentation

​
​

Development

User Acquisition

Monetization

Industry

Authentication

Unity SDK

Admin API

Client API

Open Unity Dashboard

Authentication

LiveOps
​
​
Authentication
  • Overview
  • Get started
  • Concepts
  • Tutorials
    • Anonymous sign-in
    • Google Play Games
    • Apple Game Center
    • Steam
    • Facebook
    • Unity Player Accounts
    • Oculus
    • Username and Password
    • Code-Link
    • Google
    • Apple
    • Custom OpenID Connect
    • Custom ID
  • Reference
  • Privacy and consent
  1. Unity Authentication

Google

Provide a Google sign-in option to enable players to authenticate using their Google accounts in your game.
Read time 5 minutes
Last updated 2 months ago

This article guides you through the following scenarios in setting up authentication for players in your game with a Google account:
  • Set up a Google sign-in.
  • Sign in a returning user or create new user.
  • Updating a user from an anonymous sign-in to a platform sign-in via a Google account.
Note
Signing in a player with Google is a two-step process: first, retrieve a Google ID token using a non-Unity SDK or tool; then pass that token to the Unity Authentication SDK to sign in or link the player. The deprecation notice below applies only to the documented approach for the first step. The
SignInWithGoogleAsync
,
LinkWithGoogleAsync
, and
UnlinkGoogleAsync
APIs remain fully supported.
Warning
Attention: The following concerns products or services (each a “Third Party Product”) that are not developed, owned, or operated by Unity. This information might not be up-to-date or complete, and is provided to you for your information and convenience only. Your access and use of any Third Party Product is governed solely by the terms and conditions of such Third Party Product. Unity makes no express or implied representations or warranties regarding such Third Party Products, and will not be responsible or liable, directly or indirectly, for any actual or alleged damage or loss arising from your use thereof (including damage or loss arising from any content, advertising, products or other materials on or available from the provider of any Third Party Products).
Important
Deprecated: The approach below for retrieving a Google ID token relies on the Google Sign-In API and Play Games Services v1 SDK. Google has deprecated these for new titles as of February 2025. See the notice in Google's documentation for more details. Unity is evaluating how best to support this token-retrieval approach. In the meantime, we recommend using Google Play Games for a frictionless Android login experience, or Unity Player Accounts which supports a web-based Sign in with Google flow on all platforms.
To provide a Google sign-in option for the players in your game, create your app in the Google Play Console and install Google Play Games plugin for Unity v10.14 to sign in the player and get the access token. This requires an Open Authentication (ID) access token to identify the player to other services such as Firebase or Google.
{ ((PlayGamesLocalUser)Social.localUser).GetIdToken()}
For plugin versions running v10.14 and later, refer to Google Play Games.
Note
The code example below assumes you already have the player's Google ID Token.

Set up a Google sign-in

Note
Google sign-in is supported by Google Play Games plugin for Unity v10.14 and below which uses Play Games Services v1 SDK.
  1. Download and import the Google Play Games plugin for Unity v10.14.
  2. Set up your app to enable Google sign-in. Follow Google’s documentation on how to configure your game for Google sign-in.
  3. Configure your ID provider to be Google for Unity Authentication:
    1. In the Unity Editor menu, go to Edit > Project Settings…, then select Services > Authentication from the navigation menu.
    2. Set ID Providers to Google, then select Add.
    3. Enter the Web App client ID in the Client ID text field, then select Save.
Note
You must set a Web App client ID in the plugin setup dialog to use the Authentication SDK.
void InitializePlayGamesLogin(){ var config = new PlayGamesClientConfiguration.Builder() // Requests an ID token be generated. // This OAuth token can be used to // identify the player to other services such as Firebase. .RequestIdToken() .Build(); PlayGamesPlatform.InitializeInstance(config); PlayGamesPlatform.DebugLogEnabled = true; PlayGamesPlatform.Activate();}void LoginGoogle(){ Social.localUser.Authenticate(OnGoogleLogin);}void OnGoogleLogin(bool success){ if (success) { // Call Unity Authentication SDK to sign in or link with Google. Debug.Log("Login with Google done. IdToken: " + ((PlayGamesLocalUser)Social.localUser).GetIdToken()); } else { Debug.Log("Unsuccessful login"); }}

Sign in a returning player or create new player

Use the
SignInWithGoogleAsync
method to either:
  • Create a new Unity Authentication player with the Google credentials.
  • Sign in an existing player using the Google credentials.
async Task SignInWithGoogleAsync(string idToken){ try { await AuthenticationService.Instance.SignInWithGoogleAsync(idToken); Debug.Log("SignIn is successful."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}

Update a player from anonymous to a Google account

After you’ve set up anonymous authentication, if the player wants to upgrade from being anonymous to creating a Google account and sign in, your game should prompt the player to trigger the Google sign-in and get the ID token from Google. Then, call the
LinkWithGoogleAsync
API to link the player to the Google ID token.
If a cached player exists on the SDK, you can link the cached player to the Google Account.
  1. Sign into the cached player's account using
    SignInAnonymouslyAsync
    .
  2. Link the cached player's account to the Google account with
    LinkWithGoogleAsync
    .
For more information about cached players, refer to Sign In a Cached Player.
async Task LinkWithGoogleAsync(string idToken){ try { await AuthenticationService.Instance.LinkWithGoogleAsync(idToken); Debug.Log("Link is successful."); } catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked) { // Prompt the player with an error message. Debug.LogError("This user is already linked with another account. Log in instead."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}

Unlink Google account

Use the
UnlinkGoogleAsync
API so your players can unlink their Google account. Once unlinked, if their account isn’t linked to any additional identity, it transitions to an anonymous account.
async Task UnlinkGoogleAsync(){ try { await AuthenticationService.Instance.UnlinkGoogleAsync(); Debug.Log("Unlink is successful."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Set up a Google sign-in

    • Sign in a returning player or create new player

    • Update a player from anonymous to a Google account

    • Unlink Google account


Report a problem with this page