Skip to content

Commit

Permalink
Adds support for multiple twitter auths options
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Jul 12, 2016
1 parent 7a2e906 commit 56d6c07
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/authDataManager/twitter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
// Helper functions for accessing the twitter API.
var OAuth = require('./OAuth1Client');
var Parse = require('parse/node').Parse;
var logger = require('../logger');

// Returns a promise that fulfills iff this user id is valid.
function validateAuthData(authData, options) {
if (Array.isArray(options)) {
let 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.');
}
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.');
}
options = options[0];
}
var client = new OAuth(options);
client.host = "api.twitter.com";
client.auth_token = authData.auth_token;
Expand Down

0 comments on commit 56d6c07

Please sign in to comment.