daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest May 17th, 2018 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var util = require('util')
  2.  
  3. var oauth2 = require('passport-oauth2')
  4.  
  5. function Strategy(options, verify) {
  6.   oauth2.Strategy.call(this, options, verify)
  7.   if (!options.authorizationURL) {
  8.     throw new TypeError('OAuth2Strategy requires a userinfoURL option')
  9.   }
  10.   this._userinfoURL = options.userinfoURL
  11.   this._oauth2.useAuthorizationHeaderforGET(true)
  12. }
  13.  
  14. util.inherits(Strategy, oauth2.Strategy)
  15.  
  16. Strategy.prototype.userProfile = function(accessToken, callback) {
  17.   this._oauth2.get(this._userinfoURL, accessToken, function(err, data) {
  18.     if (err) {
  19.       return callback(err)
  20.     }
  21.  
  22.     try {
  23.       return callback(null, JSON.parse(data))
  24.     }
  25.     catch (err) {
  26.       return callback(err)
  27.     }
  28.   })
  29. }
  30.  
  31. module.exports = Strategy
RAW Paste Data
Top