5.0.0 • Published 5 years ago

cordova-plugin-hms-account v5.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

CORDOVA PLUGIN HMS ACCOUNT

  1. Contents

  2. Introduction

  3. Installation Guide

  4. Cordova SDK API Method Definition

  5. Configure Description

  6. Licensing and Terms

1. Contents

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

The Cordova SDK code package is described as follows:

src/main/java/com/huawei/hms/cordova/account: Core layer that exposes AccountSDK functionality to JS side.

www: Public interfaces for interacting AccountSDK through Cordova.

2. Installation Guide

  1. Download the Cordova Account SDK Plugin.

  2. Add Platform To Project.

    cordova platform add android

  3. Run the following command in the root directory of the Cordova project:

    cordova plugin add PATH_TO_CORDOVA_ACCOUNT_SDK

  4. Check whether the Cordova Account SDK is successfully added to Plugin folder in the root directory of the Cordova project.

  5. Add agconnect-services.json and jks file to root directory.

  6. Add build.json file to your project's root.

  7. Then run the Cordova app.

    cordova run android

3. Cordova SDK API Method And Constant Definition

Module Overview

ModuleDefinition
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

Functions

Return TypeMethodsDefinition
Promise\<AuthHuaweiId>signInThis API is called to sign in to the apps with HUAWEI IDs securely.
Promise<>signOutThis API is called to sign out of a HUAWEI ID from an app.
Promise<>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.

signIn (authParams)

This API is called for HUAWEI sign-in.

ParameterTypeDescription
authParamsString[]Object to customize the authorization.
ReturnDescription
Promise\<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.

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.

ReturnDescription
Promise<>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.

cancelAuthorization()

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

ReturnDescription
Promise<>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.

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.

ReturnDescription
Promise\<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.

Constants

NameDefinition
HMSAccount.SCOPE_PROFILERequests a HUAWEI ID user to authorize profile information to an app.
HMSAccount.SCOPE_ID_TOKENRequests a HUAWEI ID user to authorize ID token to an app.
HMSAccount.SCOPE_ACCESS_TOKENRequests a HUAWEI ID user to authorize access token to an app.
HMSAccount.SCOPE_MOBILE_NUMBERRequests a HUAWEI ID user to authorize mobile number to an app.
HMSAccount.SCOPE_EMAILRequests a HUAWEI ID user to authorize email address to an app.
HMSAccount.SCOPE_SHIPPING_ADDRESSRequests a HUAWEI ID user to authorize shipping address to an app.
HMSAccount.SCOPE_UIDRequests a HUAWEI ID user to authorize uId token to an app.
HMSAccount.SCOPE_IDRequests a HUAWEI ID user to authorize ID to an app.
HMSAccount.SCOPE_AUTHORIZATION_CODERequests a HUAWEI ID user to authorize authorization code to an app.

HMSHuaweiIdAuthManager

Functions

Return TypeMethodsDefinition
Promise<>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.

addAuthScopes(requestCode, scopeList)

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

ParameterTypeDescription
requestCodeIntegerRequest Id.
scopeListString[]Authorization scope list.
Return TypeDescription
Promise<>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.

containScopes(authHuaweiId, scopeList)

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

ParameterTypeDescription
authHuaweiIdAuthHuaweiIdAuthorized HUAWEI ID information.
scopeListString[]Authorization scope list.
ReturnDescription
Promise\<ContainScopesResult>If the operation is successful, promise resolves to an object that contains boolean result, like {"containScopes": false }. Otherwise it throws an error.

getAuthResultWithScope(scopeList)

This API is called to obtain the AuthHuaweiId.

ParameterTypeDescription
scopeListString[]Authorization scope list.
ReturnDescription
Promise\<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.

getAuthResult()

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

ReturnDescription
Promise\<AuthHuaweiId>If the operation is successful, promise resolves to a AuthHuaweiId object. Otherwise it throws an error.

HMSHuaweiIdAuthTool

Functions

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

requestUnionId(huaweiAccountName)

Obtains a unionId.

ParameterTypeDescription
huaweiAccountNameStringHUAWEI ID Name.
ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains union id. Otherwise it throws an error.

requestAccessToken(account, scopeList)

Obtains a token.

ParameterTypeDescription
accountAccountHUAWEI ID for which you need to obtain a token. It contains name and type properties.
scopeListString[]HUAWEI ID authorization scope. This array takes Scope values.
ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains a access token. Otherwise it throws an error.

deleteAuthInfo(accessToken)

Clears the local cache.

ParameterTypeDescription
accessTokenStringToken to be clear.
ReturnDescription
Promise<>If the operation is successful, promise will resolve successfully. Otherwise it throws an error.

HMSNetworkTool

Functions

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.

buildNetworkCookie(cookie)

Constructs a cookie by combining input values.

ParameterTypeDescription
cookieCookieIt is an object that contains cookieName, cookieValue, domain, path, isHttpOnly, isSecure, maxAge.
ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains a cookie. Otherwise it throws an error.

buildNetworkURL(domainInfo)

Returns cookie url based on the domain name and isUseHttps.

ParameterTypeDescription
domainInfoDomainInfoThe parameter that contains a domain name and isUseHttps info.
ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains a cookie url. Otherwise it throws an error.

HMSReadSMSManager

Functions

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.

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.

ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains a content of SMS. Otherwise it throws an error.

obtainHashCode()

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

ReturnDescription
Promise\<String>If the operation is successful, promise resolves to a String that contains a hash value. Otherwise it throws an error.

HMSHuaweiIdAuthButton

Functions

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

getHuaweiIdAuthButton(buttonId, theme, colorPolicy, cornerRadius)

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

ParameterTypeOptionDescription
buttonIdStringId of div that is used for HuaweiIdAuthButton.
themeInteger0Button without any title.
themeInteger1Button with an icon and a title.
colorPolicyInteger0Blue button.
colorPolicyInteger1Red button.
colorPolicyInteger2White button.
colorPolicyInteger3White button with strokes.
colorPolicyInteger4Black button.
colorPolicyInteger5Gray button.
cornerRadiusInteger-1Button with large rounded corners.
cornerRadiusInteger-2Button with medium-sized rounded corners.
cornerRadiusInteger-3Button with small rounded corners

Data Types

AuthHuaweiId

Field NameTypeDescription
openIdStringopenId.
uidStringuid.
displayNameStringNickname.
photoUrlStringObtains the picture url.
accessTokenStringAccess token.
serviceCountryCodeStringService country code.
statusIntegerUser status. 1: Normal; 2: Dbank suspended; 3: Deregistered, 4: All services are suspended.
genderIntegerUser Gender. -1: Unknown, 0: male, 1: female, 2: confidential.
scopesString[]Authorized scopes.
serverAuthCodeStringserverAuthCode.
unionIdStringunionId.
countryCodeStringRegistration country code.

Account

Field NameTypeDescription
typeStringType of HUAWEI ID Account.
nameStringName of the HUAWEI ID Account.

Cookie

Field NameTypeDescription
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.
maxAgeLongCookie lifetime, in seconds.

DomainInfo

Field NameTypeDescription
domainStringDomain name.
isUseHttpsBooleanValue true indicates HTTPS, and value false indicates HTTP.

ContainScopesResult

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

4. Configure Description

No.

5. Licensing and Terms

Apache 2.0 license.

5.0.0

5 years ago