mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-27 08:12:45 +00:00
079822dfec
Add necessary dependency. Add baseURL parameter for self-hosted GitLab Add necessary require. Add block for GitLab auth. Fix typo Update font-awesome dependency for GitLab icon. Use a color closer to GitLab orange. More direct TODO
76 lines
No EOL
2.4 KiB
JavaScript
76 lines
No EOL
2.4 KiB
JavaScript
//auth
|
|
//external modules
|
|
var passport = require('passport');
|
|
var FacebookStrategy = require('passport-facebook').Strategy;
|
|
var TwitterStrategy = require('passport-twitter').Strategy;
|
|
var GithubStrategy = require('passport-github').Strategy;
|
|
var GitlabStrategy = require('passport-gitlab2').Strategy;
|
|
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
|
|
|
|
//core
|
|
var config = require('./config.js');
|
|
var logger = require("./logger.js");
|
|
var models = require("./models");
|
|
|
|
function callback(accessToken, refreshToken, profile, done) {
|
|
//logger.info(profile.displayName || profile.username);
|
|
models.User.findOrCreate({
|
|
where: {
|
|
profileid: profile.id.toString()
|
|
},
|
|
defaults: {
|
|
profile: JSON.stringify(profile)
|
|
}
|
|
}).spread(function(user, created) {
|
|
if (user) {
|
|
if (config.debug)
|
|
logger.info('user login: ' + user.id);
|
|
return done(null, user);
|
|
}
|
|
}).catch(function(err) {
|
|
logger.error('auth callback failed: ' + err);
|
|
return done(err, null);
|
|
})
|
|
}
|
|
|
|
//facebook
|
|
if (config.facebook) {
|
|
module.exports = passport.use(new FacebookStrategy({
|
|
clientID: config.facebook.clientID,
|
|
clientSecret: config.facebook.clientSecret,
|
|
callbackURL: config.serverurl + '/auth/facebook/callback'
|
|
}, callback));
|
|
}
|
|
//twitter
|
|
if (config.twitter) {
|
|
passport.use(new TwitterStrategy({
|
|
consumerKey: config.twitter.consumerKey,
|
|
consumerSecret: config.twitter.consumerSecret,
|
|
callbackURL: config.serverurl + '/auth/twitter/callback'
|
|
}, callback));
|
|
}
|
|
//github
|
|
if (config.github) {
|
|
passport.use(new GithubStrategy({
|
|
clientID: config.github.clientID,
|
|
clientSecret: config.github.clientSecret,
|
|
callbackURL: config.serverurl + '/auth/github/callback'
|
|
}, callback));
|
|
}
|
|
//gitlab
|
|
if (config.gitlab) {
|
|
passport.use(new GitlabStrategy({
|
|
baseURL: config.gitlab.baseURL,
|
|
clientID: config.gitlab.clientID,
|
|
clientSecret: config.gitlab.clientSecret,
|
|
callbackURL: config.serverurl + '/auth/gitlab/callback'
|
|
}, callback));
|
|
}
|
|
//dropbox
|
|
if (config.dropbox) {
|
|
passport.use(new DropboxStrategy({
|
|
clientID: config.dropbox.clientID,
|
|
clientSecret: config.dropbox.clientSecret,
|
|
callbackURL: config.serverurl + '/auth/dropbox/callback'
|
|
}, callback));
|
|
} |