Requests user authorization and returns an authorization code (authCode).
Overview
wv.getAuthCode displays an authorization pop-up requesting the user's permission to access their information. Call this method only after the user understands why authorization is needed. Do not call it on the miniapp's initial screen.
The returned authCode represents user consent. Your server uses this code to retrieve user information from the platform, such as user_id, avatar, nickname, mobile number, region, gender, and date of birth.
Request parameters
Pass an object with these parameters:
|
Parameter |
Type |
Required |
Description |
|
scopes |
Array |
No |
Authorization scopes. Valid values are listed in the Scopes table below. Defaults to |
|
success |
Function |
No |
Callback on success. |
|
fail |
Function |
No |
Callback on failure. |
Scopes
Each scope defines a permission your miniapp requests from the user.
|
Scope |
Description |
Server action |
|
USER_ID |
Deprecated. This scope is an alias for |
See |
|
USER_NICKNAME |
Grants access to the user's nickname. |
Pass the |
|
USER_NAME |
Grants access to the user's name. |
Pass the |
|
USER_LOGIN_ID |
Grants access to the user's login ID. |
Pass the |
|
HASH_LOGIN_ID |
Grants access to the hashed login ID. |
Pass the |
|
USER_AVATAR |
Grants access to the user's avatar. |
Pass the |
|
USER_GENDER |
Grants access to the user's gender. |
Pass the |
|
USER_BIRTHDAY |
Grants access to the user's date of birth. |
Pass the |
|
USER_NATIONALITY |
Grants access to the user's nationality. |
Pass the |
|
USER_CONTACTINFO |
Grants access to the user's contact information. |
Pass the |
|
auth_base |
Grants access to the user's unique identifier ( |
Pass the |
|
auth_user |
Grants access to the user's account information. |
Pass the |
Response parameters
The success callback receives an object with these properties:
|
Property |
Type |
Description |
|
authCode |
String |
The authorization code. |
|
authErrorScopes |
Object |
Maps failed scopes to their error codes. |
|
authSuccessScopes |
Array |
Successfully authorized scopes. |
A new authCode is generated each time the user grants authorization.
The fail callback receives an object with error (error code) and errorMessage (error message) properties.
|
Error code |
Error message |
Solution |
|
11 |
User canceled authorization |
Explain why authorization is needed and prompt the user to retry. |
|
12 |
Network error |
The authorization request failed or timed out. Try again later. |
|
13 |
No authorization result found |
Invalid value in |
Sample code
window.WindVane.call('wv', 'getAuthCode', {scopes: ['auth_user']}, function(res) {
authCode = res.authCode;
}, function(e) {
alert('failure:' + JSON.stringify(e));
});