Authorization Wake-up Method
Wake-Up Method | Composite Authorization | Comments |
wv.authorize | This function is globally supported. |
|
wv.getAuthCode | This function is globally supported. |
|
User Device Information Authorization By wv.authorize API
Preconditions
During the initialization of the miniapp container SDK, the App developer must set the needAuthFromApp property to 'true' within either the EMASMiniAppInitConfig or MiniAppInitConfig class, then the wv.authorize will take effect and the miniapp needs to call wv.authorize before calling API to get device information.
If the App developer doesn't set the needAuthFromApp property or set the needAuthFromApp property to 'false', the wv.authorize will not take effect and the miniapp can directly call API to get device information without user authorization.
Preparations
When a miniapp invokes get-device-information-related APIs (such as WVLocation.getLocation, WVVideo.chooseVideo), the App must display an authorization prompt dialog requiring the user to decide whether to grant authorization to the current miniapp. miniapp developers can invoke wv.getSetting to check the current authorization status of the miniapp.
When using APIs that require authorization, users must complete authorization at two distinct levels:
Authorize the miniapp within the App;
Enable the corresponding permission at the system level and authorize it to the App;
The two levels of authorization status are independent of each other. If the miniapp has already obtained user authorization for accessing specific device information(such as location scope) , but the App itself hasn't acquired the corresponding system permissions, when the miniapp calls the corresponding JSAPI (such as WVLocation.getLocation), the miniapp container will automatically trigger a system dialog asking the user to confirm whether to grant permissions to the App. The miniapp can also use the WVUIDialog.showAuthGuide API to guide users to the system settings page to enable system permissions for the App.
Miniapp authorization related logic
When the miniapp has not been authorized by the user, calling a permission-requiring JSAPI requires first invoking wv.authorize. The App will then display an authorization prompt to the user:
If the user consents, the miniapp can proceed to invoke the device-information-related API to execute its functionality, and subsequent calls to this API will no longer trigger an authorization dialog;
If the user declines, the fail callback will be triggered immediately to indicate the authorization cancellation, and subsequent API calls will still prompt the user with an authorization dialog;
For APIs that require authorization and have not been authorized by the user for the miniapp, it is suggested to first use the wv.getting method to check, then call the wv.authorize method, and finally, call the API that requires authorization.
System-level permissions related logic
If a specific permission required by an API has not been enabled by the user in the system or granted to the app, even if the user consents to authorize this permission to the current miniapp, the API call will still fail. Typically, the miniapp's first call to this API will also trigger the App to request permission from the system, prompting the user with an authorization prompt or guidance screen. If the user rejects the request and selects 'Don’t ask again', the fail callback may be directly triggered. In this case, developers can invoke WVUIDialog.showAuthGuide to launch the system permission settings page and guide the user to manually enable the required permission for this App.
User Personal Information Authorization By wv.getAuthCode API
The wv.getAuthCode API guides users to authorize their personal information (e.g., name, contact information) to the current miniapp and displays an authorization dialog. It is recommended to invoke wv.getAuthCode API only after users have fully understood the miniapp's business content, avoiding its use on the miniapp's initial screen to prevent negatively impacting the user experience.
The authorization code (authCode) obtained via wv.getAuthCode API is subsequently used by the miniapp backend to exchange for actual user personal data (e.g., userId, avatar, nickname, phone number, nationality, gender, date of birth) from the SuperApp backend.
The Alibaba Cloud SuperApp Application Open Platform provides the API standard definition for wv.getAuthCode . However, since the open platform does not store user information of client SuperApps, the implementation of this API must be completed by the SuperApp developers. For reference, see: Best practices for implementing Superapp technical standards.
Scope-based permission control
A scope represents the permission range that miniapp must request from the user.
A scope indicates the scope of permissions that a developer must obtain from a user.
Scopes under permission management and control need to be explicitly defined.
Scopes related to sensitive information require authorization to be initiated by users.
Scope | API | Description | Triggering method |
USER_ID | - | The developer is authorized to obtain the ID of the app user. No pop-up window is displayed during the authorization process. | Authorization API: wv.getAuthCode |
USER_NICKNAME | - | The developer is authorized to obtain the nickname of the app user. | |
USER_NAME | - | The developer is authorized to obtain the name of the app user. | |
USER_LOGIN_ID | - | The developer is authorized to obtain the logon ID of the app user. | |
HASH_LOGIN_ID | - | The developer is authorized to obtain the hash value of the logon ID of the app user. | |
USER_AVATAR | - | The developer is authorized to obtain the avatar of the app user. | |
USER_GENDER | - | The developer is authorized to obtain the gender of the app user. | |
USER_BIRTHDAY | - | The developer is authorized to obtain the date of birth of the app user. | |
USER_NATIONALITY | - | The developer is authorized to obtain the nationality of the app user. | |
USER_CONTACTINFO | - | The developer is authorized to obtain the contact information of the app user. | |
auth_base | - | The developer is authorized to obtain the ID of the app user. No pop-up window is displayed during the authorization process. | |
auth_user | - | The developer is authorized to obtain the account information about the app. | |
location | Geolocation authorization | Authorization API: wv.authorize | |
camera | Camera authorization | ||
bluetooth | WVBluetooth all methods | Bluetooth authorization | |
album | Album authorization | ||
contacts | WVContacts all methods | Contacts authorization | |
microphone | Micrphone authorization | ||
file | WVFile all methods | File authorization | |
call | Call authorization | ||
vibrate | Vibrate authorization | ||
screen | Scren authorization |