GoogleSignInClient

public class GoogleSignInClient extends GoogleApi<GoogleSignInOptions>

A client for interacting with the Google Sign In API.

Public Method Summary

Intent
getSignInIntent()
Gets an Intent to start the Google Sign In flow by calling Activity.startActivityForResult(Intent, int).
Task<Void>
revokeAccess()
Revokes access given to the current application.
Task<Void>
signOut()
Signs out the current signed-in user if any.
Task<GoogleSignInAccount>
silentSignIn()
Returns the ERROR(/GoogleSignInAccount) information for the user who is signed in to this app.

Inherited Method Summary

Public Methods

public Intent getSignInIntent ()

Gets an Intent to start the Google Sign In flow by calling Activity.startActivityForResult(Intent, int).

Returns
  • The Intent used for start the sign-in flow.

public Task<Void> revokeAccess ()

Revokes access given to the current application. Future sign-in attempts will require the user to re-consent to all requested scopes. Applications are required to provide users that are signed in with Google the ability to disconnect their Google account from the app. If the user deletes their account, you must delete the information that your app obtained from the Google APIs.

Returns
  • A Task that may be used to check for failure, success or completion

public Task<Void> signOut ()

Signs out the current signed-in user if any. It also clears the account previously selected by the user and a future sign in attempt will require the user pick an account again.

Returns
  • A Task that may be used to check for failure, success or completion

public Task<GoogleSignInAccount> silentSignIn ()

Returns the ERROR(/GoogleSignInAccount) information for the user who is signed in to this app. If no user is signed in, try to sign the user in without displaying any user interface.

A sample usage:

 Task<GoogleSignInAccount> task = googleSignInClient.silentSignIn();
 if (task.isSuccessful()) {
     // There's immediate result available.
     GoogleSignInAccount signInAccount = task.getResult();
     updateViewWithAccount(account);
 } else {
     // There's no immediate result ready, displays some progress indicator and waits for the
     // async callback.
     showProgressIndicator();
     task.addOnCompleteListener(new OnCompleteListener<GoogleSignInAccount>() {
             @Override
             public void onComplete(Task<GoogleSignInAccount> task) {
                 try {
                     hideProgressIndicator();
                     GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
                     updateViewWithAccount(account);
                 } catch (ApiException apiException) {
                     // You can get from apiException.getStatusCode() the detailed error code
                     // e.g. GoogleSignInStatusCodes.SIGN_IN_REQUIRED means user needs to take
                     // explicit action to finish sign-in;
                     // Please refer to GoogleSignInStatusCodes Javadoc for details
                     updateButtonsAndStatusFromErrorCode(apiException.getStatusCode());
                 }
             }
     });
 }
 

The GoogleSignInAccount will possibly contain an ID token which may be used to authenticate and identify sessions that you establish with your application servers. If you use the ID token expiry time to determine your session lifetime, you should retrieve a refreshed ID token, by calling silentSignIn prior to each API call to your application server.

Calling silentSignIn can also help you detect user revocation of access to your application on other platforms and you can call getSignInIntent() again to ask the user to re-authorize.

If your user has never previously signed in to your app on the current device, we can still try to sign them in, without displaying user interface, if they have signed in on a different device.

We attempt to sign users in if:

  • There is one and only one matching account on the device that has previously signed in to your application, and
  • the user previously granted all of the scopes your app is requesting for this sign in.
Returns