Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hmscore/cordova-plugin-hms-account

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hmscore/cordova-plugin-hms-account

Huawei Account Cordova Plugin

  • 5.0.3-302
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-80%
Maintainers
2
Weekly downloads
 
Created
Source

Cordova Plugin HMS Account

Contents


1. Introduction

The Cordova SDK code encapsulates the Huawei Account Kit interface. It provides many APIs for your reference or use.


2. Installation Guide

Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

2.1. Creating a Project in AppGallery Connect

Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:

  1. Sign in to AppGallery Connect and select My projects.
  2. Select your project from the project list or create a new one by clicking the Add Project button.
  3. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.
  4. On the Add app page, enter the app information, and click OK.

2.2. Configuring the Signing Certificate Fingerprint, Obtaining agconnect-services.json

A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the AppGallery Connect. You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.

  1. Sign in to AppGallery Connect and select your project from My Projects. Then go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.
  2. After completing the configuration, click OK to save the changes. (Check mark icon)
  3. In the same page, click agconnect-services.json button to download the configuration file.

2.3. Cordova

  1. Install Cordova CLI.

    npm install -g cordova
    
  2. Create a new Cordova project or use existing Cordova project.

    • To create new Cordova project, you can use cordova create path [id [name [config]]] [options] command. For more details please follow CLI Reference - Apache Cordova.
  3. Add the Android platform to the project if haven't done before.

    cordova platform add android
    
  4. Install HMS Account Plugin to the project. You can either install the plugin through npm or by downloading from HMS Core Plugin page.

    a. Run the following command in the root directory of your project to install it through npm.

    cordova plugin add @hmscore/cordova-plugin-hms-account
    

    b. Or download the plugin from Plugin > Account Kit > Cordova Plugin page and run the following command in the root directory of your project to install it manually.

    cordova plugin add <hms_cordova_account_plugin_path>
    
  5. Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

  6. Add keystore(.jks) and build.json files to your project's root directory.

    • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.
    • Fill build.json file according to your keystore information. For example:
    {
        "android": {
            "debug": {
                "keystore": "<keystore_file>.jks",
                "storePassword": "<keystore_password>",
                "alias": "<key_alias>",
                "password": "<key_password>"
            },
            "release": {
                "keystore": "<keystore_file>.jks",
                "storePassword": "<keystore_password>",
                "alias": "<key_alias>",
                "password": "<key_password>"
            }
        }
    }
    
  7. Update the widget id property which is specified in the config.xml file. It must be same with client > package_name value of the agconnect-services.json file.

  8. Run the application.

    cordova run android --device
    

2.4. Ionic

  1. Install Ionic CLI.

    npm install -g @ionic/cli
    
  2. Create a new Ionic project or use existing Ionic project.

2.4.1. With Cordova Runtime
  1. Enable the Cordova integration if haven't done before.

    ionic integrations enable cordova
    
  2. Update the widget id property which is specified in the config.xml file. It must be same with client > package_name value of the agconnect-services.json file.

  3. Add the Android platform to the project if haven't done before.

    ionic cordova platform add android
    
  4. Install HMS Account Plugin to the project. You can either install the plugin through npm or by downloading from HMS Core Plugin page.

    a. Run the following command in the root directory of your project to install it through npm.

    ionic cordova plugin add @hmscore/cordova-plugin-hms-account
    

    b. Or download the plugin from Plugin > Account Kit > Cordova Plugin page and run the following command in the root directory of your project to install it manually.

    ionic cordova plugin add <hms_cordova_account_plugin_path>
    
  5. Copy hms-account folder from node_modules/@hmscore/cordova-plugin-hms-account/ionic/wrapper/dist directory to node_modules/@ionic-native directory.

  6. Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

  7. Add keystore(.jks) and build.json files to your project's root directory.

    • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.

    • Fill build.json file according to your keystore information. For example:

    {
        "android": {
            "debug": {
                "keystore": "<keystore_file>.jks",
                "storePassword": "<keystore_password>",
                "alias": "<key_alias>",
                "password": "<key_password>"
            },
            "release": {
                "keystore": "<keystore_file>.jks",
                "storePassword": "<keystore_password>",
                "alias": "<key_alias>",
                "password": "<key_password>"
            }
        }
    }
    
  8. Run the application.

    ionic cordova run android --device
    
