-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (24 loc) · 938 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Module dependencies
*/
var debug = require('simple-debug')('consulate-facebook')
, FacebookStrategy = require('passport-facebook').Strategy;
/**
* Facebook Exchange Plugin
*/
module.exports = function(options, getUserByFacebookOrCreate) {
if (!getUserByFacebookOrCreate) throw new Error('`getUserByFacebookOrCreate` callback required for `consulate-facebook`');
var path = options.path || '/login/facebook';
delete options.path;
var name = options.name || 'facebook';
if (!options.callbackURL) options.callbackURL = path;
var authOpts = options.authOpts || {};
delete options.authOpts;
return function(app) {
debug('registering facebook passport strategy with options', options);
var strategy = new FacebookStrategy(options, getUserByFacebookOrCreate);
strategy.name = name;
app.register(strategy);
app.get(path, app.authenticate(name, authOpts), app.viewCallback('login'));
};
};