From a3876dfc9292cb8d96d00c045ef2bb1a517a85a5 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Mon, 9 May 2016 18:31:49 -0400 Subject: [PATCH] Start extending to support GitLab authentication. 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 --- app.js | 17 +++++++++++++++++ config.json | 5 +++++ lib/auth.js | 10 ++++++++++ lib/config.js | 2 ++ lib/response.js | 2 ++ package.json | 1 + public/views/signin-modal.ejs | 5 +++++ 7 files changed, 42 insertions(+) diff --git a/app.js b/app.js index bfb9ac7..db623a5 100644 --- a/app.js +++ b/app.js @@ -292,6 +292,23 @@ if (config.github) { //github callback actions app.get('/auth/github/callback/:noteId/:action', response.githubActions); } +//gitlab auth +if (config.gitlab) { + app.get('/auth/gitlab', + passport.authenticate('gitlab'), + function (req, res) {}); + //gitlab auth callback + app.get('/auth/gitlab/callback', + passport.authenticate('gitlab', { + failureRedirect: config.serverurl + }), + function (req, res) { + res.redirect(config.serverurl); + }); + //gitlab callback actions + // TODO: Maybe in the future + //app.get('/auth/gitlab/callback/:noteId/:action', response.gitlabActions); +} //dropbox auth if (config.dropbox) { app.get('/auth/dropbox', diff --git a/config.json b/config.json index 16ad258..c65e9c7 100644 --- a/config.json +++ b/config.json @@ -32,6 +32,11 @@ "clientID": "change this", "clientSecret": "change this" }, + "gitlab": { + "baseURL": "change this", + "clientID": "change this", + "clientSecret": "change this" + }, "dropbox": { "clientID": "change this", "clientSecret": "change this" diff --git a/lib/auth.js b/lib/auth.js index af3e8d1..d495605 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -4,6 +4,7 @@ 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 @@ -56,6 +57,15 @@ if (config.github) { 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({ diff --git a/lib/config.js b/lib/config.js index 6738d4a..c138b45 100644 --- a/lib/config.js +++ b/lib/config.js @@ -59,6 +59,7 @@ var documentmaxlength = config.documentmaxlength || 100000; var facebook = config.facebook || false; var twitter = config.twitter || false; var github = config.github || false; +var gitlab = config.gitlab || false; var dropbox = config.dropbox || false; var imgur = config.imgur || false; @@ -110,6 +111,7 @@ module.exports = { facebook: facebook, twitter: twitter, github: github, + gitlab: gitlab, dropbox: dropbox, imgur: imgur }; \ No newline at end of file diff --git a/lib/response.js b/lib/response.js index 7a75e23..2114c99 100644 --- a/lib/response.js +++ b/lib/response.js @@ -94,6 +94,7 @@ function showIndex(req, res, next) { facebook: config.facebook, twitter: config.twitter, github: config.github, + gitlab: config.gitlab, dropbox: config.dropbox, }); res.write(content); @@ -124,6 +125,7 @@ function responseHackMD(res, note) { facebook: config.facebook, twitter: config.twitter, github: config.github, + gitlab: config.gitlab, dropbox: config.dropbox, }); var buf = html; diff --git a/package.json b/package.json index a70bce3..3ecaa84 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "passport-dropbox-oauth2": "^1.0.0", "passport-facebook": "^2.1.0", "passport-github": "^1.1.0", + "passport-gitlab2": "^2.2.0", "passport-twitter": "^1.0.4", "passport.socketio": "^3.6.1", "pg": "^4.5.3", diff --git a/public/views/signin-modal.ejs b/public/views/signin-modal.ejs index 260ff42..4eb33bf 100644 --- a/public/views/signin-modal.ejs +++ b/public/views/signin-modal.ejs @@ -28,6 +28,11 @@ Sign in via Dropbox <% } %> + <% if(gitlab) { %> + + Sign in via GitLab + + <% } %>