2.4.2. With Capacitor Runtime
  1. Enable the Capacitor integration if haven't done before.

    ionic integrations enable capacitor
    
  2. Update the widget appId property which is specified in the capacitor.config.json file. It must be same with client > package_name value of the agconnect-services.json file.

  3. Install HMS Account Plugin to the project. You can either install the plugin through npm or by downloading from HMS Core Plugin page.

    a. Run the following command in the root directory of your project to install it through npm.

    npm install @hmscore/cordova-plugin-hms-account
    

    b. Or download the plugin from Plugin > Account Kit > Cordova Plugin page and run the following command in the root directory of your project to install it manually.

    npm install <hms_cordova_account_plugin_path>
    
  4. Copy hms-account folder from node_modules/@hmscore/cordova-plugin-hms-account/ionic/wrapper/dist directory to node_modules/@ionic-native directory.

  5. Build Ionic app to generate resource files.

    ionic build
    
  6. Add the Android platform to the project if haven't done before.

    npx cap add android
    
  7. Copy keystore(.jks) and agconnect-services.json files to <project_root>/android/app directory.

  8. Open the build.gradle file in the <project_root>/android/app directory.

    • Add signingConfigs entry to android according to your keystore information.
    • Enable signingConfig configuration to debug and release flavors.
    • Apply com.huawei.agconnect plugin.
    ...
    
    android {
    
        ...
    
        // Add signingConfigs according to your keystore information
        signingConfigs {
            config {
                storeFile file('<keystore_file>.jks')
                storePassword '<keystore_password>'
                keyAlias '<key_alias>'
                keyPassword '<key_password>'
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.config // Enable signingConfig in debug flavor
            }
            release {
                signingConfig signingConfigs.config // Enable signingConfig in release flavor
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    ...
    
    apply plugin: 'com.huawei.agconnect' // Apply com.huawei.agconnect plugin. This line must be added to the end of the file.
    
  9. Open the build.gradle file in the <project_root>/android directory. Add Huawei's maven repositories and agconnect classpath to the file.

    buildscript {
        repositories {
            /*
                <Other repositories>
            */
            maven { url 'https://developer.huawei.com/repo/' }
        }
        dependencies {
            /*
                <Other dependencies>
            */
            classpath 'com.huawei.agconnect:agcp:1.4.1.300'
        }
    }
    
    /*
        <Other build.gradle entries>
    */
    
    allprojects {
        repositories {
            /*
                <Other repositories>
            */
            maven { url 'https://developer.huawei.com/repo/' }
        }
    }
    
  10. Open the project in Android Studio and run it.

    npx cap open android
    

3. API Reference

Module Overview

ModuleDescription
HMSCommonTypesA module for providing common data types and constants.
HMSAccountA module for interacting with the Huawei Sign In API.
HMSHuaweiIdAuthManagerA module is used to entry point for the Huawei Sign In API.
HMSHuaweiIdAuthToolA module for obtaining and clearing authorization information.
HMSNetworkToolA module is used to construct a cookie and a url with specific parameters.
HMSReadSMSManagerA module for Huawei ID SMS Service.
HMSHuaweiIdAuthButtonA module is used to processing the the visual elements of the button for sign in.

HMSAccount

Public Method Summary

Return TypeMethodsDefinition
Promise<AuthHuaweiId>signInThis API is called to sign in to the apps with HUAWEI IDs securely.
Promise<void>signOutThis API is called to sign out of a HUAWEI ID from an app.
Promise<void>cancelAuthorizationThis API is called to cancel HUAWEI sign-in authorization.
Promise<AuthHuaweiId>silentSignInThis API is called to silent authorization. The API will not display the related page.
voidenableLoggerThis API is used to activating a logger that is for sending some statistics for the development of functions.
voiddisableLoggerThis API is used to disable a logger that is for sending some statistics for the development of functions.

Public Methods

signIn

This API is called for HUAWEI sign-in.

ParameterTypeDefinition
signInDataSignInData]Signin settings.
ReturnDefinition
Promise<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.
Call Example

const signInParameters = {
        authRequestOption: [HMSCommonTypes.AuthRequestOption.SCOPE_ID_TOKEN],
        authParam: HMSCommonTypes.HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM
}


try {
    const res = await HMSAccount.signIn(signInParameters);
    alert(JSON.stringify(res));
} catch (ex) {
    alert(JSON.stringify(ex));
}
Example Result
{"accessToken":"","displayName":"account@***.com","email":"account@***.com","familyName":"","givenName":"","authorizationCode":"DQB6e3******","avatarUriString":"","expressionTimeSecs":0,"gender":-1,"describeContentsInAuthHuaweiId":0,"status":0,"authorizedScopes":["openid","profile"],"extensionScopes":[],"account":{"type":"com.huawei","name":"account@***.com"}}

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.

ReturnDefinition
Promise<void>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.
Call Example
    try {
        await HMSAccount.signOut();
        alert("signOut -> success");
    } catch (ex) {
        alert('signOut -> Error : ' + JSON.stringify(ex));
    }

cancelAuthorization

This API is called to cancel HUAWEI sign-in authorization.

ReturnDefinition
Promise<void>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.
Call Example
    try {
        await HMSAccount.cancelAuthorization();
        alert("cancelAuthorization -> success");
    } catch (ex) {
        alert('cancelAuthorization -> Error : ' + JSON.stringify(ex));
    }

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.

ParameterTypeDefinition
authParamHuaweiIdAuthParamsAuthorization scope parameter to customize the authorization.
ReturnDefinition
Promise<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.
Call Example
    try {
        const authParam = HMSCommonTypes.HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM;
        const res = await HMSAccount.silentSignIn(authParam);
        alert("silentSignIn -> success :" + JSON.stringify(res));
    } catch (ex) {
        alert('silentSignIn -> Error : ' + JSON.stringify(ex));
    }
Example Result
{"accessToken":"","displayName":"account@***.com","familyName":"","givenName":"","unionId":"MDEC*****","avatarUriString":"","expressionTimeSecs":0,"openId":"MDF***","gender":-1,"describeContentsInAuthHuaweiId":0,"status":0,"authorizedScopes":["openid","profile"],"extensionScopes":[]}

enableLogger

Enables HMS Logger.

ReturnDefinition
Promise<void>If the operation is successful, a logger is activated. Otherwise it throws an error.
Call Example
 try {
        await HMSAccount.enableLogger();
        alert("enableLogger -> success");
    } catch (ex) {
        alert('enableLogger -> Error : ' + JSON.stringify(ex));

disableLogger

Disables HMS Logger.

ReturnDefinition
Promise<void>If the operation is successful, a logger is disabled. Otherwise it throws an error.
Call Example
 try {
        await HMSAccount.disableLogger();
        alert("disableLogger -> success");
    } catch (ex) {
        alert('disableLogger -> Error : ' + JSON.stringify(ex));

HMSHuaweiIdAuthManager

Public Method Summary

Return TypeMethodsDefinition
Promise<void>addAuthScopesThis API is called to request the permission specified by scopeList from a HUAWEI ID.
Promise<ContainScopesResult>containScopesThis API is called to check whether the user with the designated HUAWEI ID has been assigned all permissions specified by scopeList.
Promise<AuthHuaweiId>getAuthResultWithScopeThis API is called to obtain the AuthHuaweiId instance.
Promise<AuthHuaweiId>getAuthResultThis API is called to obtain the latest authorization information.

Public Methods

addAuthScopes

This API is called to request the permission specified by scopeList from a HUAWEI ID.

ParameterTypeDefinition
requestCodenumberRequest Id.
scopeListAuthScopeList[]Authorization scope list.
Return TypeDefinition
Promise<void>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.
Call Example
const scopeList = [HMSCommonTypes.AuthScopeList.EMAIL, HMSCommonTypes.AuthScopeList.PROFILE];
try {
    const res = await HMSHuaweiIdAuthManager.addAuthScopes(8888, scopeList);
    alert("addAuthScopes -> success " + JSON.stringify(res));
    console.log(JSON.stringify(res));
} catch (ex) {
    alert('addAuthScopes -> Error : ' + JSON.stringify(ex));
}

containScopes

This API is called to checks whether the designated HUAWEI ID has been assigned all permissions specified by scopeList.

ParameterTypeDefinition
authHuaweiIdAuthHuaweiIdBuilderAuthorized HUAWEI ID information.
scopeListAuthScopeList[]Authorization scope list.
ReturnDefinition
Promise<ContainScopesResult>If the operation is successful, promise resolves to an object that contains boolean result, like {"containScopes": false }. Otherwise it throws an error.
Call Example
   const authHuaweiId = {
       "openId": "MDFQ***",
       "uid": "",
       "displayName": "+90***",
       "photoUrl": "",
       "accessToken": "",
       "serviceCountryCode": "",
       "status": 0,
       "gender": HMSCommonTypes.Gender.UNKNOWN,
       "serverAuthCode": "",
       "unionId": "MDHn***",
       "countryCode": "",
       "scopes": [HMSCommonTypes.AuthScopeList.EMAIL]
   };

   const scopeList = [HMSCommonTypes.AuthScopeList.EMAIL, HMSCommonTypes.AuthScopeList.PROFILE];

   try {
       const res = await HMSHuaweiIdAuthManager.containScopes(authHuaweiId, scopeList);
       alert("containScopes -> success " + JSON.stringify(res));
   } catch (ex) {
       alert('containScopes -> Error : ' + JSON.stringify(ex));
   }
Call Result
{"containScopes": false}

getAuthResultWithScope

This API is called to obtain the AuthHuaweiId.

ParameterTypeDefinition
scopeListAuthScopeList[]Authorization scope list.
ReturnDefinition
Promise<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.
Call Example
    const scopeList = [HMSCommonTypes.AuthScopeList.EMAIL, HMSCommonTypes.AuthScopeList.PROFILE];

    try {
        const res = await HMSHuaweiIdAuthManager.getAuthResultWithScope(scopeList);
        alert("getAuthResultWithScope -> success " + JSON.stringify(res));
    } catch (ex) {
        alert('getAuthResultWithScope -> Error : ' + JSON.stringify(ex));
    }
Call Result
{"accessToken":"CgB6****","displayName":"account@***.com","familyName":"","givenName":"","idToken":"eyJr***","unionId":"MDE***","avatarUriString":"","expressionTimeSecs":0,"openId":"MDF***","gender":-1,"describeContentsInAuthHuaweiId":0,"status":0,"authorizedScopes":["openid","profile"],"extensionScopes":["profile","email"]}

getAuthResult()

This API is called to obtain information about the HUAWEI ID used for the previous sign-in and authorization.

ReturnDefinition
Promise<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.
Call Example
    try {
        const res = await HMSHuaweiIdAuthManager.getAuthResult();
        alert("getAuthResult -> success " + JSON.stringify(res));
        console.log(JSON.stringify(res));
    } catch (ex) {
        alert('getAuthResult -> Error : ' + JSON.stringify(ex));
    }
Call Result
{"accessToken":"CgB***","displayName":"account@****.com","familyName":"","givenName":"","idToken":"eyJ***","unionId":"MDE***","avatarUriString":"","expressionTimeSecs":0,"openId":"MDF***","gender":-1,"describeContentsInAuthHuaweiId":0,"status":0,"authorizedScopes":["openid","profile"],"extensionScopes":[]}

HMSHuaweiIdAuthTool

Public Method Summary

Return TypeMethodsDefinition
Promise<string>requestUnionIdThis API is called to obtain a unionId.
Promise<string>requestAccessTokenThis API is called to obtain a token.
Promise<void>deleteAuthInfoThis API is called to clear the local cache.

Public Methods

requestUnionId

Obtains a unionId.

ParameterTypeDefinition
huaweiAccountNamestringHUAWEI ID Name.
ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains union id. Otherwise it throws an error.
Call Example
    try {
        const res = await HMSHuaweiIdAuthTool.requestUnionId("account@***.com");
        alert("requestUnionId -> success " + JSON.stringify(res));
        console.log(JSON.stringify(res));
    } catch (ex) {
        alert('requestUnionId -> Error : ' + JSON.stringify(ex));
    }

Call Result
"MDE***"

requestAccessToken

Obtains a token.

ParameterTypeDefinition
accountAccountHUAWEI ID for which you need to obtain a token. It contains name and type properties.
scopeListAuthScopeList[]HUAWEI ID authorization scope.
ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains a access token. Otherwise it throws an error.
Call Example
const account = {
        "type": "com.huawei.hwid",
        "name": "account@***.com"
    }

    const scopeList = [HMSCommonTypes.AuthScopeList.PROFILE];

    try {
        const res = await HMSHuaweiIdAuthTool.requestAccessToken(account, scopeList);
        alert("requestAccessToken -> success " + JSON.stringify(res));
        console.log(JSON.stringify(res));
    } catch (ex) {
        alert('requestAccessToken -> Error : ' + JSON.stringify(ex));
    }
Call Result
"CgB***"

deleteAuthInfo

Clears the local cache.

ParameterTypeDefinition
accessTokenstringToken to be clear.
ReturnDefinition
Promise<void>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.

Call Example

   try {
       const res = await HMSHuaweiIdAuthTool.deleteAuthInfo("access_token_info");
       alert("deleteAuthInfo -> success " + JSON.stringify(res));
       console.log(JSON.stringify(res));
   } catch (ex) {
       alert('deleteAuthInfo -> Error : ' + JSON.stringify(ex));
   }

HMSNetworkTool

Public Method Summary

Return TypeMethodsDefinition
Promise<string>buildNetworkCookieThis API is called to construct a cookie by combining input values.
Promise<string>buildNetworkURLThis API is called to cookie url based on the domain name and isUseHttps.

Public Methods

buildNetworkCookie

Constructs a cookie by combining input values.

ParameterTypeDefinition
cookieCookieIt is an object that contains cookieName, cookieValue, domain, path, isHttpOnly, isSecure, maxAge.
ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains a cookie. Otherwise it throws an error.
Call Example
    const param = {
        "cookieName": "hello",
        "cookieValue": "world",
        "domain": "www.demo.com",
        "path": "/demo",
        "isHttpOnly": true,
        "isSecure": true,
        "maxAge": 10
    };




    try {
        const res = await HMSNetworkTool.buildNetworkCookie(param);
        alert("buildNetworkCookie -> success " + JSON.stringify(res));
        console.log(JSON.stringify(res));
    } catch (ex) {
        alert('buildNetworkCookie -> Error : ' + JSON.stringify(ex));
    }
Call Result
"hello=world;HttpOnly;Secure;Domain=www.demo.com;Path=/demo;Max-Age=10"

buildNetworkURL

Returns cookie url based on the domain name and isUseHttps.

ParameterTypeDefinition
domainInfoDomainInfoThe parameter that contains a domain name and isUseHttps info.
ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains a cookie url. Otherwise it throws an error.
Call Example
    const params = {
        "domain": "www.demo.com",
        "isUseHttps": true
    };

    try {
        const res = await HMSNetworkTool.buildNetworkURL(params);
        alert("buildNetworkURL -> success " + JSON.stringify(res));
    } catch (ex) {
        alert('buildNetworkURL -> Error : ' + JSON.stringify(ex));
    }
Call Result
"https://www.demo.com"

HMSReadSMSManager

Public Method Summary

Return TypeMethodsDefinition
Promise<string>smsVerificationCodeThis API is called to enable the service of reading SMS messages until the SMS messages that meet the rules (Timeout five minutes).
Promise<string>obtainHashCodeThis API is called to obtain hash code.

Public Methods

smsVerificationCode

With this function, app can automatically retrieve SMS verification codes without requesting the permission of reading SMS messages. In case of get SMS Message, returned the SMS Message.

ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains a content of SMS. Otherwise it throws an error.
Call Example
    try {
        const res = await HMSReadSMSManager.smsVerificationCode();
        alert("smsVerificationCode -> success :" + JSON.stringify(res));
        console.log(JSON.stringify(res));
    } catch (ex) {
        alert('smsVerificationCode -> Error : ' + JSON.stringify(ex));
    }
Call Result
"<#> Account Kit Test Verification code is 123456 Wc1***"

obtainHashCode

Obtains hash code which indicates the hash value generated by the HMS SDK based on app package name to uniquely identify app.

ReturnDefinition
Promise<string>If the operation is successful, promise resolves to a string that contains a hash value. Otherwise it throws an error.
Call Example
    try {
        const res = await HMSReadSMSManager.obtainHashCode();
        alert("obtainHashCode -> success " + JSON.stringify(res));
    } catch (ex) {
        alert('obtainHashCode -> Error : ' + JSON.stringify(ex));
    }
Call Result
"W1c***"

HMSHuaweiIdAuthButton

Public Method Summary

Return TypeMethodsDefinition
voidgetHuaweiIdAuthButtonThis API is called to creating a specific button for login.

Public Methods

getHuaweiIdAuthButton

Authenticates user identities. Note that this class only processes the the visual elements of the button.

ParameterTypeDefinition
buttonIdstringId of div that is used for HuaweiIdAuthButton.
themeThemeButton theme
colorPolicyColorPolicyValues indicates button colors
cornerRadiusCornerRadiusValues indicates button corner types
Call Example
const edittedButton = "btn_auth_button";

    HMSHuaweiIdAuthButton.getHuaweiIdAuthButton(edittedButton,
        HMSHuaweiIdAuthButton.Theme.THEME_FULL_TITLE,
        HMSHuaweiIdAuthButton.ColorPolicy.COLOR_POLICY_RED,
        HMSHuaweiIdAuthButton.CornerRadius.CORNER_RADIUS_LARGE);

Constants

NameDefinition
HMSCommonTypes.AuthRequestOptionProvides scopes to request a Huawei ID user.
HMSCommonTypes.HuaweiIdAuthParamsProvides default HuaweiID authorization parameters.
HMSCommonTypes.AuthScopeListProvides authorization scopes.
HMSCommonTypes.GenderProvides gender information.
HMSCommonTypes.ErrorCodesProvides result codes.
HMSHuaweiIdAuthButton.ThemeProvides themes to set theme of the button.
HMSHuaweiIdAuthButton.ColorPolicyProvides colors to set color of the button.
HMSHuaweiIdAuthButton.CornerRadiusProvides corner radiueses to set corner radius size of the button.

AuthRequestOption

Constant FieldsValueDefinition
SCOPE_PROFILE"profile"Requests a HUAWEI ID user to authorize profile information to an app.
SCOPE_ID_TOKEN"idToken"Requests a HUAWEI ID user to authorize ID token to an app.
SCOPE_ACCESS_TOKEN"accessToken"Requests a HUAWEI ID user to authorize access token to an app.
SCOPE_EMAIL"email"Requests a HUAWEI ID user to authorize email address to an app.
SCOPE_ID"id"Requests a HUAWEI ID user to authorize ID to an app.
SCOPE_AUTHORIZATION_CODE"authorizationCode"Requests a HUAWEI ID user to authorize authorization code to an app.

HuaweiIdAuthParams

Constant FieldsValueDefinition
DEFAULT_AUTH_REQUEST_PARAM"DEFAULT_AUTH_REQUEST_PARAM"Exposes HuaweiIdAuthParam.DEFAULT_AUTH_REQUEST_PARAM. Default authorization parameter of an AppTouch ID.
DEFAULT_AUTH_REQUEST_PARAM_GAME"DEFAULT_AUTH_REQUEST_PARAM_GAME"Exposes HuaweiIdAuthParam.DEFAULT_AUTH_REQUEST_PARAM_GAME. Default authorization parameter of a game.

AuthScopeList

Constant FieldsValueDefinition
GAME"https://www.huawei.com/auth/games"Value to specify game scope.
OPENID"openid"Value to specify openid scope.
EMAIL"email"Value to specify email scope.
PROFILE"profile"Value to specify profile scope.

Gender

Constant FieldsValueDefinition
UNKNOWN-1Unkown
MALE0Male
FEMALE1Female
CONFIDENTIAL2Confidential

Theme

Constant FieldsValueDefinition
THEME_NO_TITLE0Button without any title.
THEME_FULL_TITLE1Button with an icon and a title.

ColorPolicy

Constant FieldsValueDefinition
COLOR_POLICY_BLUE0Blue button.
COLOR_POLICY_RED1Red button.
COLOR_POLICY_WHITE2White button.
COLOR_POLICY_WHITE_WITH_BORDER3White button with strokes.
COLOR_POLICY_BLACK4Black button.
COLOR_POLICY_GRAY5Gray button.

CornerRadius

Constant FieldsValueDefinition
CORNER_RADIUS_LARGE-1Button with large rounded corners.
CORNER_RADIUS_MEDIUM-2Button with medium-sized rounded corners.
CORNER_RADIUS_SMALL-3Button with small rounded corners

ErrorCodes

Constant FieldsValueDefinition
HuaweiIdAuthException"503"An authentication error occurs.

Data Types

AuthHuaweiIdBuilder

Field NameTypeDefinition
openIdstringopenId.
uidstringuid.
displayNamestringNickname.
photoUrlstringObtains the picture url.
accessTokenstringAccess token.
serviceCountryCodestringService country code.
statusnumberUser status. 1: Normal; 2: Dbank suspended; 3: Deregistered, 4: All services are suspended.
genderGenderUser Gender.
scopesAuthScopeList[]Authorized scopes.
serverAuthCodestringserverAuthCode.
unionIdstringunionId.
countryCodestringRegistration country code.

AuthHuaweiId

FieldTypeDefinition
accessTokenstringAccess token.
displayNamestringNickname.
emailstringEmail adress.
familyNamestringFamily name.
givenNamestringGiven name.
idTokenstringID Token
unionIdstringUnion Id
avatarUriStringstringProfile picture URI
openIdstringOpenId
describeContentsInAuthHuaweiIdnumberDescribe Contents In AuthHuaweiId
authorizedScopesstring[]Authorized Scopes
authorizationCodestringAuthorization Code
huaweiAccountAccountHuawei Account

Account

Field NameTypeDefinition
typestringType of HUAWEI ID Account.
namestringName of the HUAWEI ID Account.
Field NameTypeDefinition
cookieNamestringCookie name.
cookieValuestringCookie value.
domainstringCookie domain name.
pathstringPage path for accessing the cookie.
isHttpOnlybooleanValue true indicates that the cookie information is contained only in the HTTP request header and cannot be accessed through document.cookie.
isSecurebooleanValue true indicates that the cookie can be transmitted only through HTTPS, and value false indicates that the cookie can be transmitted through HTTP.
maxAgenumberCookie lifetime, in seconds.

DomainInfo

Field NameTypeDefinition
domainstringDomain name.
isUseHttpsbooleanValue true indicates HTTPS, and value false indicates HTTP.

ContainScopesResult

Field NameTypeDefinition
containScopesbooleantrue: The HUAWEI ID has all the permissions specified by scopeArr. false: The HUAWEI ID does not have all the permissions specified by scopeArr.

SignInData

Field NameTypeDefinition
authRequestOptionAuthRequestOption[]AuthRequestOption array to customize the authorization.
authParamHuaweiIdAuthParamsAuthorization scope parameter to customize the authorization. It is optional.
authScopeListAuthScopeList[]AuthScopeList array to customize the authorization. If this value not passed to API, an empty array will be send. It is optional.

4. Configuration and Description

SMS Message Rules

After the service of reading SMS messages is enabled, the SMS message you obtain is as follows:

prefix_flag short message verification code is XXXXXX hash_value

prefix_flag indicates the prefix of an SMS message, which can be <#>, [#], or **. short message verification code is indicates the content of an SMS message, which is user-defined. XXXXXX indicates the verification code. hash_value indicates the hash value generated by the HMS SDK based on your app package name to uniquely identify your app.

Preparing for Release

Before building the APK, configure the obfuscation configuration file to prevent the HMS Core SDK from being obfuscated.

NOTE: This step is required only if you want to minify and obfuscate your app. By default obfuscation is disabled in Cordova and Ionic apps.

The obfuscation is done by ProGuard. By default, in Cordova and Ionic apps ProGuard is disabled. Even though ProGuard is not available, ProGuard support can be added through 3rd party ProGuard plugins. If ProGuard is enabled in your project, the Huawei Cordova Safety Detect plugin's ProGuard rules need to be added to your project. These rules are as follows:

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-repackageclasses

5. Sample Project

You can find the sample projects on HMS Core > Examples > Account Kit page.


6. Questions or Issues

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • GitHub is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the GitHub repository.


7. Licensing and Terms

Huawei Account Kit Cordova Plugin is licensed under the Apache 2.0 license.

Keywords

FAQs

Package last updated on 30 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc