Skip to content

Commit 84f52cb

Browse files
committed
vk.com auth data manager implemented
1 parent 5ca4844 commit 84f52cb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/authDataManager/vkontakte.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
// Helper functions for accessing the instagram API.
4+
var https = require('https');
5+
var Parse = require('parse/node').Parse;
6+
7+
// Returns a promise that fulfills iff this user id is valid.
8+
function validateAuthData(authData) {
9+
return request("users.get?v=V&access_token=" + authData.access_token).then(function (response) {
10+
if (response && response.response && response.response[0].uid == authData.id) {
11+
return;
12+
}
13+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk auth is invalid for this user.');
14+
});
15+
}
16+
17+
// Returns a promise that fulfills iff this app id is valid.
18+
function validateAppId() {
19+
return Promise.resolve();
20+
}
21+
22+
// A promisey wrapper for api requests
23+
function request(path) {
24+
return new Promise(function (resolve, reject) {
25+
https.get("https://api.vk.com/method/" + path, function (res) {
26+
var data = '';
27+
res.on('data', function (chunk) {
28+
data += chunk;
29+
});
30+
res.on('end', function () {
31+
data = JSON.parse(data);
32+
resolve(data);
33+
});
34+
}).on('error', function (e) {
35+
reject('Failed to validate this access token with Vk.');
36+
});
37+
});
38+
}
39+
40+
module.exports = {
41+
validateAppId: validateAppId,
42+
validateAuthData: validateAuthData
43+
};

0 commit comments

Comments
 (0)