Skip to content

Commit 22f7c4b

Browse files
committed
Merge branch 'jccrofty30-gitlab_authentication'
2 parents a70ebf7 + 7383576 commit 22f7c4b

8 files changed

Lines changed: 45 additions & 0 deletions

File tree

app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ if (config.github) {
292292
//github callback actions
293293
app.get('/auth/github/callback/:noteId/:action', response.githubActions);
294294
}
295+
//gitlab auth
296+
if (config.gitlab) {
297+
app.get('/auth/gitlab',
298+
passport.authenticate('gitlab'),
299+
function (req, res) {});
300+
//gitlab auth callback
301+
app.get('/auth/gitlab/callback',
302+
passport.authenticate('gitlab', {
303+
failureRedirect: config.serverurl
304+
}),
305+
function (req, res) {
306+
res.redirect(config.serverurl);
307+
});
308+
//gitlab callback actions
309+
// TODO: Maybe in the future
310+
//app.get('/auth/gitlab/callback/:noteId/:action', response.gitlabActions);
311+
}
295312
//dropbox auth
296313
if (config.dropbox) {
297314
app.get('/auth/dropbox',

config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"clientID": "change this",
3333
"clientSecret": "change this"
3434
},
35+
"gitlab": {
36+
"baseURL": "change this",
37+
"clientID": "change this",
38+
"clientSecret": "change this"
39+
},
3540
"dropbox": {
3641
"clientID": "change this",
3742
"clientSecret": "change this"

lib/auth.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var passport = require('passport');
44
var FacebookStrategy = require('passport-facebook').Strategy;
55
var TwitterStrategy = require('passport-twitter').Strategy;
66
var GithubStrategy = require('passport-github').Strategy;
7+
var GitlabStrategy = require('passport-gitlab2').Strategy;
78
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
89

910
//core
@@ -56,6 +57,15 @@ if (config.github) {
5657
callbackURL: config.serverurl + '/auth/github/callback'
5758
}, callback));
5859
}
60+
//gitlab
61+
if (config.gitlab) {
62+
passport.use(new GitlabStrategy({
63+
baseURL: config.gitlab.baseURL,
64+
clientID: config.gitlab.clientID,
65+
clientSecret: config.gitlab.clientSecret,
66+
callbackURL: config.serverurl + '/auth/gitlab/callback'
67+
}, callback));
68+
}
5969
//dropbox
6070
if (config.dropbox) {
6171
passport.use(new DropboxStrategy({

lib/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var documentmaxlength = config.documentmaxlength || 100000;
5959
var facebook = config.facebook || false;
6060
var twitter = config.twitter || false;
6161
var github = config.github || false;
62+
var gitlab = config.gitlab || false;
6263
var dropbox = config.dropbox || false;
6364
var imgur = config.imgur || false;
6465

@@ -110,6 +111,7 @@ module.exports = {
110111
facebook: facebook,
111112
twitter: twitter,
112113
github: github,
114+
gitlab: gitlab,
113115
dropbox: dropbox,
114116
imgur: imgur
115117
};

lib/models/user.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ module.exports = function (sequelize, DataTypes) {
6363
case "github":
6464
photo = 'https://avatars.githubusercontent.com/u/' + profile.id + '?s=48';
6565
break;
66+
case "gitlab":
67+
photo = profile.avatarUrl;
68+
break;
6669
case "dropbox":
6770
//no image api provided, use gravatar
6871
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);

lib/response.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function showIndex(req, res, next) {
9494
facebook: config.facebook,
9595
twitter: config.twitter,
9696
github: config.github,
97+
gitlab: config.gitlab,
9798
dropbox: config.dropbox
9899
});
99100
res.write(content);
@@ -124,6 +125,7 @@ function responseHackMD(res, note) {
124125
facebook: config.facebook,
125126
twitter: config.twitter,
126127
github: config.github,
128+
gitlab: config.gitlab,
127129
dropbox: config.dropbox
128130
});
129131
var buf = html;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"passport-dropbox-oauth2": "^1.0.0",
4040
"passport-facebook": "^2.1.0",
4141
"passport-github": "^1.1.0",
42+
"passport-gitlab2": "^2.2.0",
4243
"passport-twitter": "^1.0.4",
4344
"passport.socketio": "^3.6.1",
4445
"pg": "^4.5.3",

public/views/signin-modal.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<i class="fa fa-dropbox"></i> Sign in via Dropbox
2929
</a>
3030
<% } %>
31+
<% if(gitlab) { %>
32+
<a href="<%- url %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-soundcloud">
33+
<i class="fa fa-gitlab"></i> Sign in via GitLab
34+
</a>
35+
<% } %>
3136
</div>
3237
</div>
3338
</div>

0 commit comments

Comments
 (0)