Skip to content

Commit f871eff

Browse files
authored
Merge pull request #1327 from kamijin-fanta/github-enterprise
support to login with github enterprise
2 parents 7fd36b1 + 9e6f980 commit f871eff

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

lib/config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ module.exports = {
104104
consumerSecret: undefined
105105
},
106106
github: {
107+
enterpriseURL: undefined, // if you use github.com, not need to specify
107108
clientID: undefined,
108109
clientSecret: undefined
109110
},

lib/config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module.exports = {
6666
consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET
6767
},
6868
github: {
69+
enterpriseURL: process.env.CMD_GITHUB_ENTERPRISE_URL,
6970
clientID: process.env.CMD_GITHUB_CLIENTID,
7071
clientSecret: process.env.CMD_GITHUB_CLIENTSECRET
7172
},

lib/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ module.exports = function (sequelize, DataTypes) {
103103
else photo += '?size=bigger'
104104
break
105105
case 'github':
106-
photo = 'https://avatars.githubusercontent.com/u/' + profile.id
106+
if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '')
107+
else photo = 'https://avatars.githubusercontent.com/u/' + profile.id
107108
if (bigger) photo += '?s=400'
108109
else photo += '?s=96'
109110
break

lib/web/auth/github/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ const GithubStrategy = require('passport-github').Strategy
66
const config = require('../../../config')
77
const response = require('../../../response')
88
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
9+
const { URL } = require('url')
910

1011
const githubAuth = module.exports = Router()
1112

13+
function githubUrl (path) {
14+
return config.github.enterpriseURL && new URL(path, config.github.enterpriseURL).toString()
15+
}
16+
1217
passport.use(new GithubStrategy({
1318
clientID: config.github.clientID,
1419
clientSecret: config.github.clientSecret,
15-
callbackURL: config.serverURL + '/auth/github/callback'
20+
callbackURL: config.serverURL + '/auth/github/callback',
21+
authorizationURL: githubUrl('login/oauth/authorize'),
22+
tokenURL: githubUrl('login/oauth/access_token'),
23+
userProfileURL: githubUrl('api/v3/user')
1624
}, passportGeneralCallback))
1725

1826
githubAuth.get('/auth/github', function (req, res, next) {

0 commit comments

Comments
 (0)