Authorization methods
Method | Availability | Description |
wv.authorize | Globally supported |
|
wv.getAuthCode | Globally supported |
|
wv.authorize: User device information
Prerequisites
When initializing the SDK, the app developer must set needAuthFromApp to true in the EMASMiniAppInitConfig or MiniAppInitConfig class.
Before you begin
When a miniapp calls an API that requires device information, such as
WVLocation.getLocationorWVVideo.chooseVideo, the host app must display an authorization prompt for the user to grant permission. Miniapp developers can call wv.getSetting to check the miniapp's current authorization status.To use APIs that require authorization, the user must grant permission at two levels: to the miniapp within the host app, and to the host app at the operating system level.
These two authorization levels are independent. If a user has granted the miniapp permission but the host app has not obtained the corresponding system permission, the container automatically triggers a system prompt when the API is called. The miniapp can also call the WVUIDialog.showAuthGuide API to guide the user to the system settings page to grant the permission to the host app.
Miniapp authorization logic
If the user has not yet authorized the miniapp, you must first call wv.authorize before calling an API that requires permission. The host app will then display an authorization prompt to the user:
If the user agrees, the miniapp can then call the device information API. Subsequent calls will not trigger another authorization prompt.
If the user refuses, the
failcallback is triggered immediately, indicating that the authorization was denied. Subsequent calls to the API will display the authorization prompt again.
Miniapp developers should first call wv.getSetting to check the user authorization status before calling an API that requires it. If the permission has not been granted, call wv.authorize to request it, and then call the target API.
System-level permission logic
If a required permission is disabled in the operating system or has not been granted to the host app, the API call will fail even if the user has granted permission to the miniapp. Typically, the first time the miniapp calls the API, the host app also requests the permission from the system, displaying a prompt. If the user denies the request and selects 'Don’t ask again', subsequent calls may trigger the fail callback directly. In this case, miniapp developers can call WVUIDialog.showAuthGuide to open the system's permission settings page and guide the user to enable the permission manually.
wv.getAuthCode: User personal information
The wv.getAuthCode API prompts users to grant the current miniapp access to their personal information, such as their name and contact information, by displaying a floating authorization prompt. We recommend that you call wv.getAuthCode only after users fully understand the services of your miniapp. Avoid calling wv.getAuthCode on the home screen of the miniapp because this can degrade the user experience.
The miniapp's backend server must use the authorization code (authCode) returned by wv.getAuthCode. The server can then exchange this code with the platform to obtain user personal information, such as user ID, avatar, nickname, phone number, region, gender, and date of birth.
The Alibaba Cloud SuperApp Application Open Platform provides the standard API definition for wv.getAuthCode. However, because the platform does not have access to the user information of client SuperApps, the SuperApp developer is responsible for implementing this API. For a reference implementation, see Best practices for implementing SuperApp technical standards.
Scope control
A scope defines the range of permissions a developer requests from a user.
Declare the required scopes for permission control.
For scopes related to sensitive information, a user action must initiate the authorization request; it cannot be triggered automatically in the background.
Scope | Corresponding API | Description | Authorization API |
USER_ID | - | Grants permission to obtain the user's unique identifier (user_id). This is a silent authorization, which does not display a dialog. | Authorization API: wv.getAuthCode |
USER_NICKNAME | - | Grants permission to obtain the app user's nickname. | |
USER_NAME | - | Grants permission to obtain the app user's name. | |
USER_LOGIN_ID | - | Grants permission to obtain the app user's login ID. | |
HASH_LOGIN_ID | - | Grants permission to obtain the hash of the app user's login ID. | |
USER_AVATAR | - | Grants permission to obtain the app user's avatar. | |
USER_GENDER | - | Grants permission to obtain the app user's gender. | |
USER_BIRTHDAY | - | Grants permission to obtain the app user's date of birth. | |
USER_NATIONALITY | - | Grants permission to obtain the app user's nationality. | |
USER_CONTACTINFO | - | Grants permission to obtain the app user's contact information. | |
auth_base | - | Grants permission to obtain the user's unique identifier (user_id). This is a silent authorization, which does not display a dialog. | |
auth_user | - | Grants permission to obtain the app account information. | |
location | Geolocation authorization | Authorization API: wv.authorize | |
camera | Camera authorization | ||
Bluetooth | All WVBluetooth methods | Bluetooth authorization | |
album | Album authorization | ||
contacts | All WVContacts methods | Contacts authorization | |
microphone | Microphone authorization | ||
file | File authorization | ||
call | Call authorization | ||
vibration | Vibration authorization | ||
screen capture | Screen capture authorization |