How to use passport-facebook - 10 common examples

To help you get started, we’ve selected a few passport-facebook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JedWatson / sydjs-site / lib / auth / facebook.js View on Github external
exports.authenticateUser = function(req, res, next) {
	var self = this;

	var redirect = '/auth/confirm';
	if (req.cookies.target && req.cookies.target == 'app') redirect = '/auth/app';

	// Begin process
	console.log('============================================================');
	console.log('[services.facebook] - Triggered authentication process...');
	console.log('------------------------------------------------------------');

	// Initalise Facebook credentials
	var facebookStrategy = new passportFacebookStrategy(credentials, function(accessToken, refreshToken, profile, done) {
		done(null, {
			accessToken: accessToken,
			refreshToken: refreshToken,
			profile: profile
		});
	});

	// Pass through authentication to passport
	passport.use(facebookStrategy);

	// Save user data once returning from Facebook
	if (_.has(req.query, 'cb')) {

		console.log('[services.facebook] - Callback workflow detected, attempting to process data...');
		console.log('------------------------------------------------------------');
github JedWatson / sydjs-site / lib / services / facebook.js View on Github external
exports.authenticateUser = function(req, res, next, callback)
{
	// Begin process
	console.log('============================================================');
	console.log('[services.facebook] - Triggered authentication process...' );
	console.log('------------------------------------------------------------');
	
	// Set placeholder variables to hold our data
	var data = {
		facebookUser: false, // FB user
		sydjsUser: false // SydJS user
	}
	
	// Initalise Facebook credentials
	var facebookStrategy = new passportFacebookStrategy(credentials, function(accessToken, refreshToken, profile, done) {
		
		done(null, {
			accessToken: accessToken,
			profile: profile
		});
	
	});
	
	// Pass through authentication to passport
	passport.use(facebookStrategy);
	
	// Determine workflow
	var workflow = false;
	
	if ( _.has(req.query, 'callback' ) )
		workflow = 'save';
github bilashcse / Online-Video-Editor / config / passport.js View on Github external
if (!user.isValidPassword(password)) {
          
          return done(null, false, { message: 'Invalid password' })
        }

        //console.log(user);
        //console.log('Login User');
        return done(null, user)
      })
    }
  ))
 

  
  // use facebook strategy
  passport.use(new FacebookStrategy({
        clientID: config.facebook.clientID
      , clientSecret: config.facebook.clientSecret
      , callbackURL: config.facebook.callbackURL
      , passReqToCallback: true
    },
    function(req,accessToken, refreshToken, params, profile, done) {


      if(!req.user)
      {
        //console.log( params);
        User.findOne({ 'facebook.id': profile.id }, function (err, user) {
          if (err) { return done(err) }
          if (!user) {
          
            user = new User({
github gitana / cloudcms-server / middleware / authentication / providers / facebook.js View on Github external
constructor(req, config)
    {
        super(req, config);

        if (!config.properties) {
            config.properties = {};
        }
        if (!config.properties.id) {
            config.properties.id = "id";
        }

        // passport
        this.facebookStrategy = new FacebookStrategy({
            clientID: config.appId,
            clientSecret: config.appSecret,
            callbackURL: config.callbackURL,
            passReqToCallback: true
        }, auth.buildPassportCallback(config, this));

        req.passport.use(this.facebookStrategy);
    }
github jimschubert / yfa-nodejs-code / code / yfa / src / FacebookAuth.js View on Github external
module.exports = exports = function (passport) {
    // Configure the FacebookStrategy
    passport.use(new FacebookStrategy({
            clientID: facebook.app.id,
            clientSecret: facebook.app.secret,
            callbackURL: (facebook.app.host||"") + "/auth/facebook/callback"
        },
        authVerification
    ));

    // prepare for user serialize/deserialize
    passport.serializeUser(authSerialize);
    passport.deserializeUser(authDeserialize);
};
github coralproject / talk / services / passport.js View on Github external
await UsersService.flagForRecaptchaRequirement(email, false);
    } catch (err) {
      return done(err);
    }
  }

  // Define the loginProfile being used to perform an additional
  // verificaiton.
  let loginProfile = {id: email, provider: 'local'};

  // Perform final steps to login the user.
  return ValidateUserLogin(loginProfile, user, done);
}));

if (process.env.TALK_FACEBOOK_APP_ID && process.env.TALK_FACEBOOK_APP_SECRET && process.env.TALK_ROOT_URL) {
  passport.use(new FacebookStrategy({
    clientID: process.env.TALK_FACEBOOK_APP_ID,
    clientSecret: process.env.TALK_FACEBOOK_APP_SECRET,
    callbackURL: `${process.env.TALK_ROOT_URL}/api/v1/auth/facebook/callback`,
    passReqToCallback: true,
    profileFields: ['id', 'displayName', 'picture.type(large)']
  }, async (req, accessToken, refreshToken, profile, done) => {

    let user;
    try {
      user = await UsersService.findOrCreateExternalUser(profile);
    } catch (err) {
      return done(err);
    }

    return ValidateUserLogin(profile, user, done);
  }));
github kriasoft / aspnet-starter-kit / src / core / passport.js View on Github external
/**
 * Passport.js reference implementation.
 * The database schema used in this sample is available at
 * https://github.com/membership/membership.db/tree/master/postgres
 */

import passport from 'passport';
import { Strategy as FacebookStrategy } from 'passport-facebook';
import { User, UserLogin, UserClaim, UserProfile } from '../data/models';
import { auth as config } from '../config';

/**
 * Sign in with Facebook.
 */
passport.use(new FacebookStrategy({
  clientID: config.facebook.id,
  clientSecret: config.facebook.secret,
  callbackURL: '/login/facebook/return',
  profileFields: ['name', 'email', 'link', 'locale', 'timezone'],
  passReqToCallback: true,
}, (req, accessToken, refreshToken, profile, done) => {
  /* eslint-disable no-underscore-dangle */
  const loginName = 'facebook';
  const claimType = 'urn:facebook:access_token';
  const fooBar = async () => {
    if (req.user) {
      const userLogin = await UserLogin.findOne({
        attributes: ['name', 'key'],
        where: { name: loginName, key: profile.id },
      });
      if (userLogin) {
github kriasoft / app-starter-kit / api / src / passport.js View on Github external
try {
        const user = await login(req, 'google', profile, {
          accessToken,
          refreshToken,
        });
        done(null, user);
      } catch (err) {
        done(err);
      }
    },
  ),
);

// https://github.com/jaredhanson/passport-facebook
passport.use(
  new FacebookStrategy(
    {
      clientID: process.env.FACEBOOK_ID,
      clientSecret: process.env.FACEBOOK_SECRET,
      profileFields: [
        'name',
        'email',
        'picture',
        'link',
        'locale',
        'timezone',
        'verified',
      ],
      callbackURL: '/login/facebook/return',
      passReqToCallback: true,
    },
    async (req, accessToken, refreshToken, profile, done) => {
github kriasoft / nodejs-api-starter / src / passport.js View on Github external
const user = await login(req, 'google', profile, {
          accessToken,
          refreshToken,
        });
        done(null, user);
      } catch (err) {
        done(err);
      }
    },
  ),
);

// https://github.com/jaredhanson/passport-facebook
// https://developers.facebook.com/docs/facebook-login/permissions/
passport.use(
  new FacebookStrategy(
    {
      clientID: process.env.FACEBOOK_ID,
      clientSecret: process.env.FACEBOOK_SECRET,
      profileFields: [
        'id',
        'cover',
        'name',
        'age_range',
        'link',
        'gender',
        'locale',
        'picture',
        'timezone',
        'updated_time',
        'verified',
        'email',
github jannunzi / mean-stack-authentication-and-registration-with-passport / app / services / user / user.service.server.js View on Github external
failureRedirect: '/#/login'
        }));

    var googleConfig = {
        clientID        : process.env.GOOGLE_CLIENT_ID,
        clientSecret    : process.env.GOOGLE_CLIENT_SECRET,
        callbackURL     : process.env.GOOGLE_CALLBACK_URL
    };

    var facebookConfig = {
        clientID        : process.env.FACEBOOK_CLIENT_ID,
        clientSecret    : process.env.FACEBOOK_CLIENT_SECRET,
        callbackURL     : process.env.FACEBOOK_CALLBACK_URL
    };

    passport.use(new FacebookStrategy(facebookConfig, facebookStrategy));
    passport.use(new GoogleStrategy(googleConfig, googleStrategy));
    passport.use(new LocalStrategy(localStrategy));
    passport.serializeUser(serializeUser);
    passport.deserializeUser(deserializeUser);

    function facebookStrategy(token, refreshToken, profile, done) {
        userModel
            .findUserByFacebookId(profile.id)
            .then(
                function(user) {
                    if(user) {
                        return done(null, user);
                    } else {
                        var names = profile.displayName.split(" ");
                        var newFacebookUser = {
                            lastName:  names[1],

passport-facebook

Facebook authentication strategy for Passport.

MIT
Latest version published 6 years ago

Package Health Score

58 / 100
Full package analysis

Popular passport-facebook functions