目录

CredentialClient

Interface Info

public interface CredentialClient

Client for credential management.

Public Method Summary

Qualifier and Type

Method Name and Description

public void

deleteCredential(Credential credential, CredentialCallback<Void> callback)

Deletes a credential.

public void

findCredential(List<AppIdentity> trustedApps, CredentialCallback<List<Credential>> callback)

CAUTION:

Deprecated. You are advised to use findCredential(SharedCredentialFilter filter, CredentialCallback<List<Credential>> callback).

Checks for available credentials, including those saved by this app and those shared to this app by other apps.

public void

saveCredential(Credential credential, CredentialCallback<Void> callback)

Saves a credential. If the credential already exists, this method will update the credential content.

public void

findCredential(SharedCredentialFilter filter, CredentialCallback<List<Credential>> callback)

Searches for available credentials, including those saved by this app and those shared to this app by other apps.

Public Methods

[h2]deleteCredential

Method

deleteCredential(Credential credential, CredentialCallback<Void> callback)

Deletes a credential.

Parameters

Name

Description

credential

Credential to be deleted. Pass the Credential object returned by the findCredential method.

  • If the credential caller is the same as its owner, the credential will be deleted completely.
  • If the credential caller is different from its owner, only the sharing relationship of the credential is deleted. After deletion, the caller will be unable to use the credential anymore. However, the credential owner and other authorized apps can still use this credential.

callback

Callback object.

[h2]findCredential

Method

public void findCredential(List<AppIdentity> trustedApps, CredentialCallback<List<Credential>> callback)

CAUTION:

Deprecated. You are advised to use findCredential(SharedCredentialFilter filter, CredentialCallback<List<Credential>> callback).

Checks for available credentials, including those saved by this app and those shared to this app by other apps.

Parameters

Name

Description

trustedApps

List of trusted apps. Only credentials shared by apps in the list will be returned for use, ensuring that only trusted credentials are used.

If the parameter value is null, credentials shared by all apps to this app will be returned. You can determine whether to trust and use a credential based on the attribute of its owner.

However, you are advised not to set this parameter to null or pass an empty list because potential security risks may exist.

callback

Callback object. You can obtain a list of credentials using the onSuccess method.

[h2]saveCredential

Method

public void saveCredential(Credential credential, CredentialCallback<Void> callback)

Saves a credential to Keyring.

An app can use this method to save a new credential or update an existing credential.

  1. Save a new credential.

    An app creates a Credential object, sets the object attributes, and calls the saveCredential method.

    For each app, the combination of the user name and type is unique for a Credential. If a credential with the same user name and type already exists, this method will update the credential.

    Each app can save a maximum of 10 credentials of each type. If the number of credentials of a specified type reaches the maximum, you can call the deleteCredential method to delete a credential that is not frequently used, and then try to save a new credential again.

  2. Update an existing credential.

    The app modifies the attributes of the Credential object returned by findCredential and calls the saveCredential method. If the owner attribute of the Credential object is different from that of this app, only the displayName, avatarUrl, tag, and newContent attributes can be modified.

Parameters

Name

Description

credential

Credential to be saved.

callback

Callback object.

[h2]findCredential

Method

findCredential(SharedCredentialFilter filter, CredentialCallback<List<Credential>> callback)

Searches for available credentials, including those saved by this app and those shared to this app by other apps.

Parameters

Name

Description

filter

Filter for shared credentials. For details, please refer to SharedCredentialFilter.

callback

Callback object. You can obtain a list of credentials using the onSuccess method.