GoogleSignInApi

public interfaceGoogleSignInApi

This interface is deprecated.
UseCredential Managerfor authentication orGoogle Identity Servicesfor authorization.

Api interface for Sign In with Google.

Constant Summary

String EXTRA_SIGN_IN_ACCOUNT StringIntent extra key for getting the SignInAccount from theIntent data returned on Activity.onActivityResult(int, int, Intent)when sign-in succeeded.

Public Method Summary

abstractIntent
getSignInIntent(GoogleApiClient client)
Gets anIntent to start the Google Sign In flow by calling Activity.startActivityForResult(Intent, int).
abstract GoogleSignInResult
abstractPendingResult<Status>
revokeAccess(GoogleApiClient client)
Revokes access given to the current application.
abstractPendingResult<Status>
signOut(GoogleApiClient client)
Signs out the current signed-in user if any.
abstractOptionalPendingResult<GoogleSignInResult>
silentSignIn(GoogleApiClient client)
Returns theERROR(/GoogleSignInAccount) information for the user who is signed in to this app.

Constants

public static finalString EXTRA_SIGN_IN_ACCOUNT

StringIntentextra key for getting the SignInAccount from theIntentdata returned on Activity.onActivityResult(int, int, Intent)when sign-in succeeded.

Constant Value: "signInAccount"

Public Methods

public abstractIntent getSignInIntent(GoogleApiClient client)

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

Parameters
client TheGoogleApiClient to service the call.
Returns
  • theIntent used for start the sign-in flow.

public abstractGoogleSignInResult getSignInResultFromIntent(Intent data)

Helper function to extract outGoogleSignInResult from the Activity.onActivityResult(int, int, Intent)for Sign In.

Parameters
data theIntent returned on Activity.onActivityResult(int, int, Intent)when sign in completed.
Returns

public abstractPendingResult<Status> revokeAccess(GoogleApiClient client)

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.

Parameters
client The connectedGoogleApiClient to service the call.
Returns
  • the PendingResult for notification and access to the result when it's available.

public abstractPendingResult<Status> signOut(GoogleApiClient client)

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.

Parameters
client The connectedGoogleApiClient to service the call.
Returns
  • the PendingResult for notification and access to the result when it's available.

public abstractOptionalPendingResult<GoogleSignInResult> silentSignIn(GoogleApiClient client)

Returns theERROR(/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.

Client activities may call the returned OptionalPendingResult.isDone()to decide whether to show a loading indicator and set callbacks to handle an asynchronous result, or directly proceed to the next step.

A sample usage:

OptionalPendingResult<GoogleSignInResult> pendingResult =
Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (pendingResult.isDone()) {
// There's immediate result available.
updateButtonsAndStatusFromSignInResult(pendingResult.get());
} else {
// There's no immediate result ready, displays some progress indicator and waits for the
// async callback.
showProgressIndicator();
pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult result) {
updateButtonsAndStatusFromSignInResult(result);
hideProgressIndicator();
}
});
}

The GoogleSignInResult 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(GoogleApiClient)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.
Parameters
client TheGoogleApiClient to service the call.
Returns