Skip to content

Commit 755c612

Browse files
authored
Update vkontakte API to the latest version (#6944)
* Update vkontakte API to the latest version * Allow developers to set the api version (optional)
1 parent a9ce02e commit 755c612

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

spec/AuthenticationAdapters.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ describe('AuthenticationProviders', function () {
7474
options => {
7575
if (
7676
options ===
77-
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.59&grant_type=client_credentials'
77+
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.123&grant_type=client_credentials' ||
78+
options ===
79+
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.124&grant_type=client_credentials'
7880
) {
7981
return {
8082
access_token: 'access_token',
@@ -96,6 +98,8 @@ describe('AuthenticationProviders', function () {
9698
appIds: 'appId',
9799
appSecret: 'appSecret',
98100
};
101+
await provider.validateAuthData({ id: 'userId' }, params);
102+
params.appVersion = '5.123';
99103
}
100104
await provider.validateAuthData({ id: 'userId' }, params);
101105
});

src/Adapters/Auth/vkontakte.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ var Parse = require('parse/node').Parse;
77

88
// Returns a promise that fulfills iff this user id is valid.
99
function validateAuthData(authData, params) {
10-
return vkOAuth2Request(params).then(function(response) {
10+
return vkOAuth2Request(params).then(function (response) {
1111
if (response && response.access_token) {
1212
return request(
1313
'api.vk.com',
14-
'method/users.get?access_token=' + authData.access_token + '&v=5.8'
15-
).then(function(response) {
14+
'method/users.get?access_token=' +
15+
authData.access_token +
16+
'&v=' +
17+
params.apiVersion
18+
).then(function (response) {
1619
if (
1720
response &&
1821
response.response &&
@@ -35,7 +38,7 @@ function validateAuthData(authData, params) {
3538
}
3639

3740
function vkOAuth2Request(params) {
38-
return new Promise(function(resolve) {
41+
return new Promise(function (resolve) {
3942
if (
4043
!params ||
4144
!params.appIds ||
@@ -48,15 +51,20 @@ function vkOAuth2Request(params) {
4851
'Vk auth is not configured. Missing appIds or appSecret.'
4952
);
5053
}
54+
if (!params.apiVersion) {
55+
params.apiVersion = '5.124';
56+
}
5157
resolve();
52-
}).then(function() {
58+
}).then(function () {
5359
return request(
5460
'oauth.vk.com',
5561
'access_token?client_id=' +
5662
params.appIds +
5763
'&client_secret=' +
5864
params.appSecret +
59-
'&v=5.59&grant_type=client_credentials'
65+
'&v=' +
66+
params.apiVersion +
67+
'&grant_type=client_credentials'
6068
);
6169
});
6270
}

0 commit comments

Comments
 (0)