|
@@ -19,6 +19,11 @@ const validator = {
|
|
|
body('hideRestrictedByOwner').isBoolean(),
|
|
body('hideRestrictedByOwner').isBoolean(),
|
|
|
body('hideRestrictedByGroup').isBoolean(),
|
|
body('hideRestrictedByGroup').isBoolean(),
|
|
|
],
|
|
],
|
|
|
|
|
+ googleOAuth: [
|
|
|
|
|
+ body('googleClientId').isString(),
|
|
|
|
|
+ body('googleClientSecret').isString(),
|
|
|
|
|
+ body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
|
|
|
|
|
+ ],
|
|
|
githubOAuth: [
|
|
githubOAuth: [
|
|
|
body('githubClientId').isString(),
|
|
body('githubClientId').isString(),
|
|
|
body('githubClientSecret').isString(),
|
|
body('githubClientSecret').isString(),
|
|
@@ -79,6 +84,17 @@ const validator = {
|
|
|
* isSameUsernameTreatedAsIdenticalUser
|
|
* isSameUsernameTreatedAsIdenticalUser
|
|
|
* type: boolean
|
|
* type: boolean
|
|
|
* description: local account automatically linked the email matched
|
|
* description: local account automatically linked the email matched
|
|
|
|
|
+ * GoogleOAuthSetting:
|
|
|
|
|
+ * type:object
|
|
|
|
|
+ * googleClientId:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: key of comsumer
|
|
|
|
|
+ * googleClientSecret:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: password of comsumer
|
|
|
|
|
+ * isSameUsernameTreatedAsIdenticalUser
|
|
|
|
|
+ * type: boolean
|
|
|
|
|
+ * description: local account automatically linked the email matched
|
|
|
* TwitterOAuthSetting:
|
|
* TwitterOAuthSetting:
|
|
|
* type:object
|
|
* type:object
|
|
|
* twitterConsumerKey:
|
|
* twitterConsumerKey:
|
|
@@ -119,9 +135,15 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
const securityParams = {
|
|
const securityParams = {
|
|
|
generalAuth: {
|
|
generalAuth: {
|
|
|
|
|
+ isGoogleOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled'),
|
|
|
isGithubOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-github:isEnabled'),
|
|
isGithubOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-github:isEnabled'),
|
|
|
isTwitterOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-twitter:isEnabled'),
|
|
isTwitterOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-twitter:isEnabled'),
|
|
|
},
|
|
},
|
|
|
|
|
+ googleOAuth: {
|
|
|
|
|
+ googleClientId: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientId'),
|
|
|
|
|
+ googleClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientSecret'),
|
|
|
|
|
+ isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-google:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
|
|
+ },
|
|
|
githubOAuth: {
|
|
githubOAuth: {
|
|
|
githubClientId: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientId'),
|
|
githubClientId: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientId'),
|
|
|
githubClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientSecret'),
|
|
githubClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientSecret'),
|
|
@@ -198,6 +220,50 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /security-setting/google-oauth:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [SecuritySetting]
|
|
|
|
|
+ * description: Update google OAuth
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * required: true
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/SecurityParams/GoogleOAuthSetting'
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to google OAuth
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/SecurityParams/GoogleOAuthSetting'
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put('/google-oauth', loginRequiredStrictly, adminRequired, csrf, validator.googleOAuth, ApiV3FormValidator, async(req, res) => {
|
|
|
|
|
+ const requestParams = {
|
|
|
|
|
+ 'security:passport-google:clientId': req.body.googleClientId,
|
|
|
|
|
+ 'security:passport-google:clientSecret': req.body.googleClientSecret,
|
|
|
|
|
+ 'security:passport-google:isSameUsernameTreatedAsIdenticalUser': req.body.isSameUsernameTreatedAsIdenticalUser,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
|
|
+ const securitySettingParams = {
|
|
|
|
|
+ googleClientId: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientId'),
|
|
|
|
|
+ googleClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientSecret'),
|
|
|
|
|
+ isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-google:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
|
|
+ };
|
|
|
|
|
+ return res.apiv3({ securitySettingParams });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ const msg = 'Error occurred in updating googleOAuth';
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-googleOAuth-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
|
*
|
|
*
|
|
@@ -213,7 +279,7 @@ module.exports = (crowi) => {
|
|
|
* $ref: '#/components/schemas/SecurityParams/GitHubOAuthSetting'
|
|
* $ref: '#/components/schemas/SecurityParams/GitHubOAuthSetting'
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Succeeded to update function
|
|
|
|
|
|
|
+ * description: Succeeded to github OAuth
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
@@ -257,7 +323,7 @@ module.exports = (crowi) => {
|
|
|
* $ref: '#/components/schemas/SecurityParams/TwitterOAuthSetting'
|
|
* $ref: '#/components/schemas/SecurityParams/TwitterOAuthSetting'
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Succeeded to update function
|
|
|
|
|
|
|
+ * description: Succeeded to update twitter OAuth
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|