Skip to content

Commit 225e28b

Browse files
committed
support to login with github enterprise
Signed-off-by: kamijin_fanta <kamijin@live.jp>
1 parent e03a326 commit 225e28b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

config.json.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"consumerSecret": "change this"
5151
},
5252
"github": {
53+
"enterpriseURL": "if you use github.com, not need to specify",
5354
"clientID": "change this",
5455
"clientSecret": "change this"
5556
},

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)