BVB Source Codes

parse-server Show twitter.js Source code

Return Download parse-server: download twitter.js Source code - Download parse-server Source code - Type:.js
  1. // Helper functions for accessing the twitter API.
  2. var OAuth = require('./OAuth1Client');
  3. var Parse = require('parse/node').Parse;
  4. var logger = require('../../logger').default;
  5.  
  6. // Returns a promise that fulfills iff this user id is valid.
  7. function validateAuthData(authData, options) {
  8.   if(!options) {
  9.     throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Twitter auth configuration missing');
  10.   }
  11.   options = handleMultipleConfigurations(authData, options);
  12.   var client = new OAuth(options);
  13.   client.host = "api.twitter.com";
  14.   client.auth_token = authData.auth_token;
  15.   client.auth_token_secret = authData.auth_token_secret;
  16.  
  17.   return client.get("/1.1/account/verify_credentials.json").then((data) => {
  18.     if (data && data.id_str == '' + authData.id) {
  19.       return;
  20.     }
  21.     throw new Parse.Error(
  22.       Parse.Error.OBJECT_NOT_FOUND,
  23.       'Twitter auth is invalid for this user.');
  24.   });
  25. }
  26.  
  27. // Returns a promise that fulfills iff this app id is valid.
  28. function validateAppId() {
  29.   return Promise.resolve();
  30. }
  31.  
  32. function handleMultipleConfigurations(authData, options) {
  33.   if (Array.isArray(options)) {
  34.     const consumer_key = authData.consumer_key;
  35.     if (!consumer_key) {
  36.       logger.error('Twitter Auth', 'Multiple twitter configurations are available, by no consumer_key was sent by the client.');
  37.       throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
  38.     }
  39.     options = options.filter((option) => {
  40.       return option.consumer_key == consumer_key;
  41.     });
  42.  
  43.     if (options.length == 0) {
  44.       logger.error('Twitter Auth','Cannot find a configuration for the provided consumer_key');
  45.       throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Twitter auth is invalid for this user.');
  46.     }
  47.     options = options[0];
  48.   }
  49.   return options;
  50. }
  51.  
  52. module.exports = {
  53.   validateAppId,
  54.   validateAuthData,
  55.   handleMultipleConfigurations
  56. };
  57.  
downloadtwitter.js Source code - Download parse-server Source code
Related Source Codes/Software:
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
machine-learning-for-software-engineers - A complete daily plan for studying to become a mac... 2017-06-06
upterm - A terminal emulator for the 21st century. 2017-06-06
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top