GamesSignInClient

  • GamesSignInClient is a client for performing sign-in with Play Games Services.

  • The isAuthenticated method returns the current authentication status.

  • The requestServerSideAccess method requests server-side access to Play Games Services and returns an authorization code.

  • The signIn method manually requests that your game sign in with Play Games Services.

public interfaceGamesSignInClient

A client for performing sign-in with Play Games Services.

Public Method Summary

abstract Task<AuthenticationResult>
isAuthenticated()
Returns the current authentication status via anAuthenticationResult.
abstract Task<AuthResponse>
requestServerSideAccess(String serverClientId, boolean forceRefreshToken,List<AuthScope> scopes)
Requests server-side access to Play Games Services for the currently signed-in player.
abstract Task<String>
requestServerSideAccess(String serverClientId, boolean forceRefreshToken)
Requests server-side access to Play Games Services for the currently signed-in player.
abstract Task<AuthenticationResult>
signIn()
Manually requests that your game sign in with Play Games Services.

Public Methods

public abstract Task<AuthenticationResult>isAuthenticated()

Returns the current authentication status via anAuthenticationResult.

If a sign-in flow is currently in progress (such as the automatic sign-in attempt during game start), delivery of this call's result will be postponed until the current sign-in attempt has completed.

This API is useful for understanding if your game has access to Play Games Services. This method should be called when your game starts in order to conditionally enable or disable your Play Games Services integration.

Example usage:

 GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(this); gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask -> {   if (!isAuthenticatedTask.isSuccessful()) {     // Disable Play Games Services integration     return;   }   AuthenticationResult authenticationResult = isAuthenticatedTask.getResult();   if (!authenticationResult.isAuthenticated()) {     // Disable Play Games Services integration     return;   }   // Enable Play Games Services integration });
Returns

public abstract Task<AuthResponse>requestServerSideAccess(String serverClientId, boolean forceRefreshToken,List<AuthScope> scopes)

Requests server-side access to Play Games Services for the currently signed-in player.

An authorization code is returned when requested. Your server can then exchange this code for an access token (and conditionally a refresh token whenforceRefreshToken istrue). The access token allows your server to access the Play Games Services web APIs, which is often used to complete sign-in by verifying the Play Games Services player ID.

WhenforceRefreshToken istrue during authorization code exchange, a refresh token is provided along with the access token. This refresh token enables your server to obtain new access tokens and continue accessing Play Games Services even when the user isn't actively playing. Note that refresh tokens are only generated for players who have auto sign-in setting enabled.

Scopes represent theAuthScope values requested such asAuthScope.EMAIL,AuthScope.PROFILE,AuthScope.OPEN_ID. For new permissions, users will see a consent screen upon the first request. Granting consent (or if permissions were already granted) results in theAuthResponse listing the effectively grantedAuthScope. Declining permission results in an empty list of grantedAuthScope in theAuthResponse . Regardless of granted permissions, a successful request will always return the authorization code.

Parameters
serverClientIdThe client ID of the server that will perform the authorization code flow exchange.
forceRefreshTokenIftrue, when the returned authorization code is exchanged, a refresh token will be included in addition to an access token.
scopesA list ofAuthScope values representing the OAuth 2.0 permissions being requested, such asAuthScope.EMAIL,AuthScope.PROFILE andAuthScope.OPEN_ID.
Returns
  • ATask that completes with anAuthResponse containing the OAuth 2.0 authorization code as a string and a list of theAuthScopes that were effectively granted by the user (see description for details on consent). This authorization code can be exchanged by your server for an access token (and conditionally a refresh token) that can be used to access the Play Games Services web APIs and other Google Identity APIs.

public abstract Task<String>requestServerSideAccess(String serverClientId, boolean forceRefreshToken)

Requests server-side access to Play Games Services for the currently signed-in player.

When requested, an authorization code is returned that can be used by your server to exchange for an access token (and conditionally a refresh token whenforceRefreshToken istrue). The access token may then be used by your server to access the Play Games Services web APIs. This is commonly used to complete a sign-in flow by verifying the Play Games Services player ID.

IfforceRefreshToken istrue, when exchanging the authorization code, a refresh token will be returned in addition to the access token. The refresh token allows your server to request additional access tokens, allowing your server to continue accesses Play Games Services while the user is not actively playing your game. Refresh tokens are only generated for players that have auto sign-in setting enabled.

Parameters
serverClientIdThe client ID of the server that will perform the authorization code flow exchange.
forceRefreshTokenIftrue, when the returned authorization code is exchanged, a refresh token will be included in addition to an access token.
Returns
  • ATask providing an OAuth 2.0 authorization code as a string. This code can be exchanged by your server for an access token (and conditionally a refresh token) that can be used to access the Play Games Services web APIs.

public abstract Task<AuthenticationResult>signIn()

Manually requests that your game sign in with Play Games Services.

Note that a sign-in attempt will be made automatically when your game starts. Games will only need to manually request to sign in if the automatic sign-in attempt failed.

Returns
  • ATask that signals the result of the sign-in attempt.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-23 UTC.