BVB Source Codes

parse-server Show weibo.js Source code

Return Download parse-server: download weibo.js Source code - Download parse-server Source code - Type:.js
  1. // Helper functions for accessing the weibo Graph API.
  2. var https = require('https');
  3. var Parse = require('parse/node').Parse;
  4. var querystring = require('querystring');
  5.  
  6. // Returns a promise that fulfills iff this user id is valid.
  7. function validateAuthData(authData) {
  8.   return graphRequest(authData.access_token).then(function (data) {
  9.     if (data && data.uid == authData.id) {
  10.       return;
  11.     }
  12.     throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'weibo auth is invalid for this user.');
  13.   });
  14. }
  15.  
  16. // Returns a promise that fulfills if this app id is valid.
  17. function validateAppId() {
  18.   return Promise.resolve();
  19. }
  20.  
  21. // A promisey wrapper for weibo graph requests.
  22. function graphRequest(access_token) {
  23.   return new Promise(function (resolve, reject) {
  24.     var postData = querystring.stringify({
  25.       "access_token":access_token
  26.     });
  27.     var options = {
  28.       hostname: 'api.weibo.com',
  29.       path: '/oauth2/get_token_info',
  30.       method: 'POST',
  31.       headers: {
  32.         'Content-Type': 'application/x-www-form-urlencoded',
  33.         'Content-Length': Buffer.byteLength(postData)
  34.       }
  35.     };
  36.     var req = https.request(options, function(res){
  37.       var data = '';
  38.       res.on('data', function (chunk) {
  39.         data += chunk;
  40.       });
  41.       res.on('end', function () {
  42.         try {
  43.           data = JSON.parse(data);
  44.         } catch(e) {
  45.           return reject(e);
  46.         }
  47.         resolve(data);
  48.       });
  49.       res.on('error', function () {
  50.         reject('Failed to validate this access token with weibo.');
  51.       });
  52.     });
  53.     req.on('error', function () {
  54.       reject('Failed to validate this access token with weibo.');
  55.     });
  56.     req.write(postData);
  57.     req.end();
  58.   });
  59. }
  60.  
  61. module.exports = {
  62.   validateAppId,
  63.   validateAuthData
  64. };
  65.  
downloadweibo.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