Google is committed to advancing racial equity for Black communities. See how.

CredentialSavingClient

public interface CredentialSavingClient implements HasApiKey<CredentialSavingOptions>

A client for the Credential Saving API.

Public Method Summary

abstract Task<SaveAccountLinkingTokenResult>
saveAccountLinkingToken(SaveAccountLinkingTokenRequest saveAccountLinkingTokenRequest)
Attempts to save a token for account linking.
abstract Task<SavePasswordResult>
savePassword(SavePasswordRequest savePasswordRequest)
Initiates the storage of a password-backed credential that can later be used to sign a user in.

Public Methods

public abstract Task<SaveAccountLinkingTokenResult> saveAccountLinkingToken (SaveAccountLinkingTokenRequest saveAccountLinkingTokenRequest)

Attempts to save a token for account linking.

Calling this method will provide a PendingIntent in the response that can be used to launch the flow to complete the saving of the account linking token. As part of the request, you need to provide a PendingIntent for your consent page that the Google Play Services will launch in the middle of the flow. The result will then needs to be sent back to the caller following a certain contract described in SaveAccountLinkingTokenRequest.Builder.setConsentPendingIntent(PendingIntent).

A typical usage looks like the following:

SaveAccountLinkingTokenRequest request =
     SaveAccountLinkingTokenRequest.builder()
         .setTokenType(SaveAccountLinkingTokenRequest.TOKEN_TYPE_AUTH_CODE)
         .setConsentPendingIntent(thirdPartyConsentPendingIntent)
         .setServiceId("service-id-defined-by-3p")
         .setScopes(scopes) //scopes are defined by 3P
         .build();
 Identity.getCredentialSavingClient(this)
     .saveAccountLinkingToken(request)
     .addOnSuccessListener(
         saveAccountLinkingTokenResult -> {
             if (saveAccountLinkingTokenResult.hasResolution()) {
                 // Launch the resolution intent
                 PendingIntent pendingIntent = saveAccountLinkingTokenResult.getPendingIntent();
                 try {
                     startIntentSenderForResult(
                         pendingIntent.getIntentSender(),
                         REQUEST_CODE_SAVE_TOKEN, null, 0, 0, 0, null);

                } catch(SendIntentException ex){
                     throw new AssertionError("Unhandled exception", ex);
                }
             } else {
                 // This should not happen, let’s log this
                 Log.e(TAG,"Failed to save token");
             }
         })
     .addOnFailureListener(e -> Log.e(TAG,"Failed to save token", e));
 
When flow finishes, the success or failure of the process is returned back to the caller activity and can be captured like the following:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (requestCode != REQUEST_CODE_SAVE_TOKEN) {
       // Handle requests that may have originated from elsewhere.
       return;
     }
     if (resultCode == Activity.RESULT_OK) {
       // Token was successfully saved.
     } else {
       // Token was not saved successfully, or user canceled the flow.
     }
 }
 
Parameters
saveAccountLinkingTokenRequest the request that contains the parameters to successfully return a response that can be used to launch the appropriate flow.
Returns

public abstract Task<SavePasswordResult> savePassword (SavePasswordRequest savePasswordRequest)

Initiates the storage of a password-backed credential that can later be used to sign a user in.

If the request cannot be honored, an exception will be set on the returned Task. In all other cases, a SavePasswordResult will be returned.

A typical usage entails the following:

  1. Get a new API client instance by calling Identity.getCredentialSavingClient.
  2. Call CredentialSavingClient.savePassword, supplying the constructed SavePasswordRequest as an input.
  3. If the request is successful, launch the PendingIntent from the result of the operation to display the UI that guides the user through the flow of saving password. The success or failure result will be returned in Activity.onActivityResult.
Parameters
savePasswordRequest container for the SignInPassword for the password-saving flow
Returns
  • Task which eventually contains the result of the initialization