Skip to content

Commit 56d6c07

Browse files
committed
Adds support for multiple twitter auths options
1 parent 7a2e906 commit 56d6c07

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/authDataManager/twitter.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
// Helper functions for accessing the twitter API.
22
var OAuth = require('./OAuth1Client');
33
var Parse = require('parse/node').Parse;
4+
var logger = require('../logger');
45

56
// Returns a promise that fulfills iff this user id is valid.
67
function validateAuthData(authData, options) {
8+
if (Array.isArray(options)) {
9+
let consumer_key = authData.consumer_key;
10+
if (!consumer_key) {
11+
logger.error('Twitter Auth', 'Multiple twitter configurations are available, by no consumer_key was sent by the client.');
12+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
13+
}
14+
options = options.filter((option) => {
15+
return option.consumer_key == consumer_key;
16+
});
17+
18+
if (options.length == 0) {
19+
logger.error('Twitter Auth','Cannot find a configuration for the provided consumer_key');
20+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
21+
}
22+
options = options[0];
23+
}
724
var client = new OAuth(options);
825
client.host = "api.twitter.com";
926
client.auth_token = authData.auth_token;

0 commit comments

Comments
 (0)