GamesSignInClient

Stay organized with collections Save and categorize content based on your preferences.
public interface GamesSignInClient

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

Public Method Summary

abstract Task<AuthenticationResult>
isAuthenticated()
Returns the current authentication status via an AuthenticationResult.
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 an AuthenticationResult.

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<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 when forceRefreshToken is true). 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.

If forceRefreshToken is true, 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
serverClientId The client ID of the server that will perform the authorization code flow exchange.
forceRefreshToken If true, when the returned authorization code is exchanged, a refresh token will be included in addition to an access token.
Returns
  • A Task 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
  • A Task that signals the result of the sign-in attempt.