[Huawei Developers] John Wo:
More information like this, you can visit HUAWEI Developer Forum​

HUAWEI Account Kit offers very simple, quick and secure sign in and authorization functionalities which help many developers to implement hassle free and quick sign in functionalities for their applications.

HUAWEI Account Kit offers services on different parameters as

Quick and Standard

Massive user base and global services

Secure, reliable, and compliant with international standards

Quick sign-in to apps

Development Overview

Prerequisite

1. Must have a Huawei Developer Account

2. Must have a Huawei phone with HMS 4.0.0.300 or later

3. React Native environment with Android Studio, Node Js and Visual Studio code.

Major Dependencies

1. React Native CLI : 2.0.1

2. Gradle Version: 6.0.1

3. Gradle Plugin Version: 3.5.2

4. React Native Account Kit SDK : 5.0.0.300

5. React-native-hms-account kit gradle dependency

6. AGCP gradle dependency

7. Enable Auth Services

Preparation

1. Create an app or project in the Huawei app gallery connect.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828170839.39558251909697678208079014641254:50510914012657:2800:C46B07B34A5ED30BFF7DAF128A94D766AD1959D3CC701D11329834EB74A05492.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828170839.39558251909697678208079014641254:50510914012657:2800:C46B07B34A5ED30BFF7DAF128A94D766AD1959D3CC701D11329834EB74A05492.png[/IMG]

Describes the Step 1.0

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828170950.18392269281710085947705068510951:50510914012657:2800:132AA9526BF64362FD58ACB372CF1B972CD505BFF6CC60E49E5536DB264439B8.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828170950.18392269281710085947705068510951:50510914012657:2800:132AA9526BF64362FD58ACB372CF1B972CD505BFF6CC60E49E5536DB264439B8.png[/IMG]

Describes the Step 1.1

2. Provide the SHA Key and App Package name of the project in App Information Section and enable the required API.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171107.73013997565041757428112045959341:50510914012657:2800:7ADA705D53E6EC6C31C8866209BC0335808F0F880809801AF240FC2968C79FB2.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171107.73013997565041757428112045959341:50510914012657:2800:7ADA705D53E6EC6C31C8866209BC0335808F0F880809801AF240FC2968C79FB2.png[/IMG]

Describes the Step 2.0

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171309.98908430797470714661385194968791:50510914012657:2800:4F22F22D257BB330D24BFE3A9E8135EE29FDF0AF0C51497C96D56E22254B22F0.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171309.98908430797470714661385194968791:50510914012657:2800:4F22F22D257BB330D24BFE3A9E8135EE29FDF0AF0C51497C96D56E22254B22F0.png[/IMG]

Describes the Step 2.1

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171413.46240379979170156065515771630594:50510914041133:2800:5B7E768ACF5652EDC19C5F5DC5B6DAC92481265F4639679741FA093B3F6DF086.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171413.46240379979170156065515771630594:50510914041133:2800:5B7E768ACF5652EDC19C5F5DC5B6DAC92481265F4639679741FA093B3F6DF086.png[/IMG]

Describes the Step 2.2

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171459.35248121245665578395030365442943:50510914012657:2800:287AE1D3A2C8E1104DE72FD0BFBA06F97AF19E525419A9B314E449FD2C200E9A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171459.35248121245665578395030365442943:50510914012657:2800:287AE1D3A2C8E1104DE72FD0BFBA06F97AF19E525419A9B314E449FD2C200E9A.png[/IMG]

Describes the Step 2.3: Enable Account Kit Api on Manage Api page

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171737.44065458252309454683431486536873:50510914041133:2800:7B6F9F8F00BF2140EAAFCF78B48586B0D4682B38D5F353B133AC80F494658FDA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171737.44065458252309454683431486536873:50510914041133:2800:7B6F9F8F00BF2140EAAFCF78B48586B0D4682B38D5F353B133AC80F494658FDA.png[/IMG]

