Skip to content

Login Credential Verification ​

This interface should be called on the server side. It must never be called directly from the front end (APP client, web page, minigame, etc.) to avoid the risk of credential leakage.

Interface Description ​

Interface Name auth.code2session

Description Login credential verification (code2session). The minigame server uses the code obtained at login to exchange it for user session information.

Note: This interface is called directly as a standard HTTPS request and does not support service communication secondary encryption and signatures. Pass game_id, secret, code and other parameters as plaintext query parameters; the response is plaintext JSON. No encrypted payload, signature headers, or response decryption are needed.

Call Method ​

HTTPS Call ​

http
GET /v1/auth/code2session

Prepend the base URL for your game's service region to the API path. See Service Regions and API Addresses.

Request Parameters - Query ​

FieldTypeDefaultRequiredDescription
game_idstringYesGame ID
secretstringYesGame secret
codestringYesThe code obtained at login
grant_typestringYesGrant type, fixed as authorization_code

Response ​

The returned JSON data package

FieldTypeDescription
errcodeint32Error code
errmsgstringError message
session_keystringSession key
openidstringUnique user identifier
unionidstringUnique user identifier within the game group
legacy_user_identitystringLegacy user identity information
channel_idint32Channel ID: 0-Other, 1-OPPO, 2-HONOR, 3-XIAOMI

Example ​

Request Example ​

http
GET /v1/auth/code2session?game_id=xxx&secret=xxx&code=xxx&grant_type=authorization_code

Response Example ​

json
{
  "errcode": 0,
  "errmsg": "ok",
  "session_key": "Wh/vJSqjuUvFiX7Zaecgrw==",
  "openid": "176587c7ae606feb7d837852b17e7d76",
  "unionid": "9e8d7a9f9c0d581b57f131583e1702b8",
  "legacy_user_identity": "xxx",
  "channel_id": 1
}