@@ -1,6 +1,5 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
export class AuthAdapter {
|
||||
|
||||
/*
|
||||
@param appIds: the specified app ids in the configuration
|
||||
@param authData: the client provided authData
|
||||
|
||||
@@ -3,8 +3,11 @@ var https = require('https'),
|
||||
var Parse = require('parse/node').Parse;
|
||||
|
||||
var OAuth = function(options) {
|
||||
if(!options) {
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'No options passed to OAuth');
|
||||
if (!options) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
'No options passed to OAuth'
|
||||
);
|
||||
}
|
||||
this.consumer_key = options.consumer_key;
|
||||
this.consumer_secret = options.consumer_secret;
|
||||
@@ -14,23 +17,24 @@ var OAuth = function(options) {
|
||||
this.oauth_params = options.oauth_params || {};
|
||||
};
|
||||
|
||||
OAuth.prototype.send = function(method, path, params, body){
|
||||
|
||||
OAuth.prototype.send = function(method, path, params, body) {
|
||||
var request = this.buildRequest(method, path, params, body);
|
||||
// Encode the body properly, the current Parse Implementation don't do it properly
|
||||
return new Promise(function(resolve, reject) {
|
||||
var httpRequest = https.request(request, function(res) {
|
||||
var data = '';
|
||||
res.on('data', function(chunk) {
|
||||
data += chunk;
|
||||
var httpRequest = https
|
||||
.request(request, function(res) {
|
||||
var data = '';
|
||||
res.on('data', function(chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', function() {
|
||||
data = JSON.parse(data);
|
||||
resolve(data);
|
||||
});
|
||||
})
|
||||
.on('error', function() {
|
||||
reject('Failed to make an OAuth request');
|
||||
});
|
||||
res.on('end', function() {
|
||||
data = JSON.parse(data);
|
||||
resolve(data);
|
||||
});
|
||||
}).on('error', function() {
|
||||
reject('Failed to make an OAuth request');
|
||||
});
|
||||
if (request.body) {
|
||||
httpRequest.write(request.body);
|
||||
}
|
||||
@@ -39,40 +43,45 @@ OAuth.prototype.send = function(method, path, params, body){
|
||||
};
|
||||
|
||||
OAuth.prototype.buildRequest = function(method, path, params, body) {
|
||||
if (path.indexOf("/") != 0) {
|
||||
path = "/" + path;
|
||||
if (path.indexOf('/') != 0) {
|
||||
path = '/' + path;
|
||||
}
|
||||
if (params && Object.keys(params).length > 0) {
|
||||
path += "?" + OAuth.buildParameterString(params);
|
||||
path += '?' + OAuth.buildParameterString(params);
|
||||
}
|
||||
|
||||
var request = {
|
||||
host: this.host,
|
||||
path: path,
|
||||
method: method.toUpperCase()
|
||||
host: this.host,
|
||||
path: path,
|
||||
method: method.toUpperCase(),
|
||||
};
|
||||
|
||||
var oauth_params = this.oauth_params || {};
|
||||
oauth_params.oauth_consumer_key = this.consumer_key;
|
||||
if(this.auth_token){
|
||||
oauth_params["oauth_token"] = this.auth_token;
|
||||
if (this.auth_token) {
|
||||
oauth_params['oauth_token'] = this.auth_token;
|
||||
}
|
||||
|
||||
request = OAuth.signRequest(request, oauth_params, this.consumer_secret, this.auth_token_secret);
|
||||
request = OAuth.signRequest(
|
||||
request,
|
||||
oauth_params,
|
||||
this.consumer_secret,
|
||||
this.auth_token_secret
|
||||
);
|
||||
|
||||
if (body && Object.keys(body).length > 0) {
|
||||
request.body = OAuth.buildParameterString(body);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
};
|
||||
|
||||
OAuth.prototype.get = function(path, params) {
|
||||
return this.send("GET", path, params);
|
||||
}
|
||||
return this.send('GET', path, params);
|
||||
};
|
||||
|
||||
OAuth.prototype.post = function(path, params, body) {
|
||||
return this.send("POST", path, params, body);
|
||||
}
|
||||
return this.send('POST', path, params, body);
|
||||
};
|
||||
|
||||
/*
|
||||
Proper string %escape encoding
|
||||
@@ -99,8 +108,7 @@ OAuth.encode = function(str) {
|
||||
// example 3: rawurlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
|
||||
// returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
|
||||
|
||||
str = (str + '')
|
||||
.toString();
|
||||
str = (str + '').toString();
|
||||
|
||||
// Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
|
||||
// PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
|
||||
@@ -110,55 +118,72 @@ OAuth.encode = function(str) {
|
||||
.replace(/\(/g, '%28')
|
||||
.replace(/\)/g, '%29')
|
||||
.replace(/\*/g, '%2A');
|
||||
}
|
||||
};
|
||||
|
||||
OAuth.signatureMethod = "HMAC-SHA1";
|
||||
OAuth.version = "1.0";
|
||||
OAuth.signatureMethod = 'HMAC-SHA1';
|
||||
OAuth.version = '1.0';
|
||||
|
||||
/*
|
||||
Generate a nonce
|
||||
*/
|
||||
OAuth.nonce = function(){
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
OAuth.nonce = function() {
|
||||
var text = '';
|
||||
var possible =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
for(var i = 0; i < 30; i++)
|
||||
for (var i = 0; i < 30; i++)
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
OAuth.buildParameterString = function(obj){
|
||||
OAuth.buildParameterString = function(obj) {
|
||||
// Sort keys and encode values
|
||||
if (obj) {
|
||||
var keys = Object.keys(obj).sort();
|
||||
|
||||
// Map key=value, join them by &
|
||||
return keys.map(function(key){
|
||||
return key + "=" + OAuth.encode(obj[key]);
|
||||
}).join("&");
|
||||
return keys
|
||||
.map(function(key) {
|
||||
return key + '=' + OAuth.encode(obj[key]);
|
||||
})
|
||||
.join('&');
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
/*
|
||||
Build the signature string from the object
|
||||
*/
|
||||
|
||||
OAuth.buildSignatureString = function(method, url, parameters){
|
||||
return [method.toUpperCase(), OAuth.encode(url), OAuth.encode(parameters)].join("&");
|
||||
}
|
||||
OAuth.buildSignatureString = function(method, url, parameters) {
|
||||
return [
|
||||
method.toUpperCase(),
|
||||
OAuth.encode(url),
|
||||
OAuth.encode(parameters),
|
||||
].join('&');
|
||||
};
|
||||
|
||||
/*
|
||||
Retuns encoded HMAC-SHA1 from key and text
|
||||
*/
|
||||
OAuth.signature = function(text, key){
|
||||
crypto = require("crypto");
|
||||
return OAuth.encode(crypto.createHmac('sha1', key).update(text).digest('base64'));
|
||||
}
|
||||
OAuth.signature = function(text, key) {
|
||||
crypto = require('crypto');
|
||||
return OAuth.encode(
|
||||
crypto
|
||||
.createHmac('sha1', key)
|
||||
.update(text)
|
||||
.digest('base64')
|
||||
);
|
||||
};
|
||||
|
||||
OAuth.signRequest = function(request, oauth_parameters, consumer_secret, auth_token_secret){
|
||||
OAuth.signRequest = function(
|
||||
request,
|
||||
oauth_parameters,
|
||||
consumer_secret,
|
||||
auth_token_secret
|
||||
) {
|
||||
oauth_parameters = oauth_parameters || {};
|
||||
|
||||
// Set default values
|
||||
@@ -175,20 +200,20 @@ OAuth.signRequest = function(request, oauth_parameters, consumer_secret, auth_to
|
||||
oauth_parameters.oauth_version = OAuth.version;
|
||||
}
|
||||
|
||||
if(!auth_token_secret){
|
||||
auth_token_secret = "";
|
||||
if (!auth_token_secret) {
|
||||
auth_token_secret = '';
|
||||
}
|
||||
// Force GET method if unset
|
||||
if (!request.method) {
|
||||
request.method = "GET"
|
||||
request.method = 'GET';
|
||||
}
|
||||
|
||||
// Collect all the parameters in one signatureParameters object
|
||||
var signatureParams = {};
|
||||
var parametersToMerge = [request.params, request.body, oauth_parameters];
|
||||
for(var i in parametersToMerge) {
|
||||
for (var i in parametersToMerge) {
|
||||
var parameters = parametersToMerge[i];
|
||||
for(var k in parameters) {
|
||||
for (var k in parameters) {
|
||||
signatureParams[k] = parameters[k];
|
||||
}
|
||||
}
|
||||
@@ -197,32 +222,41 @@ OAuth.signRequest = function(request, oauth_parameters, consumer_secret, auth_to
|
||||
var parameterString = OAuth.buildParameterString(signatureParams);
|
||||
|
||||
// Build the signature string
|
||||
var url = "https://" + request.host + "" + request.path;
|
||||
var url = 'https://' + request.host + '' + request.path;
|
||||
|
||||
var signatureString = OAuth.buildSignatureString(request.method, url, parameterString);
|
||||
var signatureString = OAuth.buildSignatureString(
|
||||
request.method,
|
||||
url,
|
||||
parameterString
|
||||
);
|
||||
// Hash the signature string
|
||||
var signatureKey = [OAuth.encode(consumer_secret), OAuth.encode(auth_token_secret)].join("&");
|
||||
var signatureKey = [
|
||||
OAuth.encode(consumer_secret),
|
||||
OAuth.encode(auth_token_secret),
|
||||
].join('&');
|
||||
|
||||
var signature = OAuth.signature(signatureString, signatureKey);
|
||||
|
||||
// Set the signature in the params
|
||||
oauth_parameters.oauth_signature = signature;
|
||||
if(!request.headers){
|
||||
if (!request.headers) {
|
||||
request.headers = {};
|
||||
}
|
||||
|
||||
// Set the authorization header
|
||||
var authHeader = Object.keys(oauth_parameters).sort().map(function(key){
|
||||
var value = oauth_parameters[key];
|
||||
return key + '="' + value + '"';
|
||||
}).join(", ")
|
||||
var authHeader = Object.keys(oauth_parameters)
|
||||
.sort()
|
||||
.map(function(key) {
|
||||
var value = oauth_parameters[key];
|
||||
return key + '="' + value + '"';
|
||||
})
|
||||
.join(', ');
|
||||
|
||||
request.headers.Authorization = 'OAuth ' + authHeader;
|
||||
|
||||
// Set the content type header
|
||||
request.headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
return request;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = OAuth;
|
||||
|
||||
@@ -4,15 +4,17 @@ var Parse = require('parse/node').Parse;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return graphRequest('me?fields=id&access_token=' + authData.access_token)
|
||||
.then((data) => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook auth is invalid for this user.');
|
||||
});
|
||||
return graphRequest(
|
||||
'me?fields=id&access_token=' + authData.access_token
|
||||
).then(data => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -21,17 +23,18 @@ function validateAppId(appIds, authData) {
|
||||
if (!appIds.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook auth is not configured.');
|
||||
'Facebook auth is not configured.'
|
||||
);
|
||||
}
|
||||
return graphRequest('app?access_token=' + access_token)
|
||||
.then((data) => {
|
||||
if (data && appIds.indexOf(data.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook auth is invalid for this user.');
|
||||
});
|
||||
return graphRequest('app?access_token=' + access_token).then(data => {
|
||||
if (data && appIds.indexOf(data.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// A promisey wrapper for FB graph requests.
|
||||
@@ -41,5 +44,5 @@ function graphRequest(path) {
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
const crypto = require('crypto');
|
||||
const httpsRequest = require('./httpsRequest');
|
||||
const Parse = require('parse/node').Parse;
|
||||
const Parse = require('parse/node').Parse;
|
||||
|
||||
const graphRequest = (path) => {
|
||||
const graphRequest = path => {
|
||||
return httpsRequest.get(`https://graph.accountkit.com/v1.1/${path}`);
|
||||
};
|
||||
|
||||
function getRequestPath(authData, options) {
|
||||
const access_token = authData.access_token, appSecret = options && options.appSecret;
|
||||
const access_token = authData.access_token,
|
||||
appSecret = options && options.appSecret;
|
||||
if (appSecret) {
|
||||
const appsecret_proof = crypto.createHmac("sha256", appSecret).update(access_token).digest('hex');
|
||||
return `me?access_token=${access_token}&appsecret_proof=${appsecret_proof}`
|
||||
const appsecret_proof = crypto
|
||||
.createHmac('sha256', appSecret)
|
||||
.update(access_token)
|
||||
.digest('hex');
|
||||
return `me?access_token=${access_token}&appsecret_proof=${appsecret_proof}`;
|
||||
}
|
||||
return `me?access_token=${access_token}`;
|
||||
}
|
||||
@@ -20,36 +24,37 @@ function validateAppId(appIds, authData, options) {
|
||||
return Promise.reject(
|
||||
new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook app id for Account Kit is not configured.')
|
||||
)
|
||||
'Facebook app id for Account Kit is not configured.'
|
||||
)
|
||||
);
|
||||
}
|
||||
return graphRequest(getRequestPath(authData, options))
|
||||
.then(data => {
|
||||
if (data && data.application && appIds.indexOf(data.application.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook app id for Account Kit is invalid for this user.');
|
||||
})
|
||||
return graphRequest(getRequestPath(authData, options)).then(data => {
|
||||
if (data && data.application && appIds.indexOf(data.application.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook app id for Account Kit is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function validateAuthData(authData, options) {
|
||||
return graphRequest(getRequestPath(authData, options))
|
||||
.then(data => {
|
||||
if (data && data.error) {
|
||||
throw data.error;
|
||||
}
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook Account Kit auth is invalid for this user.');
|
||||
})
|
||||
return graphRequest(getRequestPath(authData, options)).then(data => {
|
||||
if (data && data.error) {
|
||||
throw data.error;
|
||||
}
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Facebook Account Kit auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId,
|
||||
validateAuthData
|
||||
validateAuthData,
|
||||
};
|
||||
|
||||
@@ -4,15 +4,15 @@ const httpsRequest = require('./httpsRequest');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return request('user', authData.access_token)
|
||||
.then((data) => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Github auth is invalid for this user.');
|
||||
});
|
||||
return request('user', authData.access_token).then(data => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Github auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -26,13 +26,13 @@ function request(path, access_token) {
|
||||
host: 'api.github.com',
|
||||
path: '/' + path,
|
||||
headers: {
|
||||
'Authorization': 'bearer ' + access_token,
|
||||
'User-Agent': 'parse-server'
|
||||
}
|
||||
Authorization: 'bearer ' + access_token,
|
||||
'User-Agent': 'parse-server',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -3,27 +3,27 @@ var Parse = require('parse/node').Parse;
|
||||
const httpsRequest = require('./httpsRequest');
|
||||
|
||||
function validateIdToken(id, token) {
|
||||
return googleRequest("tokeninfo?id_token=" + token)
|
||||
.then((response) => {
|
||||
if (response && (response.sub == id || response.user_id == id)) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Google auth is invalid for this user.');
|
||||
});
|
||||
return googleRequest('tokeninfo?id_token=' + token).then(response => {
|
||||
if (response && (response.sub == id || response.user_id == id)) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Google auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function validateAuthToken(id, token) {
|
||||
return googleRequest("tokeninfo?access_token=" + token)
|
||||
.then((response) => {
|
||||
if (response && (response.sub == id || response.user_id == id)) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Google auth is invalid for this user.');
|
||||
});
|
||||
return googleRequest('tokeninfo?access_token=' + token).then(response => {
|
||||
if (response && (response.sub == id || response.user_id == id)) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Google auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills if this user id is valid.
|
||||
@@ -31,13 +31,16 @@ function validateAuthData(authData) {
|
||||
if (authData.id_token) {
|
||||
return validateIdToken(authData.id, authData.id_token);
|
||||
} else {
|
||||
return validateAuthToken(authData.id, authData.access_token).then(() => {
|
||||
// Validation with auth token worked
|
||||
return;
|
||||
}, () => {
|
||||
// Try with the id_token param
|
||||
return validateIdToken(authData.id, authData.access_token);
|
||||
});
|
||||
return validateAuthToken(authData.id, authData.access_token).then(
|
||||
() => {
|
||||
// Validation with auth token worked
|
||||
return;
|
||||
},
|
||||
() => {
|
||||
// Try with the id_token param
|
||||
return validateIdToken(authData.id, authData.access_token);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +51,10 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for api requests
|
||||
function googleRequest(path) {
|
||||
return httpsRequest.get("https://www.googleapis.com/oauth2/v3/" + path);
|
||||
return httpsRequest.get('https://www.googleapis.com/oauth2/v3/' + path);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ const https = require('https');
|
||||
function makeCallback(resolve, reject, noJSON) {
|
||||
return function(res) {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => {
|
||||
res.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
@@ -12,7 +12,7 @@ function makeCallback(resolve, reject, noJSON) {
|
||||
}
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return reject(e);
|
||||
}
|
||||
resolve(data);
|
||||
|
||||
@@ -2,20 +2,20 @@ import loadAdapter from '../AdapterLoader';
|
||||
|
||||
const facebook = require('./facebook');
|
||||
const facebookaccountkit = require('./facebookaccountkit');
|
||||
const instagram = require("./instagram");
|
||||
const linkedin = require("./linkedin");
|
||||
const meetup = require("./meetup");
|
||||
const google = require("./google");
|
||||
const github = require("./github");
|
||||
const twitter = require("./twitter");
|
||||
const spotify = require("./spotify");
|
||||
const digits = require("./twitter"); // digits tokens are validated by twitter
|
||||
const janrainengage = require("./janrainengage");
|
||||
const janraincapture = require("./janraincapture");
|
||||
const vkontakte = require("./vkontakte");
|
||||
const qq = require("./qq");
|
||||
const wechat = require("./wechat");
|
||||
const weibo = require("./weibo");
|
||||
const instagram = require('./instagram');
|
||||
const linkedin = require('./linkedin');
|
||||
const meetup = require('./meetup');
|
||||
const google = require('./google');
|
||||
const github = require('./github');
|
||||
const twitter = require('./twitter');
|
||||
const spotify = require('./spotify');
|
||||
const digits = require('./twitter'); // digits tokens are validated by twitter
|
||||
const janrainengage = require('./janrainengage');
|
||||
const janraincapture = require('./janraincapture');
|
||||
const vkontakte = require('./vkontakte');
|
||||
const qq = require('./qq');
|
||||
const wechat = require('./wechat');
|
||||
const weibo = require('./weibo');
|
||||
|
||||
const anonymous = {
|
||||
validateAuthData: () => {
|
||||
@@ -23,8 +23,8 @@ const anonymous = {
|
||||
},
|
||||
validateAppId: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const providers = {
|
||||
facebook,
|
||||
@@ -43,8 +43,8 @@ const providers = {
|
||||
vkontakte,
|
||||
qq,
|
||||
wechat,
|
||||
weibo
|
||||
}
|
||||
weibo,
|
||||
};
|
||||
function authDataValidator(adapter, appIds, options) {
|
||||
return function(authData) {
|
||||
return adapter.validateAuthData(authData, options).then(() => {
|
||||
@@ -53,7 +53,7 @@ function authDataValidator(adapter, appIds, options) {
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function loadAuthAdapter(provider, authOptions) {
|
||||
@@ -69,9 +69,13 @@ function loadAuthAdapter(provider, authOptions) {
|
||||
|
||||
// Try the configuration methods
|
||||
if (providerOptions) {
|
||||
const optionalAdapter = loadAdapter(providerOptions, undefined, providerOptions);
|
||||
const optionalAdapter = loadAdapter(
|
||||
providerOptions,
|
||||
undefined,
|
||||
providerOptions
|
||||
);
|
||||
if (optionalAdapter) {
|
||||
['validateAuthData', 'validateAppId'].forEach((key) => {
|
||||
['validateAuthData', 'validateAppId'].forEach(key => {
|
||||
if (optionalAdapter[key]) {
|
||||
adapter[key] = optionalAdapter[key];
|
||||
}
|
||||
@@ -83,34 +87,32 @@ function loadAuthAdapter(provider, authOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {adapter, appIds, providerOptions};
|
||||
return { adapter, appIds, providerOptions };
|
||||
}
|
||||
|
||||
module.exports = function(authOptions = {}, enableAnonymousUsers = true) {
|
||||
let _enableAnonymousUsers = enableAnonymousUsers;
|
||||
const setEnableAnonymousUsers = function(enable) {
|
||||
_enableAnonymousUsers = enable;
|
||||
}
|
||||
};
|
||||
// To handle the test cases on configuration
|
||||
const getValidatorForProvider = function(provider) {
|
||||
|
||||
if (provider === 'anonymous' && !_enableAnonymousUsers) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
adapter,
|
||||
appIds,
|
||||
providerOptions
|
||||
} = loadAuthAdapter(provider, authOptions);
|
||||
const { adapter, appIds, providerOptions } = loadAuthAdapter(
|
||||
provider,
|
||||
authOptions
|
||||
);
|
||||
|
||||
return authDataValidator(adapter, appIds, providerOptions);
|
||||
}
|
||||
};
|
||||
|
||||
return Object.freeze({
|
||||
getValidatorForProvider,
|
||||
setEnableAnonymousUsers
|
||||
})
|
||||
}
|
||||
setEnableAnonymousUsers,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.loadAuthAdapter = loadAuthAdapter;
|
||||
|
||||
@@ -4,15 +4,17 @@ const httpsRequest = require('./httpsRequest');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return request("users/self/?access_token=" + authData.access_token)
|
||||
.then((response) => {
|
||||
return request('users/self/?access_token=' + authData.access_token).then(
|
||||
response => {
|
||||
if (response && response.data && response.data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Instagram auth is invalid for this user.');
|
||||
});
|
||||
'Instagram auth is invalid for this user.'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -22,10 +24,10 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for api requests
|
||||
function request(path) {
|
||||
return httpsRequest.get("https://api.instagram.com/v1/" + path);
|
||||
return httpsRequest.get('https://api.instagram.com/v1/' + path);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -5,15 +5,19 @@ const httpsRequest = require('./httpsRequest');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData, options) {
|
||||
return request(options.janrain_capture_host, authData.access_token)
|
||||
.then((data) => {
|
||||
return request(options.janrain_capture_host, authData.access_token).then(
|
||||
data => {
|
||||
//successful response will have a "stat" (status) of 'ok' and a result node that stores the uuid, because that's all we asked for
|
||||
//see: https://docs.janrain.com/api/registration/entity/#entity
|
||||
if (data && data.stat == 'ok' && data.result == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Janrain capture auth is invalid for this user.');
|
||||
});
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Janrain capture auth is invalid for this user.'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -24,10 +28,9 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for api requests
|
||||
function request(host, access_token) {
|
||||
|
||||
var query_string_data = querystring.stringify({
|
||||
'access_token': access_token,
|
||||
'attribute_name': 'uuid' // we only need to pull the uuid for this access token to make sure it matches
|
||||
access_token: access_token,
|
||||
attribute_name: 'uuid', // we only need to pull the uuid for this access token to make sure it matches
|
||||
});
|
||||
|
||||
return httpsRequest.get({ host: host, path: '/entity?' + query_string_data });
|
||||
@@ -35,5 +38,5 @@ function request(host, access_token) {
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -5,15 +5,17 @@ var querystring = require('querystring');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData, options) {
|
||||
return apiRequest(options.api_key, authData.auth_token)
|
||||
.then((data) => {
|
||||
//successful response will have a "stat" (status) of 'ok' and a profile node with an identifier
|
||||
//see: http://developers.janrain.com/overview/social-login/identity-providers/user-profile-data/#normalized-user-profile-data
|
||||
if (data && data.stat == 'ok' && data.profile.identifier == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Janrain engage auth is invalid for this user.');
|
||||
});
|
||||
return apiRequest(options.api_key, authData.auth_token).then(data => {
|
||||
//successful response will have a "stat" (status) of 'ok' and a profile node with an identifier
|
||||
//see: http://developers.janrain.com/overview/social-login/identity-providers/user-profile-data/#normalized-user-profile-data
|
||||
if (data && data.stat == 'ok' && data.profile.identifier == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Janrain engage auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -24,11 +26,10 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for api requests
|
||||
function apiRequest(api_key, auth_token) {
|
||||
|
||||
var post_data = querystring.stringify({
|
||||
'token': auth_token,
|
||||
'apiKey': api_key,
|
||||
'format': 'json'
|
||||
token: auth_token,
|
||||
apiKey: api_key,
|
||||
format: 'json',
|
||||
});
|
||||
|
||||
var post_options = {
|
||||
@@ -37,8 +38,8 @@ function apiRequest(api_key, auth_token) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Length': post_data.length
|
||||
}
|
||||
'Content-Length': post_data.length,
|
||||
},
|
||||
};
|
||||
|
||||
return httpsRequest.request(post_options, post_data);
|
||||
@@ -46,5 +47,5 @@ function apiRequest(api_key, auth_token) {
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -4,15 +4,19 @@ const httpsRequest = require('./httpsRequest');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return request('people/~:(id)', authData.access_token, authData.is_mobile_sdk)
|
||||
.then((data) => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Linkedin auth is invalid for this user.');
|
||||
});
|
||||
return request(
|
||||
'people/~:(id)',
|
||||
authData.access_token,
|
||||
authData.is_mobile_sdk
|
||||
).then(data => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Linkedin auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -23,21 +27,21 @@ function validateAppId() {
|
||||
// A promisey wrapper for api requests
|
||||
function request(path, access_token, is_mobile_sdk) {
|
||||
var headers = {
|
||||
'Authorization': 'Bearer ' + access_token,
|
||||
Authorization: 'Bearer ' + access_token,
|
||||
'x-li-format': 'json',
|
||||
}
|
||||
};
|
||||
|
||||
if(is_mobile_sdk) {
|
||||
if (is_mobile_sdk) {
|
||||
headers['x-li-src'] = 'msdk';
|
||||
}
|
||||
return httpsRequest.get({
|
||||
host: 'api.linkedin.com',
|
||||
path: '/v1/' + path,
|
||||
headers: headers
|
||||
headers: headers,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -4,15 +4,15 @@ const httpsRequest = require('./httpsRequest');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return request('member/self', authData.access_token)
|
||||
.then((data) => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Meetup auth is invalid for this user.');
|
||||
});
|
||||
return request('member/self', authData.access_token).then(data => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Meetup auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills iff this app id is valid.
|
||||
@@ -26,12 +26,12 @@ function request(path, access_token) {
|
||||
host: 'api.meetup.com',
|
||||
path: '/2/' + path,
|
||||
headers: {
|
||||
'Authorization': 'bearer ' + access_token
|
||||
}
|
||||
Authorization: 'bearer ' + access_token,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -4,11 +4,16 @@ var Parse = require('parse/node').Parse;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return graphRequest('me?access_token=' + authData.access_token).then(function (data) {
|
||||
return graphRequest('me?access_token=' + authData.access_token).then(function(
|
||||
data
|
||||
) {
|
||||
if (data && data.openid == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'qq auth is invalid for this user.');
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'qq auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,18 +24,23 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for qq graph requests.
|
||||
function graphRequest(path) {
|
||||
return httpsRequest.get('https://graph.qq.com/oauth2.0/' + path, true).then((data) => {
|
||||
return parseResponseData(data);
|
||||
});
|
||||
return httpsRequest
|
||||
.get('https://graph.qq.com/oauth2.0/' + path, true)
|
||||
.then(data => {
|
||||
return parseResponseData(data);
|
||||
});
|
||||
}
|
||||
|
||||
function parseResponseData(data) {
|
||||
const starPos = data.indexOf("(");
|
||||
const endPos = data.indexOf(")");
|
||||
if(starPos == -1 || endPos == -1){
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'qq auth is invalid for this user.');
|
||||
const starPos = data.indexOf('(');
|
||||
const endPos = data.indexOf(')');
|
||||
if (starPos == -1 || endPos == -1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'qq auth is invalid for this user.'
|
||||
);
|
||||
}
|
||||
data = data.substring(starPos + 1,endPos - 1);
|
||||
data = data.substring(starPos + 1, endPos - 1);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ var Parse = require('parse/node').Parse;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return request('me', authData.access_token)
|
||||
.then((data) => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Spotify auth is invalid for this user.');
|
||||
});
|
||||
return request('me', authData.access_token).then(data => {
|
||||
if (data && data.id == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Spotify auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Returns a promise that fulfills if this app id is valid.
|
||||
@@ -21,17 +21,18 @@ function validateAppId(appIds, authData) {
|
||||
if (!appIds.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Spotify auth is not configured.');
|
||||
'Spotify auth is not configured.'
|
||||
);
|
||||
}
|
||||
return request('me', access_token)
|
||||
.then((data) => {
|
||||
if (data && appIds.indexOf(data.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Spotify auth is invalid for this user.');
|
||||
});
|
||||
return request('me', access_token).then(data => {
|
||||
if (data && appIds.indexOf(data.id) != -1) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Spotify auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// A promisey wrapper for Spotify API requests.
|
||||
@@ -40,12 +41,12 @@ function request(path, access_token) {
|
||||
host: 'api.spotify.com',
|
||||
path: '/v1/' + path,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
Authorization: 'Bearer ' + access_token,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -5,22 +5,26 @@ var logger = require('../../logger').default;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData, options) {
|
||||
if(!options) {
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Twitter auth configuration missing');
|
||||
if (!options) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
'Twitter auth configuration missing'
|
||||
);
|
||||
}
|
||||
options = handleMultipleConfigurations(authData, options);
|
||||
var client = new OAuth(options);
|
||||
client.host = "api.twitter.com";
|
||||
client.host = 'api.twitter.com';
|
||||
client.auth_token = authData.auth_token;
|
||||
client.auth_token_secret = authData.auth_token_secret;
|
||||
|
||||
return client.get("/1.1/account/verify_credentials.json").then((data) => {
|
||||
return client.get('/1.1/account/verify_credentials.json').then(data => {
|
||||
if (data && data.id_str == '' + authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Twitter auth is invalid for this user.');
|
||||
'Twitter auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,16 +37,28 @@ function handleMultipleConfigurations(authData, options) {
|
||||
if (Array.isArray(options)) {
|
||||
const consumer_key = authData.consumer_key;
|
||||
if (!consumer_key) {
|
||||
logger.error('Twitter Auth', 'Multiple twitter configurations are available, by no consumer_key was sent by the client.');
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
|
||||
logger.error(
|
||||
'Twitter Auth',
|
||||
'Multiple twitter configurations are available, by no consumer_key was sent by the client.'
|
||||
);
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Twitter auth is invalid for this user.'
|
||||
);
|
||||
}
|
||||
options = options.filter((option) => {
|
||||
options = options.filter(option => {
|
||||
return option.consumer_key == consumer_key;
|
||||
});
|
||||
|
||||
if (options.length == 0) {
|
||||
logger.error('Twitter Auth','Cannot find a configuration for the provided consumer_key');
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
|
||||
logger.error(
|
||||
'Twitter Auth',
|
||||
'Cannot find a configuration for the provided consumer_key'
|
||||
);
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Twitter auth is invalid for this user.'
|
||||
);
|
||||
}
|
||||
options = options[0];
|
||||
}
|
||||
@@ -52,5 +68,5 @@ function handleMultipleConfigurations(authData, options) {
|
||||
module.exports = {
|
||||
validateAppId,
|
||||
validateAuthData,
|
||||
handleMultipleConfigurations
|
||||
handleMultipleConfigurations,
|
||||
};
|
||||
|
||||
@@ -8,29 +8,62 @@ var logger = require('../../logger').default;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData, params) {
|
||||
return vkOAuth2Request(params).then(function (response) {
|
||||
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=5.8").then(function (response) {
|
||||
if (response && response.response && response.response.length && response.response[0].id == authData.id) {
|
||||
return request(
|
||||
'api.vk.com',
|
||||
'method/users.get?access_token=' + authData.access_token + '&v=5.8'
|
||||
).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 auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
logger.error('Vk Auth', 'Vk appIds or appSecret is incorrect.');
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk appIds or appSecret is incorrect.');
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Vk appIds or appSecret is incorrect.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function vkOAuth2Request(params) {
|
||||
return new Promise(function (resolve) {
|
||||
if (!params || !params.appIds || !params.appIds.length || !params.appSecret || !params.appSecret.length) {
|
||||
logger.error('Vk Auth', 'Vk auth is not configured. Missing appIds or appSecret.');
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Vk auth is not configured. Missing appIds or appSecret.');
|
||||
return new Promise(function(resolve) {
|
||||
if (
|
||||
!params ||
|
||||
!params.appIds ||
|
||||
!params.appIds.length ||
|
||||
!params.appSecret ||
|
||||
!params.appSecret.length
|
||||
) {
|
||||
logger.error(
|
||||
'Vk Auth',
|
||||
'Vk auth is not configured. Missing appIds or appSecret.'
|
||||
);
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Vk auth is not configured. Missing appIds or appSecret.'
|
||||
);
|
||||
}
|
||||
resolve();
|
||||
}).then(function () {
|
||||
return request("oauth.vk.com", "access_token?client_id=" + params.appIds + "&client_secret=" + params.appSecret + "&v=5.59&grant_type=client_credentials");
|
||||
}).then(function() {
|
||||
return request(
|
||||
'oauth.vk.com',
|
||||
'access_token?client_id=' +
|
||||
params.appIds +
|
||||
'&client_secret=' +
|
||||
params.appSecret +
|
||||
'&v=5.59&grant_type=client_credentials'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,10 +74,10 @@ function validateAppId() {
|
||||
|
||||
// A promisey wrapper for api requests
|
||||
function request(host, path) {
|
||||
return httpsRequest.get("https://" + host + "/" + path);
|
||||
return httpsRequest.get('https://' + host + '/' + path);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId: validateAppId,
|
||||
validateAuthData: validateAuthData
|
||||
validateAuthData: validateAuthData,
|
||||
};
|
||||
|
||||
@@ -4,11 +4,16 @@ var Parse = require('parse/node').Parse;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return graphRequest('auth?access_token=' + authData.access_token + '&openid=' + authData.id).then(function (data) {
|
||||
return graphRequest(
|
||||
'auth?access_token=' + authData.access_token + '&openid=' + authData.id
|
||||
).then(function(data) {
|
||||
if (data.errcode == 0) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'wechat auth is invalid for this user.');
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'wechat auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,5 +29,5 @@ function graphRequest(path) {
|
||||
|
||||
module.exports = {
|
||||
validateAppId,
|
||||
validateAuthData
|
||||
validateAuthData,
|
||||
};
|
||||
|
||||
@@ -5,11 +5,14 @@ var querystring = require('querystring');
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData) {
|
||||
return graphRequest(authData.access_token).then(function (data) {
|
||||
return graphRequest(authData.access_token).then(function(data) {
|
||||
if (data && data.uid == authData.id) {
|
||||
return;
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'weibo auth is invalid for this user.');
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'weibo auth is invalid for this user.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +24,7 @@ function validateAppId() {
|
||||
// A promisey wrapper for weibo graph requests.
|
||||
function graphRequest(access_token) {
|
||||
var postData = querystring.stringify({
|
||||
"access_token": access_token
|
||||
access_token: access_token,
|
||||
});
|
||||
var options = {
|
||||
hostname: 'api.weibo.com',
|
||||
@@ -29,13 +32,13 @@ function graphRequest(access_token) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
'Content-Length': Buffer.byteLength(postData),
|
||||
},
|
||||
};
|
||||
return httpsRequest.request(options, postData);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAppId,
|
||||
validateAuthData
|
||||
validateAuthData,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user