Skip to content

fix: Auth adapter VKontakte not working with new API #8640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 13 additions & 46 deletions src/Adapters/Auth/vkontakte.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,23 @@ 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) {
if (response && response.access_token) {
return request(
'api.vk.com',
'method/users.get?access_token=' + authData.access_token + '&v=' + params.apiVersion
).then(function (response) {
if (
response &&
response.response &&
response.response.length &&
response.response[0].id == authData.id
) {
return;
}
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk auth is invalid for this user.');
});
}
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk appIds or appSecret is incorrect.');
});
}
if (!params.apiVersion) {
params.apiVersion = '5.131';
}

function vkOAuth2Request(params) {
return new Promise(function (resolve) {
return request(
'api.vk.com',
'method/users.get?access_token=' + authData.access_token + '&v=' + params.apiVersion
).then(function (response) {
if (
!params ||
!params.appIds ||
!params.appIds.length ||
!params.appSecret ||
!params.appSecret.length
response &&
response.response &&
response.response.length &&
response.response[0].id == authData.id
) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Vk auth is not configured. Missing appIds or appSecret.'
);
}
if (!params.apiVersion) {
params.apiVersion = '5.124';
return;
}
resolve();
}).then(function () {
return request(
'oauth.vk.com',
'access_token?client_id=' +
params.appIds +
'&client_secret=' +
params.appSecret +
'&v=' +
params.apiVersion +
'&grant_type=client_credentials'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk auth is invalid for this user.');
});
}

Expand Down