Importance of Huawei Account Kit for Unity and integration

Melikeeroglu
Huawei Developers
Published in
5 min readSep 28, 2020

In this article we will talk about the importance of Huawei Account kit for Unity apps. Firstly we will look at the methods of Huawei Account Kit then we will integrate it with our Unity app. We will focus details of Huawei Account Kit in this article.

1-What is Huawei Account Kit?

Huawei Account Kit is a mobile service with the ability to log in and authorize just about HUAWEI ID, simply, securely and quickly without requiring email and password.

2- What are the features of Huawei Account Kit?

  • Quick and standard

Connects your app to the Huawei ecosystem, allowing users to sign in to your app using their HUAWEI IDs from a range of devices, such as mobile phones, tablets, and smart screens.

  • Massive user base and global services

Serves more than 190 locations worldwide, and supports more than 70 languages, with up to 900 million users. Users can quickly sign in to your apps through their HUAWEI IDs.

  • Secure, reliable, and compliant with international standards

Complies with international standards and protocols such as OAuth 2.0 and Open ID Connect, and supports two-factor (password+mobile number) authentication to ensure high security.

3- What is HuaweiIdAuthService?

A client for interacting with the Huawei Sign In API.

Let’s take a look at HuaweiIdAuthService methods.

  • public Intent getSignInIntent(): This API is called to obtain the Intent of the HUAWEI ID sign-in and authorization page and use the startActivityForResult(Intent, int) method to display the related page.

Return

Intent: The Intent object is returned, which can be used to display the HUAWEI ID sign-in and authorization page through the startActivityForResult(Intent, int) method.

  • public Task<AuthHuaweiId> silentSignIn(): This API is called to return the information (or error information) about the HUAWEI ID used by a user who has signed in to an app. During this process, no user page will be displayed to the HUAWEI ID user.

Return

Task<AuthHuaweiId>:The Task of AuthHuaweiId or ApiException is returned. You can handle asynchronous results by setting callbacks in this task.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure.

In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

  • public Task<Void> signOut(): This API is called to sign out of a HUAWEI ID from an app. After sign-out, the HMS SDK deletes the cached HUAWEI ID information.

Return

Task<Void>:The Task object is returned, which is used to check whether a request is successful, fails, or is completed.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure.

In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

  • public Task<Void> cancelAuthorization(): This API is called to cancel HUAWEI sign-in authorization.

Return

Task<Void>

The Task object is returned, which is used to check whether a request is successful, fails, or is completed.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure.

In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

4- Integrate Unity Game with Account Kit

Preperation Step

Enable the HUAWEI services.

AGC -> Project -> Project Settings -> Manage APIs

  • This plugin have two branch for Unity versions.(version 2019 used)

Download plugin from this for Unity version 2019.x.

Download plugin from this for Unity version 2018.x .

  • Import package to unity.

Then select downloaded package and click import.

  • Download agconnect.json file from AGC.

1- Open project_path\Assets\Huawei\agconnect.json replace with you downloanded from AGC.

2- Open project_path\Assets\Plugins\Android\ AndoridManifest.

Update App ID, CP ID and package name, this informations exist in updated agconnect.json file.

Integration

  • Create empty object and add account manager script from Huawei package component. ( Object name is important, if you want to give diffrent name from “AccountManager” update ~~\Assets\Huawei\Account\AccountManager.cs -> line 11)

Add new script “AccountSignIn” to this object.

In AccountSignIn.cs

We can create Login and Logout buttons

Firstly we will add new On Click() to the Login button then add AccountManager as object and add Login function of AccountSignIn script as function.

Login button call Login function of AccountSignIn script.

App example

We’ve come to the end of this article. Thank you for reading so far. I hope I’ve been able to explain the importance of the Account Kit for Unity and its integration. I’ll see you next article.

--

--