getOauthV1Code
Description
Call the function to obtain authorization code. The authorization code can be used to obtain the access token, so as to obtain app user's information, such as avatar, name. For more information, refer to User Authorization
Sample Code
Sample Request:
window.zlpSdk.User.getOauthV1Code({
appId: 1878,
codeChallenge": "NmNlZTBiNDg3MDU3ZGIyNmIxYTQ5YWFlMmI1NmE4MWVlZWZjYTg2OWM2YWMzOTdmNmRmM2M3YjRiMjNlZWMzNg",
}).then((response) => console.log(response))
.catch((error) => console.error(error));
Sample Response:
{
"data": {
"code": "LUUHyD5CtqxwjtDCu8NiqFt169Ql7MBdEOVDdaqB097jk670Yj1JoGBLg5W4KbW7",
"redirectUri": "https://merchant.com/callback?code=LUUHyD5CtqxwjtDCu8NiqFt169Ql7MBdEOVDdaqB097jk670Yj1JoGBLg5W4KbW7&state="
},
"status": "success"
}
Parameters
Param | Data type | Required | Description |
---|---|---|---|
appId | number | Yes | App ID is issued when registering merchant, Zalopay team will provide this info. |
codeChallenge | string | Yes | This is a cryptographically random string using the characters A-Z, a-z, 0-9, and the punctuation characters -._~ codeChallenge = Base64.UrlEncode(SHA-256.hash(codeVerifier)) |
Return Value
Param | Data type | Description |
---|---|---|
code | string | Authorization code |
redirectUri | string | The url with appended authorization code to the callback url as a query param. This callback url is configured when registering merchant Example: https://merchant.com/callback?code=bmBwKZQ9uXivu3UjvCXllpBt5JPRNCF0U2P |
Error Code
Error Code | Description |
---|---|
030501 | User Canceled |
030502 | Invalid Argument |
030503 | System Error |
030504 | Unauthenticated |
030505 | Get permissions error |
Generate code challenge
To generate code challange first we need to create a code verifier, then use the code verifier to generate code challange
- Generate code verifier: Call zlpSdk.User.generateCodeVerifier to generate a codeVerifier
- Store this codeVerifier to use in Obtain access token step
- Generate code challange: Call zlpSdk.User.generateCodeChallenge function with the codeVerifier from previous step to generate a codeChallenge