To ensure secure network access, use the TLS 1.2 protocol and supported cipher suites. If your app server accesses Account Kit using TLS 1.0, TLS 1.1, or unsupported cipher suites, the connection may fail.
For details about TLS 1.2 and supported cipher suites, please refer to TLS Protocol and Cipher Suites.
This API is called to obtain the UnionID, OpenID, mobile number bound to the HUAWEI ID, and other related information using the authorization code in the one-tap sign-in scenario.
This API is called by your app server from the Account Kit server to obtain the UnionID, OpenID, mobile number bound to the HUAWEI ID, and other related information in the scenario of signing in with HUAWEI ID through just one tap (obtaining the mobile number and UnionID/OpenID). This service is available only to users in the Chinese mainland.
Ensure normal network connection on the caller side.
The one-tap HUAWEI ID sign-in service is available only to users in the Chinese mainland.
Your app needs to request the one-tap HUAWEI ID sign-in scope before calling the corresponding capability. For details, please refer to Requesting Scopes.
Protocol: HTTPS POST
Direction: Your server -> Account Kit server
URL: https://account-api.cloud.huawei.com/oauth2/v6/quickLogin/getPhoneNumber
Data format:
Request: Content-Type: application/json
Response: Content-Type: application/json
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-Type | Yes | String | Content type. The value is application/json. NOTE The request body parameters must follow the format defined in the request header. Otherwise, the request may fail. For details on how to pass these parameters, please refer to Sample Code. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| code | Yes | String | Authorization code obtained in the scenario of signing in with HUAWEI ID through just one tap (obtaining the mobile number and UnionID/OpenID). For details, please refer to App-Side Development. |
| clientId | Yes | String | Unique ID allocated by AppGallery Connect to a newly-created app. For details about the value, please refer to the Client ID field under OAuth 2.0 client ID in Viewing App Basic Information. NOTE The value must match the client ID used for obtaining the authorization code. Otherwise, an error (resultCode=60180003 in the response) will be triggered. If such an error occurs, please refer to Configuring the Client ID for troubleshooting. |
| clientSecret | Yes | String | Client secret allocated by AppGallery Connect to a newly-created app. For details about the value, please refer to the Client secret field under OAuth 2.0 client ID in Viewing App Basic Information. |
Send a POST request. Example:
POST /oauth2/v6/quickLogin/getPhoneNumber HTTP/1.1
Host: account-api.cloud.huawei.com
Content-Type: application/json
{"code":"<code>","clientId": "<clientId>","clientSecret": "<clientSecret>"} | Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-Type | Yes | String | Content type. The value is application/json. |
If the API is successfully called, the response body is as follows.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| openId | Yes | String | OpenID of a user. For details about the format requirements, please refer to Formats of OpenID and UnionID. |
| unionId | Yes | String | UnionID of a user. For details about the format requirements, please refer to Formats of OpenID and UnionID. |
| phoneNumber | Yes | String | Mobile number (including the country/region code) bound to the HUAWEI ID. The mobile number is used for one-tap sign-in. For details, please refer to Signing In with HUAWEI ID Through Just One Tap (Obtaining the Mobile Number, UnionID, and OpenID). |
| phoneNumberValid | Yes | Integer | Indicates whether the validity of a mobile number, which is bound to a HUAWEI ID, obtained through one-tap sign-in has been verified. If the value of verifyPhoneNumber passed in LoginPanelParams during one-tap sign-in is true, Huawei verifies the mobile number. You can ignore this parameter. If the passed value of verifyPhoneNumber is false, determine the processing based on the following status values: 0: indicates that it cannot be proved that the user has ever been reached through the mobile number in the past 90 days and mobile number verification is required. 1: indicates that it can be proved that the user has ever been reached through the mobile number in the past 90 days and mobile number verification is not required. |
| purePhoneNumber | Yes | String | Mobile number without a country/region code. The value is derived from phoneNumber by removing the international call prefix and country/region code. |
| phoneCountryCode | Yes | String | International call prefix (00) and country/region code of purePhoneNumber. |
If the API fails to be called, the response body is as follows.
| Parameter | Type | Description |
|---|---|---|
| resultCode | int | Error code. For details, please refer to HTTP Response Codes. |
| resultDesc | String | Error description. |
HTTP/1.1 200 OK
Content-Type: application/json
{
"openId": "AQAxrBzThFv*****lv9tV_4rMCc",
"unionId": "AQAxrB1HNA*****n-IfWRSUVq2M7xU",
// Mobile number bound to the HUAWEI ID, which is used for one-tap sign-in. (The returned data is in plaintext.)
"phoneNumber": "0086191******08",
// Real-time validity of the mobile number bound to the HUAWEI ID. The mobile number is obtained through the one-tap sign-in function. Value 0 indicates that the validity needs to be further verified, and value 1 indicates that the mobile number can be directly used.
"phoneNumberValid": 1,
// Mobile number without the international call prefix and country/region code. (The returned data is in plaintext.)
"purePhoneNumber": "191******08",
"phoneCountryCode": "0086"
} HTTP/1.1 200 OK
Content-Type: application/json
{
"resultCode": 60180008,
"resultDesc": "user or phone number not exist"
} The Java sample code is as follows. Before running it, set up the environment for the sample code. (Place this sample code and the CallUtils utility class in the same directory. If not, manually add the corresponding import statement to the sample code.)
import com.alibaba.fastjson2.JSONObject;
import org.apache.http.client.methods.HttpPost;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Obtain the OpenID/UnionID and mobile number bound to a HUAWEI ID with one-tap sign-in.
*/
public class GetQuickLoginMobilePhoneByCodeDemo {
public static void main(String[] args) throws IOException {
// URL of the API for obtaining the OpenID/UnionID and mobile number bound to a HUAWEI ID with one-tap sign-in.
String url = "https://account-api.cloud.huawei.com/oauth2/v6/quickLogin/getPhoneNumber";
// Replace it with the authorization code obtained in the one-tap sign-in scenario.
String authorizationCode = "<Authorization Code>";
// Replace it with the client ID used for obtaining the authorization code in the one-tap sign-in scenario.
String clientId = "<Client ID>";
// Replace it with the client secret corresponding to the client ID of your app.
String clientSecret = "<Client Secret>";
JSONObject result = getQuickLoginMobile(url, authorizationCode, clientId, clientSecret);
// Parse the result to obtain openId.
String openId = result.getString("openId");
// Parse the result to obtain unionId.
String unionId = result.getString("unionId");
// Parse the result to obtain phoneNumber.
String phoneNumber = result.getString("phoneNumber");
// Parse the result to obtain phoneNumberValid.
Integer phoneNumberValid = result.getInteger("phoneNumberValid");
// Parse the result to obtain purePhoneNumber.
String purePhoneNumber = result.getString("purePhoneNumber");
// Parse the result to obtain phoneCountryCode.
String phoneCountryCode = result.getString("phoneCountryCode");
}
private static JSONObject getQuickLoginMobile(
String url, String authorizationCode, String clientId, String clientSecret) throws IOException {
HttpPost httpPost = new HttpPost(url);
Map<String, Object> reqBody = new HashMap<>();
reqBody.put("code", authorizationCode);
reqBody.put("clientId", clientId);
reqBody.put("clientSecret", clientSecret);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(CallUtils.wrapJsonEntity(reqBody));
// For custom exception handling, use the CallUtils#remoteCall(HttpUriRequest, BiFunction<CloseableHttpResponse,String,E>) API.
return CallUtils.toJsonObject(CallUtils.remoteCallAccountApi(httpPost));
}
} | HTTP Response Code | Description | Solution |
|---|---|---|
| 200 | The API call is successful. The actual service processing result is indicated by resultCode in the response body. | - |
| 400 | Parameter error. | Ensure that the request parameters comply with the specifications. |
| 403 | No access permission. | Check the network environment configuration to see if the access is blocked by the caller's network security policy. If the error persists, submit a ticket online. |
| 404 | Service not found. | Ensure that the request URI is correct. |
| 405 | Unsupported HTTP request method. | Ensure that the method for the HTTP request complies with the API specifications. |
| 500 | Internal service error. | Submit a ticket online. |
| 502 | Connection error. This typically occurs when network connectivity is unstable. | Try again later. If the error persists, submit a ticket online. |
| 503 | System rate limiting triggered. | Rate limiting has been triggered by the system. Try again later. |
| 504 | Connection timed out. This typically occurs when network connectivity is unstable. | Try again later. If the error persists, submit a ticket online. |
| 590 | Internal service error. | Submit a ticket online. |
| resultCode | Description | Solution |
|---|---|---|
| 60010002 | Invalid parameter. | Check the input parameters according to the error description and the parameter description in Request Body. |
| 60010012 | The value of the code parameter is incorrect. | The value of the code parameter is incorrect. The possible cause is that the value of code is invalid or is tampered with. |
| 60010013 | The value of the clientSecret parameter is incorrect. | The value of clientSecret is incorrect. For details about the value, please refer to the Client secret field under OAuth 2.0 client ID in Viewing App Basic Information. |
| 60180003 | The client ID obtained by parsing code is different from the value of the input parameter clientId. | The value of clientId in code is different from that of the input parameter clientId. Ensure that the value of the input parameter clientId is the same as the configured value, as described in Configuring the Client ID. |
| 60180004 | The authorization code has expired. It is valid for only 5 minutes and becomes unusable thereafter. | Guide the user to re-authorize the app to obtain a new authorization code, and retry the operation. |
| 60180005 | The authorization code has been used. | The authorization code can be used only once. Obtain a new authorization code and try again. |
| 60180006 | The authorization code is invalidated. Although its normal validity period is 5 minutes, it may be revoked prematurely by the Huawei server due to user operations such as password change or app authorization revocation. | Guide the user to re-authorize the app to obtain a new authorization code, and retry the operation. |
| 60180007 | The authorization code does not include the scope for one-tap HUAWEI ID sign-in. | The possible causes are as follows: - When developing the one-tap HUAWEI ID sign-in function on the app side, LoginWithHuaweiIDButtonParams.loginType is not set to LoginType.QUICK_LOGIN. - The authorization code sent by the app to the server is the one obtained during the number pre-fetching phase of one-tap HUAWEI ID sign-in. - The authorization code sent by the app to the server is not obtained in the one-tap HUAWEI ID sign-in scenario. For details about how to address the above possible causes, please refer to 60180007 What Should I Do If the Server Cannot Obtain the One-tap Sign-in Mobile Number of a HUAWEI ID Through the Authorization Code? |
| 60180008 | No mobile number bound. | Check whether a mobile number is bound to the user's HUAWEI ID. If not, show the sign-in screen that contains other sign-in options. |
| 60180009 | The mobile number cannot be obtained. | The one-tap HUAWEI ID sign-in service is available only to users in the Chinese mainland. |
| 60010001 | Internal system error. | Try again later. If the error persists, submit a ticket online. |