Manage Your Credentials with Huawei Keyring

Sinan Yılmaz
Huawei Developers
Published in
3 min readJan 7, 2022

Hi folks,

In this blog, I want to talk about a new tool that comes with Huawei Mobile Services 6.0.

Keyring provides the Credentials Management API for storing user credentials locally on Android devices and sharing them between different apps and different platform versions of an app.

Supports Android, Web, and Quick Apps. We can sign in for 3 different uses: Automatic, Cross-App, Cross-Platform.

Automatic Sign In: Stores user credentials on the user’s device. In this way, when you want to sign in, you can sign in automatically.

Cross-App Sign In: Enables the user to sign in to an app by using the credentials from another already signed-in app.

Cross-Platform Sign In: Easily shares user’s credentials between your Android, Quick, and Web apps.

For these 3 use-cases, it may be useful to use Keyring. Now, let’s integrate Keyring into the Android application as an example. We can do this simply.

After making the necessary AGC implementations, we can add the SDK of the Keyring to the Gradle file. This SDK provides us with a class called CredentialManager. As the name suggests, we can manage our existing credentials with CredentialManager. First, we need to create a CredentialClient object from this class.

After that, we need to define the Android apps or Websites we want to include. I’m creating a list for it.

We need to create a list of types AppIdentity. Then, according to the Android or Web application, we need to enter the necessary information as in the example. If we want to save a credential, we must first create a Credential object. Here we can specify the user’s information. Then we can use the saveCredential() function from the credentialClient.

Now let’s sign in with the credential object that we created before. We have to check if there is a suitable credential with findCredential() which it provides us.

This function takes the list we created as a parameter and gives us a callback where we can check the status of the credentials. If we want to delete the credentials we have saved, it will be enough to call the deleteCredential() function and convey that we want to delete the credentials we have reached above(within findCredential()).

Conclusion

We found answers to questions such as: What is Huawei Keyring in this article? What scenarios is it used for? How to manage credentials on Android with Keyring? As seen in the code examples, we can integrate the keyring into our projects quickly and easily with a few methods.

References

Thank you for reading this article! I hope it was useful for you. Don’t forget the clap if you like this blog :)

--

--