This document explains how to integrate one-click login into a HarmonyOS client and provides interface usage examples.
The one-click logon service works only when cellular data is enabled and the application has permission to use the cellular network.
The number retrieval request consumes a small amount of data.
China Mobile supports 2G, 3G, 4G, and 5G data networks. On 2G and 3G networks, latency is higher and the success rate is lower than on 4G networks.
China Telecom supports 4G and 5G data networks, but not 2G or 3G.
China Unicom supports 3G, 4G, and 5G data networks, but not 2G.
Procedure
Get the SDK
Log in to the Phone Number Verification Service console. On the overview page, in the API & SDK section on the right, click Download Now. On the API & SDK page, select Phone Number Verification Service for HarmonyOS.
Import the project
Create or open your project in DevEco Studio.
Extract the downloaded package and copy the
.harfile to thelibsdirectory in your project.
Add the SDK dependency to the
oh_package.json5file in your module:Note: This is the
oh_package.json5file in the module, not the one in the project's root directory. For example, refer to the demo project in the package."dependencies": { "numberauth_standard": "file:libs/auth_number_product-2.0.1-log-online-standard-release.har" }
Configure permissions
Edit the module.json5 file to configure the required permissions for the SDK:
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
},
{
"name": "ohos.permission.GET_NETWORK_INFO"
},
{
"name": "ohos.permission.SET_NETWORK_INFO"
}
]Permission | Description |
INTERNET | Lets your application connect to the internet to access the gateway and authentication server. |
GET_NETWORK_INFO | Lets your application get the network status to determine the connection type, such as cellular data or Wi-Fi. |
SET_NETWORK_INFO | Lets your application configure the cellular data network. This permission is required to switch to the cellular network for number retrieval. |
Request a certification scheme key
API calls require a scheme code and a key. To obtain them, go to the Phone Number Verification Service console and create a certification scheme. You will need to provide your app name, package name, package signature, and AppId.
Get the signature
Use the following HarmonyOS code to get the package name, package signature, and AppId.
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO).then((bundleInfo) => {
const packageName = bundleInfo.name
console.log("numberauth:pagname:" + packageName)
const sign = bundleInfo.signatureInfo.fingerprint
console.log("numberauth:sign:" + sign)
const appIdentifier = bundleInfo.signatureInfo.appIdentifier
console.log("numberauth:appid:" + appIdentifier)
})Sign your app
If you have not yet signed your new project, use the automatic signing feature in DevEco Studio:
To use automatic signing, click the Project Structure icon in the upper-right corner of the IDE:

In the dialog, navigate to Project > Signing Configs and select the Automatically generate signature checkbox. Wait for the process to complete, and then click OK.

For more information about configuring app signatures for HarmonyOS apps, see the official HarmonyOS documentation.
Interaction flow
For the complete flow, see one-click login interaction flow.
SDK methods
Required: Create an entry point instance
PhoneNumberAuthHelper is the entry point of the SDK. All API calls must be made through PhoneNumberAuthHelper.
Required: Configure the authorization page UI
public setAuthConfig(config: AuthUiConfig): void;Parameters:
Parameter | Type | Description |
config | AuthUiConfig | A configuration object that contains the UI parameters for the authorization page and secondary pop-up. For more information, see UI Page API Reference. |
Required: Set the secret key
public setAuthSDKInfo(secretInfo: string): voidParameters:
Parameter | Type | Description |
secretInfo | string | The SDK secret key. You can obtain it by creating an authentication scheme in the Phone Number Verification Service console. |
Required: Retrieve the token
Authorization request
When you call this method, the SDK displays the authorization page. After the user grants authorization, the SDK returns a token to your app.
// Timeout duration in milliseconds.
public getLoginToken(totalTime: number): Promise<void>;Parameters:
Parameter | Type | Description |
totalTime | number | The timeout duration in milliseconds. |
Usage example
this.helper.getLoginToken(5000)The method returns the result through the TokenResultListener callback:
class TokenListener implements TokenResultListener {
private page: Index
constructor(page: Index) {
this.page = page
}
onSuccess(msg: string): void {
console.log("auth:onSuccess:" + msg)
const result: object = JSON.parse(msg)
const code = result['_code'] + ''
const token = result['_token'] + ''
if (code === "600000") {
this.page.quitLoginPage()
}
}
onFailure(ret: string): void {
console.log("auth:onFailure:" + ret)
this.page.updateAuth()
}
}Required: Clear the flow callback listener
After the flow completes, call this method to clear the listener and prevent unnecessary background processing.
public clearAuthListener():voidOptional: Exit the authorization page
After the authorization page appears, call this method to exit.
public quitLoginPage(): Promise<void>;Use this method to close the authorization page, end the Phone Number Verification Service session, and switch to your custom login UI.
For example, the demo (path shown in the figure below) uses a custom logo component to set the logo image and position. Clicking the logo closes the authorization page and invokes custom login logic, which allows the user to switch to other login methods. To download the demo, see HarmonyOS Client Demo.

