User authorization
With this solution, merchants can learn how to obtain users' authorization to access user information on mini programs. For more information about mini programs, see About Mini Programs.
User authorization is based on the industry-standard OAuth2.0 authorization mechanism. When users open and use a mini program, the mini program needs to get the users' consent so that users allow mini programs to obtain basic user information such as avatar, nickname, gender, region, etc, that are store in the native app.
Note: This solution is aimed at mini programs that are released to Alipay+ partner apps. If you release your mini program to Alipay China, refer to the Alipay China user authorization solution.
How it works
The authorization happens between the mini program, the native app and the user. In order for merchants to learn more details when a mini program is developed on the Alipay+ Mini Program Platform and launched to Alipay+ partner app, the following diagram illustrates the end-to-end process on how it works:

- The merchant signs a contract with Alipay+ Mini Program Platform (AIMPDP).
- The merchant uses the Alipay+ Mini Program Platform to develop and manage mini programs.
- After the mini program is ready to be released, the merchant launches the mini program to a native app, for example, an Alipay+ partner app, or another wallet app.
- When users open the merchant's mini program that run on the native app, the mini program needs to first obtain user authorization in order to get the basic information that have been authorized in the native app.
The following documents will explain more about the authorization from a developer's point of view.
Basic concepts
Check the basic concepts below. The following terms and descriptions will help you understand more about user authorization:
Name | Description |
Scope of authorization (scope) | A scope represents the scope of permissions that developers need to request user authorization. A scope contains at least one open API interface or JSAPI interface. One authorization can combine multiple scopes for combined authorization. |
Authorization code (auth_code) | Temporary user authorization credentials. After obtaining it, promptly call the |
Access token or authorization token (access_token or auth_token) | Long-term authorization credentials. It is used to call the Mini Program Platform gateway for server-side authorization interface calls. Pay attention to the scope and validity of the authorization token. |
Guidelines
When obtaining user authorization, stick to the following guidelines:
- Do not guide users to grant authorization at the launch of the mini program. Users have the right to fully understand the mini program and its operations before giving any authorization.
- Fully respect the privacy of users and handle user authorization properly. If a mini program is found to handle user authorization unreasonably or beyond the agreed scope, the Mini Program Platform has the right to permanently withdraw this authority of the mini program.
How to obtain user authorization
To achieve the authorization capability, follow the steps below:
Before you start
- Make sure you have finished all the following steps:
- Apply for an account.
- Log in to the Alipay Global Merchant portal and click Manage to navigate to the Alipay+ Mini Program Platform to manage mini programs. For more information, see Alipay+ merchant onboarding.
- Create a mini program. Open your mini program and get the
appId. - Contact Alipay technical support to provide us the
appId.
- What Alipay technical support will provide is listed below:
- MID (merchant ID)
- ClientId (client ID)
- Then we will guide you through the configuration of public key and private key. For more information, see OpenAPIs Overview and Call an API via adding a signature. The process is as follows:
- You exchange your public key for our public key.
- We provide endpoints for you to call OpenAPIs.
Step 1: Obtain authCode from the wallet app
The flow illustrates how a merchant's mini program obtains the authCode from the wallet app (also known as super app) or Alipay+ partner app:

Detailed flow is as follows:
- A user opens the merchant's mini program. The mini program invokes the
my.getAuthCode(scopes)to send an authorization request to the wallet app [1.1]. - The wallet app processes the request and then pops up the authorization page [1.1.1].
- After the user agrees to the authorization, the mini program gets the
authCode[2.1]. - Then the mini program calls
my.getAppIdSyncand getsappIdfrom the wallet app [2.1.2]. - The mini program calls
my.getSiteInfoand getscustomerBelongsTofrom the wallet app [2.1.4].
You can obtain user authorization by calling the my.getAuthCode JSAPI and fetch the authCode in the success callback. To learn more, see my.getAuthCode.
Note: The
authCode,appId, andcustomerBelongsToare required to getaccessTokenin Step 2.
Step 2: Obtain accessToken
With the obtained authCode, appId, and customerBelongsTo, you can exchange accessToken and userId.
For more information, check the flow below. It illustrates the sequence of obtaining accessToken from the AIMPDP (Alipay International Mini Program Development Platform):

Detailed flow is as follows:
- The merchant's mini program obtains the
accessTokenfrom the merchant server. During this process,authCode,appId, andcustomerBelongsToare required [1]. - The merchant server initiates a request to obtain the access token via the
applyTokenAPI [1.1]. Before calling theapplyTokenAPI, signing the request is needed. To learn more, see Call an API via adding a signature. - Then the merchant server sends the request via
/v2/authorizations/applyTokento the AIMPDP. During this process,authCode,appId, andcustomerBelongsToare required [1.2]. - The AIMPDP processes the request and returns the
accessToken[1.3]. - The merchant server validates the signature, creates a login session, and then saves the
accessToken[1.6]. - The merchant server returns the request result to the mini program [1.7].
Note:
- For more about the
applyTokenAPI, refer to /v2/authorizations/applyToken.- During this process, the
ClientId, public key, and private key are required.
With the above steps, you have now completed the configuration of user authorization. The following sections introduce the extended steps to query user information and revoke authorization.
Step 3: Query user information (optional)
You can decide which kind of information you want to inquire about tailored to your business. User information includes userId, status, nickName, userName, avatar, gender, birthDate, loginIdInfos, contactInfos, etc.
The flow below illustrates how to query user information via accessToken:

Detailed flow is as follows:
- The merchant's mini program sends a request to query user information with
appId[1]. - The merchant server processes the request and gets the user's
accessToken[1.1]. - The merchant server initiates a request to inquire user information via the
inquiryUserInfoAPI [1.2]. Before calling theinquiryUserInfoAPI, signing the request is needed. To learn more, see Call an API via adding a signature. - Then the merchant server sends the request via
/v2/users/inquiryUserInfoto the AIMPDP [1.3]. The AIMPDP processes the request and returns the user information [1.4]. - The merchant server validates the signature and gets the user information [1.6].
- Then the merchant server sends the request result to the merchant's mini program [1.7].
Note: For more about the inquiryUserInfo API, refer to /v2/users/inquiryUserInfo.
Step 4: Revoke authorization (optional)
You can cancel the authorization by calling the revoke API. For more about this API, refer to /v2/authorizations/revoke.
The flow below illustrates how to cancel the authorization via the revoke API:

When a user cancels an access token from the mini program,
- The merchant server calls the
revokeinterface via /v2/authorizations/revoke to cancel the access token [1.1]. - The AIMPDP processes the cancellation request and returns the result to the merchant server [1.2].
- Then the merchant server transfers the result to the mini program [1.3].
API list
Refer to the following two tables for the APIs that are used in the above procedures, along with their description:
JSAPI
Interface Name | Description |
Obtains the authorization code. | |
Obtains the mini program app ID. | |
Obtains the site information. |
OpenAPI
Interface Name | Description |
Obtains the access token. | |
Gets the user-related information. | |
Cancels the access token. |