sud.login
Starts the OpenPaaS login and returns a single-use temporary login credential code. User authentication is completed by the OpenPaaS runtime; the game does not handle account credentials.
Parameters
Object object
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| success | function | No | Callback for a successful login | |
| fail | function | No | Callback for a failed login | |
| complete | function | No | Callback invoked when the call ends, after either success or failure |
Callback Parameters
success
| Property | Type | Description |
|---|---|---|
| code | string | Single-use temporary login credential issued by OpenPaaS |
fail
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
complete carries no arguments. It is invoked after success or fail, and runs only once per request.
Notes
codecan be used only once. Pass it unchanged to Game SVR, which calls auth.code2session to exchange it forsession_key,openid, andunionid.codeis not a session. Do not reuse it or keep it on the client for long. Game SVR should issue its own session after exchanging the code.auth.code2sessionmust be called from the server. The request carriesgame_idandsecret, which must never appear in client code.session_keymay only be stored on Game SVR. Never deliver it to the client, place it in configuration readable by the front end, or write it to logs. It is the key used to decrypt and verify sensitive user data returned by sud.getUserProfile.
Example Code
javascript
sud.login({
success: (res) => {
// code can be used only once; submit it to Game SVR immediately
console.log('Login succeeded, code obtained', res.code);
},
fail: (err) => {
console.error('Login failed', err.errCode, err.errMsg);
},
complete: () => {
console.log('Login call finished');
},
});