Optional: Set the callback listener
Adds or updates the listener for the authentication flow.
public setAuthListener(listener: TokenResultListener): voidParameters:
Parameter | Type | Description |
listener | TokenResultListener | The listener to add or update. |
Optional: Check the runtime environment
This method checks if the device's runtime environment is suitable for the SDK and returns the result in the callback.
public checkEnvAvailable(type: number): voidParameters:
Parameter | Type | Description |
type | number | The SDK feature type. Valid values:
|
Optional: Get carrier type
Returns the carrier type of the default data SIM card.
public getCurrentCarrierName(): StringReturn value description: CMCC: China Mobile; CUCC: China Unicom; CTCC: China Telecom.
Optional: Accelerate one-click login (pre-fetch)
We recommend that you call this interface in advance to quickly bring up the authorization page. Bringing up the authorization page requires a successful pre-fetch. If you do not call this interface in advance and instead call the getlogintoken interface directly, the SDK automatically calls the pre-fetch interface first, which causes a noticeable delay before the authorization page appears.
When to call this method
We recommend that you call this interface 2 to 3 seconds before you call the
getlogintokeninterface, because this interface requires 1 to 3 seconds to obtain a temporary credential.Call this method only for users who are not logged in.
Do not call this method frequently, repeatedly, or while or after the authorization page appears.
If the login process starts immediately after the app launches, you do not need to call this method.
Usage example:
class PreListener implements PreLoginResultListener {
onTokenSuccess(vendor: string): void {
throw new Error('Method not implemented.');
}
onTokenFailed(vendor: string, ret: string): void {
throw new Error('Method not implemented.');
}
}
let preListener = new PreListener();
this.helper.accelerateLoginPage(5000, preListener);Parameters:
public accelerateLoginPage(overdueTimeMills: number, listener: PreLoginResultListener): voidParameter | Type | Description |
overdueTimeMills | number | The timeout duration, in milliseconds. |
listener | PreLoginResultListener | The callback listener. |
Optional: Set dialog mode
Sets the SDK to display the authorization page and agreement details pages in dialog mode.
public setDialog(isDialog: boolean): voidParameters:
Parameter | Type | Description |
isDialog | boolean | Specifies whether to enable dialog mode. Valid values:
|
Optional: Set a UI click listener
Sets a listener for click events on the authorization page and the secondary pop-up.
public setUIClickListener(listener: AuthUIControlClickListener): voidParameters:
Parameter | Type | Description |
listener | AuthUIControlClickListener | The callback listener for click events. |
Optional: Check the agreement checkbox state
Use this method to check if the agreement checkbox on the authorization page is selected. Based on the state, you can display a message or a secondary privacy agreement pop-up.
public queryCheckBoxIsChecked(): booleanUI page API
Create authorization page
Secondary pop-up
SDK return codes
For the return codes from the Phone Number Verification HarmonyOS client SDK, see Alibaba Cloud Phone Number Verification SDK return code reference (HarmonyOS client only).
Common import issues
[build init]failed:npm ERR! Error: EPERM: operation not permittedThis error indicates a permission issue on Windows. To resolve this, ensure your local development environment, including the SDK and Node.js, is configured correctly. Then, run DevEco Studio as an administrator.
[Ohpm Install]failed:ohpm ERROR: missing: numberauth_standardThis error indicates that the
numberauth_standarddependency is missing or incorrectly referenced. Refer to the Import the project section to verify that the SDK dependency's path and name are correct. The full error message is as follows:ohpm ERROR: missing: numberauth_standard@C:\workspace\NumberAuthDemo\demo\libs, required by demo@1.0.0 ohpm ERROR: Found exception: Error: Fetch local folder package error, C:\workspace\NumberAuthDemo\demo\libs\oh-package.json5 does not exist., reached retry limit or non retryable error encountered. ohpm ERROR: Install failed, detail: Error: Fetch local folder package error, C:\workspace\NumberAuthDemo\demo\libs\oh-package.json5 does not exist.To resolve an SDK import failure:
Delete the imported
oh_modulesfolder and theoh_modulesfolder in the project root directory.
Then, run ohpm installin the DevEco Studio terminal to re-import the SDK.


Then, run 