|
|
@@ -113,7 +113,7 @@ module.exports = function(crowi, app) {
|
|
|
'email': mailToBeRegistered,
|
|
|
};
|
|
|
|
|
|
- const externalAccount = await getOrCreateUser(req, res, next, userInfo, providerId);
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
|
return next();
|
|
|
}
|
|
|
@@ -230,13 +230,21 @@ module.exports = function(crowi, app) {
|
|
|
const loginPassportGoogleCallback = async(req, res, next) => {
|
|
|
const providerId = 'google';
|
|
|
const strategyName = 'google';
|
|
|
- const response = await promisifiedPassportAuthentication(req, res, next, strategyName);
|
|
|
+
|
|
|
+ let response;
|
|
|
+ try {
|
|
|
+ response = await promisifiedPassportAuthentication(strategyName, req, res);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ return loginFailure(req, res, next);
|
|
|
+ }
|
|
|
+
|
|
|
const userInfo = {
|
|
|
'id': response.id,
|
|
|
'username': response.displayName,
|
|
|
'name': `${response.name.givenName} ${response.name.familyName}`
|
|
|
};
|
|
|
- const externalAccount = await getOrCreateUser(req, res, next, userInfo, providerId);
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
|
return loginFailure(req, res, next);
|
|
|
}
|
|
|
@@ -263,14 +271,22 @@ module.exports = function(crowi, app) {
|
|
|
const loginPassportGitHubCallback = async(req, res, next) => {
|
|
|
const providerId = 'github';
|
|
|
const strategyName = 'github';
|
|
|
- const response = await promisifiedPassportAuthentication(req, res, next, strategyName);
|
|
|
+
|
|
|
+ let response;
|
|
|
+ try {
|
|
|
+ response = await promisifiedPassportAuthentication(strategyName, req, res);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ return loginFailure(req, res, next);
|
|
|
+ }
|
|
|
+
|
|
|
const userInfo = {
|
|
|
'id': response.id,
|
|
|
'username': response.username,
|
|
|
'name': response.displayName
|
|
|
};
|
|
|
|
|
|
- const externalAccount = await getOrCreateUser(req, res, next, userInfo, providerId);
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
|
return loginFailure(req, res, next);
|
|
|
}
|
|
|
@@ -297,14 +313,22 @@ module.exports = function(crowi, app) {
|
|
|
const loginPassportTwitterCallback = async(req, res, next) => {
|
|
|
const providerId = 'twitter';
|
|
|
const strategyName = 'twitter';
|
|
|
- const response = await promisifiedPassportAuthentication(req, res, next, strategyName);
|
|
|
+
|
|
|
+ let response;
|
|
|
+ try {
|
|
|
+ response = await promisifiedPassportAuthentication(strategyName, req, res);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ return loginFailure(req, res, next);
|
|
|
+ }
|
|
|
+
|
|
|
const userInfo = {
|
|
|
'id': response.id,
|
|
|
'username': response.username,
|
|
|
'name': response.displayName
|
|
|
};
|
|
|
|
|
|
- const externalAccount = await getOrCreateUser(req, res, next, userInfo, providerId);
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
|
return loginFailure(req, res, next);
|
|
|
}
|
|
|
@@ -337,7 +361,14 @@ module.exports = function(crowi, app) {
|
|
|
const attrMapFirstName = config.crowi['security:passport-saml:attrMapFirstName'] || 'firstName';
|
|
|
const attrMapLastName = config.crowi['security:passport-saml:attrMapLastName'] || 'lastName';
|
|
|
|
|
|
- const response = await promisifiedPassportAuthentication(req, res, loginFailure, strategyName);
|
|
|
+ let response;
|
|
|
+ try {
|
|
|
+ response = await promisifiedPassportAuthentication(strategyName, req, res);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ return loginFailure(req, res);
|
|
|
+ }
|
|
|
+
|
|
|
const userInfo = {
|
|
|
'id': response[attrMapId],
|
|
|
'username': response[attrMapUsername],
|
|
|
@@ -351,7 +382,7 @@ module.exports = function(crowi, app) {
|
|
|
userInfo['name'] = `${response[attrMapFirstName]} ${response[attrMapLastName]}`.trim();
|
|
|
}
|
|
|
|
|
|
- const externalAccount = await getOrCreateUser(req, res, loginFailure, userInfo, providerId);
|
|
|
+ const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
|
return loginFailure(req, res);
|
|
|
}
|
|
|
@@ -395,7 +426,7 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- const getOrCreateUser = async(req, res, next, userInfo, providerId) => {
|
|
|
+ const getOrCreateUser = async(req, res, userInfo, providerId) => {
|
|
|
try {
|
|
|
// find or register(create) user
|
|
|
const externalAccount = await ExternalAccount.findOrRegister(
|