daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const passport = require('passport');
  2. const FacebookTokenStrategy = require('passport-facebook-token');
  3. const { Strategy: GoogleTokenStrategy } = require('passport-google-token');
  4.  
  5. // FACEBOOK STRATEGY
  6. const FacebookTokenStrategyCallback = (accessToken, refreshToken, profile, done) => done(null, {
  7.     accessToken,
  8.     refreshToken,
  9.     profile,
  10. });
  11.  
  12. passport.use(new FacebookTokenStrategy({
  13.     clientID: 'your-facebook-client-id',
  14.     clientSecret: 'your-facebook-client-secret'
  15. }, FacebookTokenStrategyCallback));
  16.  
  17. // GOOGLE STRATEGY
  18. const GoogleTokenStrategyCallback = (accessToken, refreshToken, profile, done) => done(null, {
  19.     accessToken,
  20.     refreshToken,
  21.     profile,
  22. });
  23.  
  24. passport.use(new GoogleTokenStrategy({
  25.     clientID: 'your-google-client-id',
  26.     clientSecret: 'your-google-client-secret'
  27. }, GoogleTokenStrategyCallback));
  28.  
  29. // authenticate function
  30. const authenticateFacebook = (req, res) => new Promise((resolve, reject) => {
  31.     passport.authenticate('facebook-token', { session: false }, (err, data, info) => {
  32.         if (err) reject(err);
  33.         resolve({ data, info });
  34.     })(req, res);
  35. });
  36.  
  37. const authenticateGoogle = (req, res) => new Promise((resolve, reject) => {
  38.     passport.authenticate('google-token', { session: false }, (err, data, info) => {
  39.         if (err) reject(err);
  40.         resolve({ data, info });
  41.     })(req, res);
  42. });
  43.  
  44. module.exports = { authenticateFacebook, authenticateGoogle };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top