|
@@ -60,6 +60,7 @@ const validator = {
|
|
|
body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
|
|
body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
|
|
|
],
|
|
],
|
|
|
googleOAuth: [
|
|
googleOAuth: [
|
|
|
|
|
+ body('isGoogleOAuthEnabled').isBoolean(),
|
|
|
body('googleClientId').isString(),
|
|
body('googleClientId').isString(),
|
|
|
body('googleClientSecret').isString(),
|
|
body('googleClientSecret').isString(),
|
|
|
body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
|
|
body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
|
|
@@ -222,6 +223,9 @@ const validator = {
|
|
|
* description: local account automatically linked the email matched
|
|
* description: local account automatically linked the email matched
|
|
|
* GitHubOAuthSetting:
|
|
* GitHubOAuthSetting:
|
|
|
* type:object
|
|
* type:object
|
|
|
|
|
+ * isGoogleOAuthEnabled:
|
|
|
|
|
+ * type: boolean
|
|
|
|
|
+ * description: whether to enable google oauth
|
|
|
* githubClientId:
|
|
* githubClientId:
|
|
|
* type: string
|
|
* type: string
|
|
|
* description: key of comsumer
|
|
* description: key of comsumer
|
|
@@ -659,6 +663,7 @@ module.exports = (crowi) => {
|
|
|
*/
|
|
*/
|
|
|
router.put('/google-oauth', loginRequiredStrictly, adminRequired, csrf, validator.googleOAuth, ApiV3FormValidator, async(req, res) => {
|
|
router.put('/google-oauth', loginRequiredStrictly, adminRequired, csrf, validator.googleOAuth, ApiV3FormValidator, async(req, res) => {
|
|
|
const requestParams = {
|
|
const requestParams = {
|
|
|
|
|
+ 'security:passport-google:isEnabled': req.body.isEnabled,
|
|
|
'security:passport-google:clientId': req.body.googleClientId,
|
|
'security:passport-google:clientId': req.body.googleClientId,
|
|
|
'security:passport-google:clientSecret': req.body.googleClientSecret,
|
|
'security:passport-google:clientSecret': req.body.googleClientSecret,
|
|
|
'security:passport-google:isSameUsernameTreatedAsIdenticalUser': req.body.isSameUsernameTreatedAsIdenticalUser,
|
|
'security:passport-google:isSameUsernameTreatedAsIdenticalUser': req.body.isSameUsernameTreatedAsIdenticalUser,
|
|
@@ -667,13 +672,22 @@ module.exports = (crowi) => {
|
|
|
try {
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
const securitySettingParams = {
|
|
const securitySettingParams = {
|
|
|
|
|
+ isGoogleOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled'),
|
|
|
googleClientId: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientId'),
|
|
googleClientId: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientId'),
|
|
|
googleClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientSecret'),
|
|
googleClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientSecret'),
|
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-google:isSameUsernameTreatedAsIdenticalUser'),
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-google:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
};
|
|
};
|
|
|
|
|
+ // reset strategy
|
|
|
|
|
+ await crowi.passportService.resetGoogleStrategy();
|
|
|
|
|
+ // setup strategy
|
|
|
|
|
+ if (crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled')) {
|
|
|
|
|
+ await crowi.passportService.setupGoogleStrategy(true);
|
|
|
|
|
+ }
|
|
|
return res.apiv3({ securitySettingParams });
|
|
return res.apiv3({ securitySettingParams });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
|
|
+ // reset strategy
|
|
|
|
|
+ await crowi.passportService.resetGoogleStrategy();
|
|
|
const msg = 'Error occurred in updating googleOAuth';
|
|
const msg = 'Error occurred in updating googleOAuth';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-googleOAuth-failed'));
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-googleOAuth-failed'));
|