diff --git a/lib/config/default.js b/lib/config/default.js index e3aee6ca..64113c43 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,6 +104,7 @@ module.exports = { consumerSecret: undefined }, github: { + enterpriseURL: undefined, // if you use github.com, not need to specify clientID: undefined, clientSecret: undefined }, diff --git a/lib/config/environment.js b/lib/config/environment.js index 905f0e0d..4defcac6 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.CMD_GITHUB_ENTERPRISE_URL, clientID: process.env.CMD_GITHUB_CLIENTID, clientSecret: process.env.CMD_GITHUB_CLIENTSECRET }, 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) {