A client for the Credential Saving API.
| abstract Status | |
| 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.
|
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 Google Play services will launch in the middle of the flow.
The result must then 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 the 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.
}
}
| saveAccountLinkingTokenRequest | the request that contains the parameters to successfully return a response that can be used to launch the appropriate flow. |
|---|
Task which may
contain the PendingIntent
required to launch the flow. To find out if the response can be used to start the
flow, first call
SaveAccountLinkingTokenResult.hasResolution().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:
Identity.getCredentialSavingClient.
CredentialSavingClient.savePassword, supplying the constructed
SavePasswordRequest as an input.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.| savePasswordRequest | container for the SignInPassword
for the password-saving flow |
|---|
Task which
eventually contains the result of the initialization