Update vkontakte API to the latest version (#6944)

* Update vkontakte API to the latest version

* Allow developers to set the api version (optional)
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2020-10-15 15:24:36 -07:00
committed by GitHub
parent a9ce02eb74
commit 755c612fd8
2 changed files with 19 additions and 7 deletions

View File

@@ -74,7 +74,9 @@ describe('AuthenticationProviders', function () {
options => { options => {
if ( if (
options === options ===
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.59&grant_type=client_credentials' 'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.123&grant_type=client_credentials' ||
options ===
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.124&grant_type=client_credentials'
) { ) {
return { return {
access_token: 'access_token', access_token: 'access_token',
@@ -96,6 +98,8 @@ describe('AuthenticationProviders', function () {
appIds: 'appId', appIds: 'appId',
appSecret: 'appSecret', appSecret: 'appSecret',
}; };
await provider.validateAuthData({ id: 'userId' }, params);
params.appVersion = '5.123';
} }
await provider.validateAuthData({ id: 'userId' }, params); await provider.validateAuthData({ id: 'userId' }, params);
}); });

View File

@@ -7,12 +7,15 @@ var Parse = require('parse/node').Parse;
// Returns a promise that fulfills iff this user id is valid. // Returns a promise that fulfills iff this user id is valid.
function validateAuthData(authData, params) { function validateAuthData(authData, params) {
return vkOAuth2Request(params).then(function(response) { return vkOAuth2Request(params).then(function (response) {
if (response && response.access_token) { if (response && response.access_token) {
return request( return request(
'api.vk.com', 'api.vk.com',
'method/users.get?access_token=' + authData.access_token + '&v=5.8' 'method/users.get?access_token=' +
).then(function(response) { authData.access_token +
'&v=' +
params.apiVersion
).then(function (response) {
if ( if (
response && response &&
response.response && response.response &&
@@ -35,7 +38,7 @@ function validateAuthData(authData, params) {
} }
function vkOAuth2Request(params) { function vkOAuth2Request(params) {
return new Promise(function(resolve) { return new Promise(function (resolve) {
if ( if (
!params || !params ||
!params.appIds || !params.appIds ||
@@ -48,15 +51,20 @@ function vkOAuth2Request(params) {
'Vk auth is not configured. Missing appIds or appSecret.' 'Vk auth is not configured. Missing appIds or appSecret.'
); );
} }
if (!params.apiVersion) {
params.apiVersion = '5.124';
}
resolve(); resolve();
}).then(function() { }).then(function () {
return request( return request(
'oauth.vk.com', 'oauth.vk.com',
'access_token?client_id=' + 'access_token?client_id=' +
params.appIds + params.appIds +
'&client_secret=' + '&client_secret=' +
params.appSecret + params.appSecret +
'&v=5.59&grant_type=client_credentials' '&v=' +
params.apiVersion +
'&grant_type=client_credentials'
); );
}); });
} }