Describes the Step 2.4: Put SHA signature generated using Android Studio

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171822.51393617010428317004337102034241:50510914012657:2800:2D6F0FF16B30033AC60A7317E74D09382495E8176F95DA4CB00498873654B447.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828171822.51393617010428317004337102034241:50510914012657:2800:2D6F0FF16B30033AC60A7317E74D09382495E8176F95DA4CB00498873654B447.png[/IMG]

Describes the Step 2.5: Download agc services file and paste it under App folder of the project.

3. Create a react native project, use the below command

“react-native init project name”

4. Download the React Native Account Kit SDK and paste it under Node Modules directory of React Native project.

5. Enable Auth services

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172024.82192481832916257535835697640504:50510914012657:2800:ADE38CE4C6CD952059B56E1EEABA784D14BBCC28C93024556BF97A0A88C495DD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172024.82192481832916257535835697640504:50510914012657:2800:ADE38CE4C6CD952059B56E1EEABA784D14BBCC28C93024556BF97A0A88C495DD.png[/IMG]

Describes the Step 5.1: Redirect to Auth Services and enable the required authorization service.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172226.51333407449691460751427492700418:50510914012657:2800:6CD59E39493173960C85863DB1DEE49ED6754313A9200F96309F587742F90403.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172226.51333407449691460751427492700418:50510914012657:2800:6CD59E39493173960C85863DB1DEE49ED6754313A9200F96309F587742F90403.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172226.51333407449691460751427492700418:50510914012657:2800:6CD59E39493173960C85863DB1DEE49ED6754313A9200F96309F587742F90403.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172226.51333407449691460751427492700418:50510914012657:2800:6CD59E39493173960C85863DB1DEE49ED6754313A9200F96309F587742F90403.png[/IMG]

Describes the Step 5.2: copy the App ID and App Secret from “My Apps “ page and paste them here.

Tips

1. agconnect-services.json is not required for integrating the hms-ads-sdk.

2. Run below command under project directory using CLI if you cannot find node modules.

“npm install” & “npm link”

Integration

1. Configure android level build.gradle

Add to buildscript/repositories and allprojects/repositories

maven {url 'http://developer.huawei.com/repo/'}

2. Configure app level build.gradle. (Add to dependencies)

Implementation project (“: react-native-hms-ads”)

3. Linking the HMS Account Kit Sdk.

Run below command in the project directory

react-native link react-native-hms-account

Development Process

Once sdk is integrated and ready to use, add following code to your App.js file which will import the API’s present.

Import the SDK

Sign In

Sign Out

Testing

Import the SDK

Add below line of code in the app.js file

import RNHMSAccount from "react-native-hms-account";

Sign In

To sign in, create a signInData object and set the field values. Then invoke the signIn method of the HMSAccount module, setting the signInData object as the argument. If the sign in is successful, an AuthHuaweiId object will be returned, an exception object is returned otherwise.

Add below code on the “SIGN IN” button click

const onSignIn = () => {
let signInData = {
huaweiIdAuthParams:
RNHMSAccount.HmsAccount
.CONSTANT_HUAWEI_ID_AUTH_PARAMS_DEFAULT_AUTH_REQUEST_PARAM,
scopes: [RNHMSAccount.HmsAccount.SCOPE_ID_TOKEN],
};
RNHMSAccount.HmsAccount.signIn(signInData)
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};

Sign Out

To sign out, invoke the signOut method of the HMSAccount module. The promise is resolved if the sign in is successful, is rejected otherwise.

Add below code on the “SIGN OUT” button click.

const onSignOut = () => {
RNHMSAccount.HmsAccount.signOut()
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};

Testing

Run the below command to build the project

React-native run-android

Upon successful build, run the below command in the android directory of the project to create the signed apk.

gradlew assembleRelease

Results

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172821.92868595989994725184011261120684:50510914012657:2800:8ED057F784ECB105795DDD56A91E378B5F714C36A202797CE763DC5ADCCF650C.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/834/235/2640091000001834235.20200828172821.92868595989994725184011261120684:50510914012657:2800:8ED057F784ECB105795DDD56A91E378B5F714C36A202797CE763DC5ADCCF650C.gif[/IMG]

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001050725712

Conclusion

Adding SignIn and SignOut functionalities seems easy.