👨🏼‍💻Integrating Huawei AppGallery Connect to Unity: A Quiz Game -Part 1 Auth Service

Necati Semih Özer
Huawei Developers
Published in
4 min readSep 23, 2022

--

AppGallery Connect
Huawei AppGallery Connect

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

  1. 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.
  2. 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.

  1. From My Projects select your project card and app that you created
AppGallery Console Project List

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.

Authentication Mode List

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

Unity Resources Folder View

After that download sdk from here. Place under Resources/AGC folder

Also add this linker xml file same place

Linker file

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.

Auth Manager
Login Scene

AGC object is managing our auth mechanism. Now for Login with email we need firstly register user. Registering user is working in 2 steps

  1. Request verify code for user’s email adress
  2. Send user information to Huawei Auth Service Server

First step can be done below code

Request Verify Code

And for second step you can write below code.

Register user

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.

Sign in with email

We already created user and sign in with email. You can monitor your authenticated users in AGC console under Auth Service section.

AppGallery Connect Console Auth Service User 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.

Sign in with Anonymously

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.

Well Done

AND WAIT FOR SECOND PART THAT WE WILL IMPLEMENT MORE FEATURES FROM HUAWEI APPGALLERY CONSOLE

Stay Tuned

References and Further Reading

Special thanks to Ali Türkay Avci and My Teammates at HTRDC

--

--

Necati Semih Özer
Huawei Developers

A Computer Engineer which love to build applications and touch people lifes.