Skip to content
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