|
|
@@ -231,6 +231,40 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const loginPassportGitHub = function(req, res) {
|
|
|
+ if (!passportService.isGitHubStrategySetup) {
|
|
|
+ debug('GitHubStrategy has not been set up');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ passport.authenticate('github')(req, res);
|
|
|
+ };
|
|
|
+
|
|
|
+ const loginPassportGitHubCallback = async(req, res, next) => {
|
|
|
+ const providerId = 'github';
|
|
|
+ const strategyName = 'github';
|
|
|
+ const response = await promisifiedPassportAuthentication(req, res, next, strategyName);
|
|
|
+ const userInfo = {
|
|
|
+ 'id': response.id,
|
|
|
+ 'username': response.username,
|
|
|
+ 'name': response.displayName
|
|
|
+ }
|
|
|
+
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, next, userInfo, providerId);
|
|
|
+ if (!externalAccount) {
|
|
|
+ return loginFailure(req, res, next);
|
|
|
+ }
|
|
|
+
|
|
|
+ const user = await externalAccount.getPopulatedUser();
|
|
|
+
|
|
|
+ // login
|
|
|
+ await req.logIn(user, err => {
|
|
|
+ if (err) { return next(err) };
|
|
|
+ return loginSuccess(req, res, user);
|
|
|
+ });
|
|
|
+ return next()
|
|
|
+ };
|
|
|
+
|
|
|
const promisifiedPassportAuthentication = (req, res, next, strategyName) => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
passport.authenticate(strategyName, (err, response, info) => {
|
|
|
@@ -279,7 +313,7 @@ module.exports = function(crowi, app) {
|
|
|
return loginFailure(req, res, next);
|
|
|
}
|
|
|
}
|
|
|
- throw err; // throw again
|
|
|
+ // throw err; // throw again
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -289,6 +323,8 @@ module.exports = function(crowi, app) {
|
|
|
testLdapCredentials,
|
|
|
loginWithLocal,
|
|
|
loginPassportGoogle,
|
|
|
+ loginPassportGitHub,
|
|
|
loginPassportGoogleCallback,
|
|
|
+ loginPassportGitHubCallback,
|
|
|
};
|
|
|
};
|