-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 913 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-github');
var GithubStrategy = require('passport-github').Strategy;
/**
* GitHub Exchange Plugin
*/
module.exports = function(options, getUserByGithubOrCreate) {
if (!getUserByGithubOrCreate) throw new Error('`getUserByGithubOrCreate` callback required for `consulate-github`');
var path = options.path || '/login/github';
delete options.path;
var name = options.name || 'github';
if (!options.callbackURL) options.callbackURL = path;
var authOpts = options.authOpts || {};
delete options.authOpts;
return function(app) {
debug('registering github passport strategy with options', options);
var strategy = new GithubStrategy(options, getUserByGithubOrCreate);
strategy.name = name;
app.register(strategy);
app.get(path, app.authenticate(name, authOpts), app.viewCallback('login'));
};
};