Skip to main content

getOauthV1Code

Note
Please contact ZaloPay Team to be granted permission to use this functionality.

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

ParamData typeRequiredDescription
appIdnumberYesApp ID is issued when registering merchant, Zalopay team will provide this info.
codeChallengestringYesThis 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))
Note
To silently obtain user id(muid) only without asking user consent, please request Zalopay team configure scope to empty. All other scopes require user consent

Return Value

ParamData typeDescription
codestringAuthorization code
redirectUristringThe 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 CodeDescription
030501User Canceled
030502Invalid Argument
030503System Error
030504Unauthenticated
030505Get 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

  1. Generate code verifier: Call zlpSdk.User.generateCodeVerifier to generate a codeVerifier
  1. Generate code challange: Call zlpSdk.User.generateCodeChallenge function with the codeVerifier from previous step to generate a codeChallenge