👨🏼💻Integrating Huawei AppGallery Connect to Unity: A Quiz Game -Part 1 Auth Service
Introduction
Hello Unity Developers. In this article we will create a Unity Quiz Game with Huawei AppGallery Connect Services.
Auth Service -> provides an SDK and backend services, supports multiple authentication modes, and provides a powerful management console, enabling you to easily develop and manage user authentication.
Before starting implementation you will need an Huawei developer account. You can register or sign in from here
Creating Your Project and App
- A project is a container of your apps in AppGallery Connect. You can add different platform versions of an app to the same project. If you do not have any projects yet, create one to get started.
- If you have not added any apps to your project, add one first. The app can either be a new one or an existing one that has not been added to any project yet. For details, please refer to Adding an App to the Project.
Setting a Data Processing Location
Before using Auth services, you will need to set a data processing location.
Enable Auth Service
After creating your project and app now we need to enable Auth Service.
- From My Projects select your project card and app that you created
2. On the left sidebar select Build->Auth Service then click Enable now in the upper right corner.
3. We will use Email and Anonymous authentication modes. Enable also the modes.
We will now integrate Huawei AppGallery Connect Services to demo app. Before we start, I would like to inform that I won’t go into details about the UI code and some business logic. All source code will be available in github repository.
Firstly we need configuration file agconnect-services.json. Download from Project settings > General information and place it into project under Asset/Resources folder
After that download sdk from here. Place under Resources/AGC folder
Also add this linker xml file same place
If you are using newtonsoft.json in your project remove Newtonsoft.Json.dll from AGC folder.
Now create object that will manage our authentication and write below code in Start method.
AGC object is managing our auth mechanism. Now for Login with email we need firstly register user. Registering user is working in 2 steps
- Request verify code for user’s email adress
- Send user information to Huawei Auth Service Server
First step can be done below code
And for second step you can write below code.
Now that we register our user. Next step is creating the login mechanism. Firstly we need create Credential. Then we will send that credential to Auth Service server.
We already created user and sign in with email. You can monitor your authenticated users in AGC console under Auth Service section.
We have done with Email authentication mode. Let’s continue with Anonymous sign in method. For this authentication mode we do not need register user. User will sign directly. Below code can help us.
Conclusion
We have implemented the authentication features from the Huawei AppGallery Console for Unity into our app with ease since most of the hard work is handled by the SDK itself. Now, our app can provide login and sign in mechanism to users.
Congrats if you followed this tutorial till the end and made your app more convenient for you and your users.
AND WAIT FOR SECOND PART THAT WE WILL IMPLEMENT MORE FEATURES FROM HUAWEI APPGALLERY CONSOLE
References and Further Reading
Special thanks to Ali Türkay Avci and My Teammates at HTRDC