mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
if they've been set in the config. This causes the app to crash if things aren't configured for github. Fixed.
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
var passport = require('passport'),
|
|
GitHubStrategy = require('passport-github').Strategy;
|
|
|
|
var setup = function(options) {
|
|
passport.use(new GitHubStrategy({
|
|
clientID: options.github.id,
|
|
clientSecret: options.github.secret
|
|
},
|
|
function(accessToken, refreshToken, profile, done) {
|
|
// Delete information we don't need that will fill up the cookie jar
|
|
//
|
|
// .---------------------------.
|
|
// /_ _ _ __ __ /|
|
|
// // \ / \ / \ |_/ | |_ (_ / |
|
|
// / \_ \_/ \_/ | \ | |__ ,_/ / |
|
|
// :.__________________________/ /
|
|
// | .--. .--. .--. .--. | /
|
|
// | ( ) ) ( ) ( ) | /
|
|
// | '--' '--' '--' '--' |/
|
|
// '---------------------------'
|
|
//
|
|
profile.email = profile._json.email;
|
|
delete profile._raw;
|
|
delete profile._json;
|
|
delete profile.photos;
|
|
return done(null, {
|
|
access_token: accessToken,
|
|
profile: profile
|
|
});
|
|
}
|
|
));
|
|
}
|
|
|
|
module.exports = function (options) {
|
|
/**
|
|
* Passport configuration
|
|
*/
|
|
|
|
passport.serializeUser(function(user, done) {
|
|
done(null, user);
|
|
});
|
|
|
|
passport.deserializeUser(function(obj, done) {
|
|
done(null, obj);
|
|
});
|
|
|
|
|
|
if (options.github && options.github.id) {
|
|
setup(options);
|
|
return {
|
|
initialize: function (app) {
|
|
app.use(passport.initialize());
|
|
}
|
|
};
|
|
} else {
|
|
return {
|
|
initialize: function () {
|
|
console.log('doing nothing');
|
|
}
|
|
};
|
|
}
|
|
};
|