File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments