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<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 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
- A
Task
providing anAuthenticationResult
that indicates the current authentication status.
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 when
forceRefreshToken
is true
). 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.
When forceRefreshToken
is true
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 the AuthScope
values requested such as AuthScope.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 the AuthResponse
listing the effectively granted AuthScope
.
Declining permission results in an empty list of granted AuthScope
in the AuthResponse
. Regardless of granted permissions, a successful request will always return the
authorization code.
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. |
scopes | A list of AuthScope
values representing the OAuth 2.0 permissions being requested, such as
AuthScope.EMAIL , AuthScope.PROFILE and
AuthScope.OPEN_ID . |
Returns
- A
Task
that completes with anAuthResponse
containing the OAuth 2.0 authorization code as a string and a list of theAuthScope
s 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 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.