A client for the Credential Saving API.
Public Method Summary
abstract Status | |
abstract Task<SaveAccountLinkingTokenResult> |
saveAccountLinkingToken(SaveAccountLinkingTokenRequest
saveAccountLinkingTokenRequest)
Attempts to save a token for account linking.
|
abstract Task<SavePasswordResult> |
savePassword(SavePasswordRequest
savePasswordRequest)
This method is deprecated. Use Credential
Manager instead.
|
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 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));
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
Task
which may contain thePendingIntent
required to launch the flow. To find out if the response can be used to start the flow, first callSaveAccountLinkingTokenResult.hasResolution()
.
public abstract Task<SavePasswordResult> savePassword (SavePasswordRequest savePasswordRequest)
This method is deprecated.
Use Credential
Manager instead.
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:
- Get a new API client instance by calling
Identity.getCredentialSavingClient
. - Call
CredentialSavingClient.savePassword
, supplying the constructedSavePasswordRequest
as an input. - If the request is successful, launch the
PendingIntent
from theresult
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 inActivity.onActivityResult
.
Parameters
savePasswordRequest | container for the SignInPassword
for the password-saving flow |
---|
Returns
Task
which eventually contains the result of the initialization