All Products
Search
Document Center

SuperApp:wv.getAuthCode

Last Updated:Jun 11, 2025

Obtains an authorization code to access user information.

Overview

wv.getAuthCode guides a user to grant permissions on user information to the current miniapp in a tooltip. We recommend that you call wv.getAuthCode after the user fully understands the business content of the miniapp. We recommend that you do not call wv.getAuthCode on the home screen of the miniapp to ensure user experience.

The authorization code obtained by calling wv.getAuthCode must be used by the miniapp server to exchange for actual user information such as the user ID, avatar, nickname, mobile phone number, region, gender, and date of birth.

Request parameters

The request parameters are of the Object type. The following table describes the parameters.

Parameter

Type

Required

Description

scopes

Array

No

The scope of authorization. The auth_base and auth_user fields are supported. For more information, see the "scopes description" section of this topic. Default value: auth_base.

success

Function

No

The callback function for a successful call.

fail

Function

No

The callback function for a failed call.

scopes description

A scope indicates the scope of permissions that a developer needs to request from a user.

scopes

Description

What to do next

USER_ID

The developer is authorized to obtain the unique identifier (user_id) of the app user. No tooltip is displayed during the authorization process.

Pass the authorization code obtained by the miniapp to the server to obtain the user ID.

USER_NICKNAME

The developer is authorized to obtain the nickname of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_NAME

The developer is authorized to obtain the name of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_LOGIN_ID

The developer is authorized to obtain the logon ID of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

HASH_LOGIN_ID

The developer is authorized to obtain the hash value of the logon ID of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_AVATAR

The developer is authorized to obtain the avatar of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_GENDER

The developer is authorized to obtain the gender of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_BIRTHDAY

The developer is authorized to obtain the date of birth of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_NATIONALITY

The developer is authorized to obtain the nationality of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

USER_CONTACTINFO

The developer is authorized to obtain the contact information of the app user.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

auth_base

The developer is authorized to obtain the ID of the app user. No tooltip is displayed during the authorization process.

Pass the authorization code obtained by the miniapp to the server to obtain the user ID.

auth_user

The developer is authorized to obtain the account information of the app.

Pass the authorization code obtained by the miniapp to the server to obtain the authorized user information.

Response parameters

The success callback function receives an object that has the following properties.

Property

Type

Description

authCode

String

The authorization code.

authErrorScopes

Object

The scope of a failed authorization. The key is the scope of the failed authorization, and the value is the corresponding error code.

authSuccessScopes

Array

The scope of a successful authorization.

Note

A new authorization code is generated for each user authorization.

The fail callback function receives an object of the Object type, in which the error field indicates the error code and the errorMessage field indicates the error message.

Error code

Error message

Solution

11

User cancels authorization

Explain the purpose and necessity of obtaining user information, and guide the operation again.

12

Network Error

Authorization-related network requests failed or timed out. Try again later.

13

No authorization result found

The specified scopes parameter is invalid. Check the scopes parameter.

Sample code

window.WindVane.call('wv', 'getAuthCode', {scopes: ['auth_user']}, function(res) {
		authCode = res.authCode;
}, function(e) {
    alert('failure:' + JSON.stringify(e));
});