BVB Source Codes

parse-server Show facebook.js Source code

Return Download parse-server: download facebook.js Source code - Download parse-server Source code - Type:.js
  1. // Helper functions for accessing the Facebook Graph API.
  2. var https = require('https');
  3. var Parse = require('parse/node').Parse;
  4.  
  5. // Returns a promise that fulfills iff this user id is valid.
  6. function validateAuthData(authData) {
  7.   return graphRequest('me?fields=id&access_token=' + authData.access_token)
  8.     .then((data) => {
  9.       if (data && data.id == authData.id) {
  10.         return;
  11.       }
  12.       throw new Parse.Error(
  13.         Parse.Error.OBJECT_NOT_FOUND,
  14.         'Facebook auth is invalid for this user.');
  15.     });
  16. }
  17.  
  18. // Returns a promise that fulfills iff this app id is valid.
  19. function validateAppId(appIds, authData) {
  20.   var access_token = authData.access_token;
  21.   if (!appIds.length) {
  22.     throw new Parse.Error(
  23.       Parse.Error.OBJECT_NOT_FOUND,
  24.       'Facebook auth is not configured.');
  25.   }
  26.   return graphRequest('app?access_token=' + access_token)
  27.     .then((data) => {
  28.       if (data && appIds.indexOf(data.id) != -1) {
  29.         return;
  30.       }
  31.       throw new Parse.Error(
  32.         Parse.Error.OBJECT_NOT_FOUND,
  33.         'Facebook auth is invalid for this user.');
  34.     });
  35. }
  36.  
  37. // A promisey wrapper for FB graph requests.
  38. function graphRequest(path) {
  39.   return new Promise(function(resolve, reject) {
  40.     https.get('https://graph.facebook.com/v2.5/' + path, function(res) {
  41.       var data = '';
  42.       res.on('data', function(chunk) {
  43.         data += chunk;
  44.       });
  45.       res.on('end', function() {
  46.         try {
  47.           data = JSON.parse(data);
  48.         } catch(e) {
  49.           return reject(e);
  50.         }
  51.         resolve(data);
  52.       });
  53.     }).on('error', function() {
  54.       reject('Failed to validate this access token with Facebook.');
  55.     });
  56.   });
  57. }
  58.  
  59. module.exports = {
  60.   validateAppId: validateAppId,
  61.   validateAuthData: validateAuthData
  62. };
  63.  
downloadfacebook.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