From 225e28bdbd0e75829504623b03ce3fa32de8acc2 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Fri, 25 Oct 2019 15:12:20 +0900 Subject: [PATCH 1/4] support to login with github enterprise Signed-off-by: kamijin_fanta --- config.json.example | 1 + lib/models/user.js | 3 ++- lib/web/auth/github/index.js | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index 30bd3ced..b878067a 100644 --- a/config.json.example +++ b/config.json.example @@ -50,6 +50,7 @@ "consumerSecret": "change this" }, "github": { + "enterpriseURL": "if you use github.com, not need to specify", "clientID": "change this", "clientSecret": "change this" }, diff --git a/lib/models/user.js b/lib/models/user.js index ba817c0b..19836029 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -103,7 +103,8 @@ module.exports = function (sequelize, DataTypes) { else photo += '?size=bigger' break case 'github': - photo = 'https://avatars.githubusercontent.com/u/' + profile.id + if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '') + else photo = 'https://avatars.githubusercontent.com/u/' + profile.id if (bigger) photo += '?s=400' else photo += '?s=96' break diff --git a/lib/web/auth/github/index.js b/lib/web/auth/github/index.js index c1bf48f8..0609f6b3 100644 --- a/lib/web/auth/github/index.js +++ b/lib/web/auth/github/index.js @@ -6,13 +6,21 @@ const GithubStrategy = require('passport-github').Strategy const config = require('../../../config') const response = require('../../../response') const { setReturnToFromReferer, passportGeneralCallback } = require('../utils') +const { URL } = require('url') const githubAuth = module.exports = Router() +function githubUrl (path) { + return config.github.enterpriseURL && new URL(path, config.github.enterpriseURL).toString() +} + passport.use(new GithubStrategy({ clientID: config.github.clientID, clientSecret: config.github.clientSecret, - callbackURL: config.serverURL + '/auth/github/callback' + callbackURL: config.serverURL + '/auth/github/callback', + authorizationURL: githubUrl('login/oauth/authorize'), + tokenURL: githubUrl('login/oauth/access_token'), + userProfileURL: githubUrl('api/v3/user') }, passportGeneralCallback)) githubAuth.get('/auth/github', function (req, res, next) { From ba37faf71a1dc62b7233c9919c749e14c8bb5ed2 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Sat, 26 Oct 2019 22:17:45 +0900 Subject: [PATCH 2/4] github login: default config/config from env vars. Signed-off-by: kamijin_fanta --- lib/config/default.js | 1 + lib/config/environment.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/config/default.js b/lib/config/default.js index 93de2599..9083b4c0 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,6 +104,7 @@ module.exports = { consumerSecret: undefined }, github: { + enterpriseURL: undefined, clientID: undefined, clientSecret: undefined }, diff --git a/lib/config/environment.js b/lib/config/environment.js index de573e18..e3a15006 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -66,6 +66,7 @@ module.exports = { consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET }, github: { + enterpriseURL: process.env.ENTERPRISE_URL, clientID: process.env.CMD_GITHUB_CLIENTID, clientSecret: process.env.CMD_GITHUB_CLIENTSECRET }, From b785ead5e5a9abe37f681f1281177ce9e00caed1 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Sun, 27 Oct 2019 00:01:56 +0900 Subject: [PATCH 3/4] github login: fix env name Signed-off-by: kamijin_fanta --- lib/config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/environment.js b/lib/config/environment.js index e3a15006..bc2516e7 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -66,7 +66,7 @@ module.exports = { consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET }, github: { - enterpriseURL: process.env.ENTERPRISE_URL, + enterpriseURL: process.env.CMD_GITHUB_ENTERPRISE_URL, clientID: process.env.CMD_GITHUB_CLIENTID, clientSecret: process.env.CMD_GITHUB_CLIENTSECRET }, From 9e6f980d8d3422e0a3f178226e1445ca37009a95 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Wed, 30 Oct 2019 17:02:15 +0900 Subject: [PATCH 4/4] github-login: move comment to default.js Signed-off-by: kamijin_fanta --- config.json.example | 1 - lib/config/default.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index b878067a..30bd3ced 100644 --- a/config.json.example +++ b/config.json.example @@ -50,7 +50,6 @@ "consumerSecret": "change this" }, "github": { - "enterpriseURL": "if you use github.com, not need to specify", "clientID": "change this", "clientSecret": "change this" }, diff --git a/lib/config/default.js b/lib/config/default.js index 9083b4c0..3463c4a2 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,7 +104,7 @@ module.exports = { consumerSecret: undefined }, github: { - enterpriseURL: undefined, + enterpriseURL: undefined, // if you use github.com, not need to specify clientID: undefined, clientSecret: undefined },