This module provides the authentication capabilities of Account Kit, including account sign-in, authorization, and authorization revoking.
Start version: 4.0.0(10)
Provides methods for implementing the authentication service and provides the capabilities for creating sign-in, authorization, and authorization revoking request objects.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: HuaweiIDProvider inherits from AuthenticationProvider.
createLoginWithHuaweiIDRequest(): LoginWithHuaweiIDRequest
Creates a sign-in request object with default scopes and permissions. You can set request parameters based on the return values.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Returns:
| Type | Description |
|---|---|
| Request object for a HarmonyOS app to use the Account Kit-based sign-in API to obtain data such as the UnionID and OpenID. |
Example:
import { authentication } from '@kit.AccountKit';
const huaweiIdProvider = new authentication.HuaweiIDProvider();
const loginWithHuaweiIDRequest = huaweiIdProvider.createLoginWithHuaweiIDRequest(); createAuthorizationWithHuaweiIDRequest(): AuthorizationWithHuaweiIDRequest
Creates an Account Kit-based authorization request object. You can set request parameters based on the return values.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Returns:
| Type | Description |
|---|---|
| Request object for authorizing a HarmonyOS app to obtain user information. |
Example:
import { authentication } from '@kit.AccountKit';
const huaweiIdProvider = new authentication.HuaweiIDProvider();
const request = huaweiIdProvider.createAuthorizationWithHuaweiIDRequest(); createCancelAuthorizationRequest(): CancelAuthorizationRequest
Creates an Account Kit-based authorization revoking request object. You can set request parameters based on the return values.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Returns:
| Type | Description |
|---|---|
| Request object for revoking the authorization for a HarmonyOS app. |
Example:
import { authentication } from '@kit.AccountKit';
const huaweiIdProvider = new authentication.HuaweiIDProvider();
const cancelAuthorizationRequest = huaweiIdProvider.createCancelAuthorizationRequest(); getHuaweiIDState(request: StateRequest): Promise<StateResult>
Obtains the sign-in status of a HUAWEI ID. This API returns the result asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | Yes | Request object for obtaining the sign-in status of a HUAWEI ID. The object includes request parameters. |
Returns:
| Type | Description |
|---|---|
| Promise<StateResult> | StateResult object returned through a promise. |
Error codes:
For details about the error codes, please refer to Account Management Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| System service works abnormally. | |
| Invalid input parameter value. |
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Create request parameters.
const stateRequest: authentication.StateRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
}
try {
// Execute the request for obtaining the HUAWEI ID sign-in status and process the result.
new authentication.HuaweiIDProvider().getHuaweiIDState(stateRequest).then((data: authentication.StateResult) => {
hilog.info(0x0000, 'testTag', 'Succeeded in getting huaweiIdState result.');
const state = data.state;
// Process the state.
}).catch((error: BusinessError) => {
this.dealAllError(error);
})
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', 'Failed to get huaweiIdState, errorCode=%{public}d, errorMsg=%{public}s', error.code, error.message);
} getMobileNumberConsistency(request: ConsistencyRequest): Promise<ConsistencyResult>
Obtains the mobile number consistency status. This API returns the result asynchronously through a promise.
Before using the API for obtaining the mobile number consistency status, apply for the quickLoginMobilePhone scope first. For details, please refer to Prerequisites. If the scope/permission application fails, error 1001502014 will be returned, indicating that the app has not got necessary scopes/permissions.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | Yes | Request object for obtaining the mobile number consistency status, including request parameters. |
Returns:
| Type | Description |
|---|---|
| Promise<ConsistencyResult> | ConsistencyResult object returned through a promise. |
Error codes:
For details about the error codes, please refer to ArkTS Error Codes and Universal Error Codes.
| Error Code | Error Message |
|---|---|
| Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | |
| Failed to check the fingerprint of the app bundle. | |
| The account does not support this function. | |
| This function is restricted from being called. | |
| The user has not logged in with HUAWEI ID. | |
| The application is not authorized. | |
| Network error. | |
| Internal error. | |
| The app does not have the required scopes or permissions. |
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Create request parameters.
const consistencyRequest: authentication.ConsistencyRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
mobileNumber: '+86xxxxxxxxxxx' // Plaintext mobile number obtained through the one-tap HUAWEI ID sign-in function.
}
try {
// Execute the request for obtaining the mobile number consistency status and process the result.
new authentication.HuaweiIDProvider().getMobileNumberConsistency(consistencyRequest).then((data: authentication.ConsistencyResult) => {
hilog.info(0x0000, 'testTag', 'Succeeded in getting getMobileNumberConsistency result = %{public}d', data.state);
const state = data.state;
// Process the state.
}).catch((err: BusinessError) => {
this.dealAllError(err);
})
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', 'Failed to getMobileNumberConsistency, errorCode=%{public}d, errorMsg=%{public}s', error.code, error.message);
} Defines the request object for a HarmonyOS app to use the Account Kit-based sign-in API to obtain data such as the UnionID and OpenID.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: LoginWithHuaweiIDRequest inherits from AuthenticationRequest.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| forceLogin | boolean | No | Yes | Indicates whether a user needs to sign in. If the value is true but no HUAWEI ID has signed in, the HUAWEI ID sign-in screen will be displayed. In addition, LoginWithHuaweiIDRequest must be executed in the context of an ArkUI screen. Otherwise, an exception will be thrown. If the value is false and no HUAWEI ID has signed in, error 1001502001 will be returned. The default value is true. |
| state | string | No | Yes | state parameter in the request body. This parameter will be compared with the state parameter in the response body to prevent cross-site attacks. You can set this parameter to a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. For security purposes, util.generateRandomUUID() is recommended. |
| nonce | string | No | Yes | nonce parameter in the request body. This parameter is contained in the returned ID token and can be used to prevent replay attacks through consistency verification. The value is a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. You are advised to use nonces and perform consistency verification. If this parameter is not passed or is left empty, the default value of nonce in the ID token is default. For security purposes, util.generateRandomUUID() is recommended. |
| idTokenSignAlgorithm | No | Yes | Signature algorithm of ID tokens. The default value is PS256. |
Example:
import { authentication } from '@kit.AccountKit';
import { util } from '@kit.ArkTS';
const loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
loginRequest.forceLogin = true;
loginRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256; // The default value is PS256.
loginRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state. ID token signature algorithm, which has enumerated values. ID tokens are encrypted according to the value of IdTokenSignAlgorithm.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
| Name | Value | Description |
|---|---|---|
| PS256 | 1 | RSASSA-PSS uses SHA-256 and SHA-256-based MGF1. |
| RS256 | 2 | RSASSA-PKCS1-v1_5 uses SHA-256. |
Example:
import { authentication } from '@kit.AccountKit';
const loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
loginRequest.forceLogin = true;
loginRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256; Response to an Account Kit-based sign-in request. You can obtain the OpenID, UnionID, authorization code, and ID token data after parsing the response.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: LoginWithHuaweiIDResponse inherits from AuthenticationResponse.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| data | Yes | Yes | Sign-in result data, containing the openID, unionID, authorizationCode, and idToken parameters. | |
| state | string | Yes | Yes | state parameter returned in the response body. Account Kit compares this parameter with the state parameter passed in the request body to prevent cross-site attacks. The value is a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create a sign-in request and set parameters.
const loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
loginRequest.forceLogin = true;
loginRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;
loginRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
// Execute the sign-in request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(loginRequest, (error: BusinessError<Object>, data) => {
if (error) {
this.dealAllError(error);
return;
}
const loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
const state = loginWithHuaweiIDResponse.state;
if (state != undefined && loginRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to login. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in login.');
const loginWithHuaweiIDCredential = loginWithHuaweiIDResponse.data!;
const code = loginWithHuaweiIDCredential.authorizationCode;
const idToken = loginWithHuaweiIDCredential.idToken;
const openID = loginWithHuaweiIDCredential.openID;
const unionID = loginWithHuaweiIDCredential.unionID;
// Process code, idToken, openID, and unionID.
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to login. Code: ${error.code}, message: ${error.message}`);
} Credential returned after successful Account Kit-based sign-in. The credential is used to parse out the data returned upon the sign-in, such as the authorization code and ID token.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| authorizationCode | string | Yes | Yes | Authorization code. This temporary credential is valid for 5 minutes and can be used only once. |
| idToken | string | Yes | Yes | ID token. It is a character string in JWT format, containing user information. |
| openID | string | Yes | No | OpenID, which represents the identity of a HUAWEI ID user when using different types of products. The same user has different OpenIDs for different apps. |
| unionID | string | Yes | No | UnionID, which represents the identity of a HUAWEI ID user when using different products of the same developer. The same user has the same UnionID for different apps of the same developer. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create a sign-in request and set parameters.
const loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
loginRequest.forceLogin = true;
loginRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;
loginRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
// Execute the sign-in request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(loginRequest, (error: BusinessError<Object>, data) => {
if (error) {
this.dealAllError(error);
return;
}
const loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
const state = loginWithHuaweiIDResponse.state;
if (state != undefined && loginRequest.state != state) {
hilog.error(0x0000,
'testTag', `Failed to login. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in login.');
const loginWithHuaweiIDCredential = loginWithHuaweiIDResponse.data!;
const code = loginWithHuaweiIDCredential.authorizationCode;
const idToken = loginWithHuaweiIDCredential.idToken;
const openID = loginWithHuaweiIDCredential.openID;
const unionID = loginWithHuaweiIDCredential.unionID;
// Process code, idToken, openID, and unionID.
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to login. Code: ${error.code}, message: ${error.message}`);
} Authorization request for an app, containing parameters such as scopes and permissions. Account Kit is used to request authorization to apply for more user information.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: AuthorizationWithHuaweiIDRequest inherits from AuthenticationRequest.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| scopes | string[] | No | Yes | List of scopes used to obtain user data. The scopes and permissions parameters cannot be empty at the same time. Otherwise, error 1001502003 will be returned. If an invalid scope (for example, null) is passed, the OpenID and UnionID are directly returned. The options of scopes are as follows:
|
| permissions | string[] | No | Yes | List of permissions. The scopes and permissions parameters cannot be empty at the same time. Otherwise, error 1001502003 will be returned. If an invalid permission (for example, null) is passed, the OpenID and UnionID are directly returned. The options of permissions are as follows:
|
| forceAuthorization | boolean | No | Yes | Indicates whether a user needs to give sign-in authorization. The default value is true. If the value is true but the user has not signed in or given authorization, the user sign-in or authorization screen will be displayed. In addition, AuthorizationWithHuaweiIDRequest must be executed in the context of an ArkUI screen. Otherwise, an exception will be thrown. If the value is false and the user has not signed in, error 1001502001 will be returned upon AuthorizationWithHuaweiIDRequest execution. |
| state | string | No | Yes | state parameter in the request body. You can set this parameter to a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. This parameter will be compared with the state parameter in the response body to prevent cross-site attacks. For security purposes, util.generateRandomUUID() is recommended. |
| nonce | string | No | Yes | nonce parameter in the request body. The value is a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. This parameter is contained in the returned ID token and can be used to prevent replay attacks through consistency verification. You are advised to use nonces and perform consistency verification. If this parameter is not passed or is left empty, the default value of nonce in the ID token is default. For security purposes, util.generateRandomUUID() is recommended. |
| idTokenSignAlgorithm | No | Yes | Signature algorithm of ID tokens. The default value is PS256. |
Example:
import { authentication } from '@kit.AccountKit';
import { util } from '@kit.ArkTS';
const authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
authRequest.scopes = ['profile']; // Atomic services do not support profile. You need to pass other scopes that are supported.
authRequest.permissions = ['idtoken'];
authRequest.forceAuthorization = true;
authRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
authRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256; Encapsulates the user information obtained upon an authorization request.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: AuthorizationWithHuaweiIDResponse inherits from AuthenticationResponse.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| data | Yes | Yes | User authorization result data. | |
| state | string | Yes | Yes | state parameter returned in the response body. The value is a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. This parameter will be compared with the state parameter in the request body to prevent cross-site attacks. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create an authorization request and set parameters.
const authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
authRequest.scopes = ['profile']; // Atomic services do not support profile. You need to pass other scopes that are supported. By default, the OpenID and UnionID are returned.
authRequest.permissions = ['idtoken', 'serviceauthcode'];
authRequest.forceAuthorization = true;
authRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
authRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;
// Execute the authorization request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(authRequest, (error: BusinessError<Object>, data) => {
if (error) {
this.dealAllError(error);
return;
}
const authorizationWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;
const state = authorizationWithHuaweiIDResponse.state;
if (state != undefined && authRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to authorize. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in authentication.');
const authorizationWithHuaweiIDCredential = authorizationWithHuaweiIDResponse.data!;
const avatarUri = authorizationWithHuaweiIDCredential.avatarUri; // Atomic services do not support this parameter.
const nickName = authorizationWithHuaweiIDCredential.nickName; // Atomic services do not support this parameter.
const idToken = authorizationWithHuaweiIDCredential.idToken;
const openID = authorizationWithHuaweiIDCredential.openID;
const unionID = authorizationWithHuaweiIDCredential.unionID;
const code = authorizationWithHuaweiIDCredential.authorizationCode;
// Process avatarUri, nickName, idToken, openID, unionID, and code.
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to auth. Code: ${error.code}, message: ${error.message}`);
} Parses the user information returned upon an authorization request.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| authorizationCode | string | Yes | Yes | Authorization code. This temporary credential is valid for 5 minutes and can be used only once. Return scenario: This parameter is returned when the serviceauthcode parameter is passed to permissions of the AuthorizationWithHuaweiIDRequest API. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
| idToken | string | Yes | Yes | ID token. It is a character string in JWT format, containing user information. Return scenario: This parameter is returned when the idtoken parameter is passed to permissions of the AuthorizationWithHuaweiIDRequest API. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
| openID | string | Yes | Yes | OpenID, which represents the identity of a HUAWEI ID user when using different types of products. The same user has different OpenIDs for different apps. Return scenario: This parameter is returned by default. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
| unionID | string | Yes | Yes | UnionID, which represents the identity of a HUAWEI ID user when using different products of the same developer. The same user has the same UnionID for different apps of the same developer. Return scenario: This parameter is returned by default. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
| avatarUri | string | Yes | Yes | Link to a user avatar, which has a short validity period. You are advised to download and save the avatar before using it. Return scenario: This parameter is returned when the profile parameter is passed to scopes of the AuthorizationWithHuaweiIDRequest API. NOTICE: Atomic services do not support this parameter. |
| nickName | string | Yes | Yes | Nickname of a user. Return scenario: This parameter is returned when the profile parameter is passed to scopes of the AuthorizationWithHuaweiIDRequest API. NOTICE: Atomic services do not support this parameter. |
| | string | Yes | Yes | Email address of a user. Return scenario: This parameter is returned when the email parameter is passed to scopes of the AuthorizationWithHuaweiIDRequest API. NOTICE: Atomic services do not support this parameter. |
| authorizedScopes | string[] | Yes | Yes | List of scopes for authorization. Return scenario: This parameter is returned by default. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
| extraInfo | Record<string, Object> | Yes | Yes | Extended information. Return scenario: This parameter is returned when extended request parameters (such as quickLoginAnonymousPhone) are passed to scopes of the AuthorizationWithHuaweiIDRequest API. Atomic service API: This API can be used in atomic services since API version 5.0.0(12). Note: In the one-tap sign-in scenario of a HUAWEI ID, you can use the localNumberConsistency parameter to obtain the comparison result between the mobile number bound to the HUAWEI ID and the mobile number of the local SIM card. true: The two mobile numbers are the same. false: The two mobile numbers are different. NOTE: If the user's device has no SIM cards, false will be returned. As long as the mobile number of one of the device's SIM cards is the same as the passed one, true will be returned. Otherwise, false will be returned. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create an authorization request and set parameters.
const authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
authRequest.scopes = ['profile']; // Atomic services do not support profile. You need to pass other scopes that are supported.
authRequest.permissions = ['idtoken'];
authRequest.forceAuthorization = true;
authRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
authRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;
// Execute the authorization request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(authRequest, (error: BusinessError<Object>, data) => {
if (error) {
this.dealAllError(error);
return;
}
const authorizationWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;
const state = authorizationWithHuaweiIDResponse.state;
if (state != undefined && authRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to authorize. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in authentication.');
const authorizationWithHuaweiIDCredential = authorizationWithHuaweiIDResponse.data!;
const avatarUri = authorizationWithHuaweiIDCredential.avatarUri; // Atomic services do not support this parameter.
const nickName = authorizationWithHuaweiIDCredential.nickName; // Atomic services do not support this parameter.
const idToken = authorizationWithHuaweiIDCredential.idToken;
const unionID = authorizationWithHuaweiIDCredential.unionID;
const openID = authorizationWithHuaweiIDCredential.openID;
// Process avatarUri, nickName, idToken, openID, and unionID.
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to auth. Code: ${error.code}, message: ${error.message}`);
} Request for an app to revoke Account Kit-based authorization.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: CancelAuthorizationRequest inherits from AuthenticationRequest.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| state | string | No | Yes | state parameter in the request body. You can set this parameter to a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. This parameter will be compared with the state parameter in the response body to prevent cross-site attacks. For security purposes, util.generateRandomUUID() is recommended. |
Example:
import { authentication } from '@kit.AccountKit';
import { util } from '@kit.ArkTS';
const cancelRequest = new authentication.HuaweiIDProvider().createCancelAuthorizationRequest();
cancelRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state. Response for an app to revoke Account Kit-based authorization.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Inheritance: CancelAuthorizationResponse inherits from AuthenticationResponse.
Parameters:
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| state | string | Yes | Yes | state parameter returned in the response body. The value is a string of digits (0-9), letters (a-z or A-Z), dots (.), colons (:), slashes (/), and underscores (_). The length limit is 255 characters. The verification rule is ^[0-9a-zA-Z:/\.\-_]{1,255}$. This parameter will be compared with the state parameter in the request body to prevent cross-site attacks. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create an authorization revoking request and set parameters.
const cancelRequest = new authentication.HuaweiIDProvider().createCancelAuthorizationRequest();
cancelRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
// Execute the authorization revoking request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(cancelRequest, (error: BusinessError<Object>, data) => {
if (error) {
this.dealAllError(error);
return;
}
const cancelAuthorizationResponse = data as authentication.CancelAuthorizationResponse;
const state = cancelAuthorizationResponse.state;
if (state != undefined && cancelRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to cancel. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in canceling.');
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to cancel. Code: ${error.code}, message: ${error.message}`);
} Error codes for the sign-in, authorization, and authorization revoking APIs.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
| Name | Value | Description |
|---|---|---|
| PACKAGE_FINGERPRINT_CHECK_ERROR | The certificate fingerprint of the app fails to be verified. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| DUPLICATE_REQUEST_REJECTED | Repeated request. No operation is needed to address this error code. Your app needs to implement tap control to prevent consecutive taps from initiating the same request. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| SCOPE_OR_PERRMISSION_UNSUPPORTED | The scopes or permissions are not supported. Start version: 5.0.0(12) Atomic service API: This API can be used in atomic services since API version 5.0.0(12). | |
| UNSUPPORTED | This function is unavailable for the HUAWEI ID already signed in. Start version: 5.0.0(12) Atomic service API: This API can be used in atomic services since API version 5.0.0(12). | |
| REQUEST_RESTRICTED | This function is restricted. Start version: 5.0.0(12) Atomic service API: This API can be used in atomic services since API version 5.0.0(12). | |
| ACCOUNT_NOT_LOGGED_IN | No HUAWEI ID is signed in. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| APP_NOT_AUTHORIZED | The app is not authorized. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| PARAMETER_INVALID | Invalid input parameter value. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| NETWORK_ERROR | Network error. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| INTERNAL_ERROR | Internal errors, such as Account Kit server errors. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| USER_CANCELED | The user revokes authorization. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). | |
| SCOPE_OR_PERMISSION_NOT_REQUESTED | The app does not have the required scopes or permissions. Atomic service API: This API can be used in atomic services since API version 4.1.0(11). |
Controller for Account Kit-based sign-in, authorization, and authorization revoking requests.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
constructor(context?: common.Context)
Constructor, which constructs the Controller instance for Account Kit-based sign-in, authorization, and other requests.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | No | Context. This parameter is mandatory when the HUAWEI ID sign-in or authorization screen needs to be shown. Otherwise, error 401 will be returned. Contexts supported by apps: UIAbilityContext and UIExtensionContext Apps cannot use UIExtensionContext in non-full-screen components such as semi-modal, pop-up, and sub-window components. Contexts supported by atomic services: UIAbilityContext NOTE:
|
Example:
import { authentication } from '@kit.AccountKit';
const controller = new authentication.AuthenticationController(getContext(this)); executeRequest(request: AuthenticationRequest, callback: AsyncCallback<AuthenticationResponse, Record<string, Object>>): void
Executes requests (such as sign-in and authorization) of Account Kit. This API returns the result asynchronously through a callback.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | Yes | Authentication request body. If parameters are not passed as expected, error 401 will be returned, indicating a parameter error. | |
| callback | AsyncCallback<AuthenticationResponse, Record<string, Object>> | Yes | Callback function. If the operation is successful, err is undefined and data is the obtained AuthenticationResponse object. Otherwise, an error object will be returned. If parameters are not passed as expected, error 401 will be returned, indicating a parameter error. |
Error codes:
For details about the error codes, please refer to Universal Error Codes, Account Management Error Codes, and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | |
| System service works abnormally. | |
| The user has not logged in with HUAWEI ID. | |
| The application is not authorized. | |
| Invalid input parameter value. | |
| Network error. | |
| Internal error. | |
| Failed to check the fingerprint of the app bundle. | |
| The user canceled the authorization. | |
| The app does not have the required scopes or permissions. | |
| This error code is reported when a request is already being processed. | |
| The scopes or permissions are not supported. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create an authorization request and set parameters.
const authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
authRequest.scopes = ['profile']; // Atomic services do not support profile. You need to pass other scopes that are supported.
authRequest.permissions = ['idtoken'];
authRequest.forceAuthorization = true;
authRequest.state = util.generateRandomUUID(); // You are advised to use generateRandomUUID to generate a state.
authRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;
// Execute the authorization request and process the result.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(authRequest, (err: BusinessError<Object>, data) => {
if (err) {
this.dealAllError(err);
return;
}
const authorizationWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;
const state = authorizationWithHuaweiIDResponse.state;
if (state != undefined && authRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to authorize. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in authentication.');
const authorizationWithHuaweiIDCredential = authorizationWithHuaweiIDResponse.data!;
const avatarUri = authorizationWithHuaweiIDCredential.avatarUri; // Atomic services do not support this parameter.
const nickName = authorizationWithHuaweiIDCredential.nickName; // Atomic services do not support this parameter.
const idToken = authorizationWithHuaweiIDCredential.idToken;
const unionID = authorizationWithHuaweiIDCredential.unionID;
const openID = authorizationWithHuaweiIDCredential.openID;
// Process avatarUri, nickName, idToken, openID, and unionID.
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to auth. Code: ${error.code}, message: ${error.message}`);
} executeRequest(request: AuthenticationRequest): Promise<AuthenticationResponse>
Executes Account Kit-based sign-in, authorization, and other requests. This API returns the result asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | Yes | Authentication request body. If parameters are not passed as expected, error 401 will be returned, indicating a parameter error. |
Returns:
| Type | Description |
|---|---|
| Promise<AuthenticationResponse> | AuthenticationResponse object returned through a promise. |
Error codes:
For details about the error codes, please refer to Universal Error Codes, Account Management Error Codes, and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | |
| System service works abnormally. | |
| The user has not logged in with HUAWEI ID. | |
| The application is not authorized. | |
| Invalid input parameter value. | |
| Network error. | |
| Internal error. | |
| Failed to check the fingerprint of the app bundle. | |
| The user canceled the authorization. | |
| The app does not have the required scopes or permissions. | |
| This error code is reported when a request is already being processed. | |
| The scopes or permissions are not supported. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';
// Create an authorization request and set parameters.
const authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
// To obtain a user's mobile number, the following scope must be passed in the request. Before passing it, you first need to submit an application to request this scope.
authRequest.scopes = ['phone'];
// To obtain an authorization code, set the permission as follows.
authRequest.permissions = ['serviceauthcode'];
// Specifies whether HUAWEI ID sign-in needs user authorization. If the value is true but the user has not signed in or given authorization, the user sign-in or authorization screen will be displayed.
authRequest.forceAuthorization = true;
// Used to prevent cross-site request forgery.
authRequest.state = util.generateRandomUUID();
// Execute the request.
try {
const controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(authRequest).then((data) => {
const authorizationWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;
const state = authorizationWithHuaweiIDResponse.state;
if (state != undefined && authRequest.state != state) {
hilog.error(0x0000, 'testTag', `Failed to authorize. The state is different, response state: ${state}`);
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in authentication.');
const authorizationWithHuaweiIDCredential = authorizationWithHuaweiIDResponse.data!;
const code = authorizationWithHuaweiIDCredential.authorizationCode;
const unionID = authorizationWithHuaweiIDCredential.unionID;
const openID = authorizationWithHuaweiIDCredential.openID;
// Process the authorization code, UnionID, and OpenID.
}).catch((err: BusinessError) => {
this.dealAllError(err);
});
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', 'Failed to auth, errorCode=%{public}d, errorMsg=%{public}s', error.code,
error.message);
} Parent class object of authentication requests.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Parent class object of authentication responses.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Parent class object of authentication request providers.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 4.0.0(10)
Enumeration object of ID types.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| USER_ID | 1 | UID of a HUAWEI ID user. NOTE: This parameter is available only to system apps. |
| OPEN_ID | 2 | OpenID of a HUAWEI ID user. |
| UNION_ID | 3 | UnionID of a HUAWEI ID user. |
Enumeration object of HUAWEI ID sign-in statuses.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| UNLOGGED_IN | 0 | No HUAWEI ID is signed in. |
| AUTHORIZED | 1 | A HUAWEI ID has been signed in, and the passed HUAWEI ID is the same as the current HUAWEI ID. |
| UNAUTHORIZED | 2 | A HUAWEI ID has been signed in, but the passed HUAWEI ID is different from the current HUAWEI ID. |
Request object for obtaining the HUAWEI ID sign-in status.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| idType | No | No | ID type of idValue. Currently, non-system apps can only pass IdType.UNION_ID or IdType.OPEN_ID. | |
| idValue | string | No | No | UnionID or OpenID obtained by a user. The value cannot be empty. The type passed is defined by idType. The UnionID and OpenID can be obtained through the LoginWithHuaweiIDResponse, AuthorizationWithHuaweiIDResponse, LoginPanel, or LoginWithHuaweiIDButton API. For details, please refer to the relevant sample code. |
Example:
import { authentication } from '@kit.AccountKit';
// Create request parameters.
const request: authentication.StateRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
} Result object for obtaining the HUAWEI ID sign-in status.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| state | No | No | Enumeration object of HUAWEI ID sign-in statuses. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Create request parameters.
const stateRequest: authentication.StateRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
}
try {
// Execute the request for obtaining the HUAWEI ID sign-in status and process the result.
new authentication.HuaweiIDProvider().getHuaweiIDState(stateRequest).then((data: authentication.StateResult) => {
hilog.info(0x0000, 'testTag', 'Succeeded in getting huaweiIdState result.');
const state = data.state;
// Process the state.
}).catch((err: BusinessError) => {
this.dealAllError(err);
})
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', 'Failed to getHuaweiIdState, errorCode=%{public}d, errorMsg=%{public}s', error.code, error.message);
} Enumeration object of mobile number consistency statuses.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| CONSISTENT | 0 | A HUAWEI ID has signed in, and the passed mobile number is the same as that bound to the HUAWEI ID and also the same as the mobile number of the device's SIM card. NOTE: As long as the mobile number of one of the device's SIM cards is the same as the passed one, 0 will be returned. |
| INCONSISTENT_WITH_DEVICES | 1 | A HUAWEI ID has signed in, and the passed mobile number is the same as that bound to the HUAWEI ID but different from the mobile number of the device's SIM card. NOTE: If the user's device has no SIM cards, 1 will also be returned. |
| INCONSISTENT | 2 | A HUAWEI ID has signed in, but the passed mobile number is different from that bound to the HUAWEI ID. |
Request object for obtaining the mobile number consistency status.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| idType | No | No | ID type of idValue. For non-system apps, this type cannot be set to USER_ID. Otherwise, error 401 will be returned. | |
| idValue | string | No | No | UnionID or OpenID obtained by a user. The value is mandatory and cannot exceed 256 characters. The type of idValue is defined by idType. The UnionID and OpenID can be obtained through the LoginWithHuaweiIDResponse, AuthorizationWithHuaweiIDResponse, LoginPanel, or LoginWithHuaweiIDButton API. For details, please refer to the relevant sample code. |
| mobileNumber | string | No | No | Mobile number obtained through the one-tap sign-in function of the LoginWithHuaweiIDButton component. The country/region code (default: +86) must be added to the passed mobile number. The value is mandatory and cannot exceed 256 characters. |
Example:
import { authentication } from '@kit.AccountKit';
// Create request parameters.
const request: authentication.ConsistencyRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
mobileNumber: '+86xxxxxxxxxxx' // Plaintext mobile number obtained through the one-tap HUAWEI ID sign-in function.
} Result object for obtaining the mobile number consistency status.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AuthenticationServices.HuaweiID.Auth
Start version: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| state | No | No | Enumeration object of mobile number consistency statuses. |
Example:
import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Create request parameters.
const consistencyRequest: authentication.ConsistencyRequest = {
idType: authentication.IdType.UNION_ID,
idValue: '<Value obtained through the HUAWEI ID sign-in API>' // The value can be obtained through the HUAWEI ID sign-in API.
mobileNumber: '+86xxxxxxxxxxx' // Mobile number obtained through the one-tap HUAWEI ID sign-in function.
}
try {
// Execute the request for obtaining the mobile number consistency status and process the result.
new authentication.HuaweiIDProvider().getMobileNumberConsistency(consistencyRequest).then((data: authentication.ConsistencyResult) => {
hilog.info(0x0000, 'testTag', 'Succeeded in getting getMobileNumberConsistency result = %{public}d', data.state);
const state = data.state;
// Process the state.
}).catch((err: BusinessError) => {
this.dealAllError(err);
})
} catch (error) {
this.dealAllError(error);
}
// Handle the error.
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', 'Failed to get mobileNumberConsistency, errorCode=%{public}d, errorMsg=%{public}s', error.code, error.message);
}