From 755c612fd8e3d7989ad41371c14413187fdd66b1 Mon Sep 17 00:00:00 2001 From: Antonio Davi Macedo Coelho de Castro Date: Thu, 15 Oct 2020 15:24:36 -0700 Subject: [PATCH] Update vkontakte API to the latest version (#6944) * Update vkontakte API to the latest version * Allow developers to set the api version (optional) --- spec/AuthenticationAdapters.spec.js | 6 +++++- src/Adapters/Auth/vkontakte.js | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/AuthenticationAdapters.spec.js b/spec/AuthenticationAdapters.spec.js index a6b31086..a3f3ab5e 100644 --- a/spec/AuthenticationAdapters.spec.js +++ b/spec/AuthenticationAdapters.spec.js @@ -74,7 +74,9 @@ describe('AuthenticationProviders', function () { options => { if ( 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 { access_token: 'access_token', @@ -96,6 +98,8 @@ describe('AuthenticationProviders', function () { appIds: 'appId', appSecret: 'appSecret', }; + await provider.validateAuthData({ id: 'userId' }, params); + params.appVersion = '5.123'; } await provider.validateAuthData({ id: 'userId' }, params); }); diff --git a/src/Adapters/Auth/vkontakte.js b/src/Adapters/Auth/vkontakte.js index 9fb2935b..fe9913ab 100644 --- a/src/Adapters/Auth/vkontakte.js +++ b/src/Adapters/Auth/vkontakte.js @@ -7,12 +7,15 @@ var Parse = require('parse/node').Parse; // Returns a promise that fulfills iff this user id is valid. function validateAuthData(authData, params) { - return vkOAuth2Request(params).then(function(response) { + return vkOAuth2Request(params).then(function (response) { if (response && response.access_token) { return request( 'api.vk.com', - 'method/users.get?access_token=' + authData.access_token + '&v=5.8' - ).then(function(response) { + 'method/users.get?access_token=' + + authData.access_token + + '&v=' + + params.apiVersion + ).then(function (response) { if ( response && response.response && @@ -35,7 +38,7 @@ function validateAuthData(authData, params) { } function vkOAuth2Request(params) { - return new Promise(function(resolve) { + return new Promise(function (resolve) { if ( !params || !params.appIds || @@ -48,15 +51,20 @@ function vkOAuth2Request(params) { 'Vk auth is not configured. Missing appIds or appSecret.' ); } + if (!params.apiVersion) { + params.apiVersion = '5.124'; + } resolve(); - }).then(function() { + }).then(function () { return request( 'oauth.vk.com', 'access_token?client_id=' + params.appIds + '&client_secret=' + params.appSecret + - '&v=5.59&grant_type=client_credentials' + '&v=' + + params.apiVersion + + '&grant_type=client_credentials' ); }); }