itizawa 6 лет назад
Родитель
Сommit
02ea2e0b07

+ 1 - 1
src/client/js/components/Admin/Security/GithubSecuritySetting.jsx

@@ -25,7 +25,7 @@ class GithubSecurityManagement extends React.Component {
     const { t } = this.props;
 
     try {
-      // await this.props.adminGithubSecurityContainer.updateTwitterSetting();
+      await this.props.adminGithubSecurityContainer.updateGitHubSetting();
       toastSuccess(t('security_setting.OAuth.GitHub.updated_github'));
     }
     catch (err) {

+ 19 - 0
src/client/js/services/AdminGithubSecurityConatainer.js

@@ -69,4 +69,23 @@ export default class AdminGithubSecurityContainer extends Container {
     this.setState({ isSameUsernameTreatedAsIdenticalUser: !this.state.isSameUsernameTreatedAsIdenticalUser });
   }
 
+  /**
+   * Update githubSetting
+   */
+  async updateGitHubSetting() {
+
+    const response = await this.appContainer.apiv3.put('/security-setting/github-oauth', {
+      githubClientId: this.state.githubClientId,
+      githubClientSecret: this.state.githubClientSecret,
+      isSameUsernameTreatedAsIdenticalUser: this.state.isSameUsernameTreatedAsIdenticalUser,
+    });
+
+    this.setState({
+      githubClientId: this.state.githubClientId,
+      githubClientSecret: this.state.githubClientSecret,
+      isSameUsernameTreatedAsIdenticalUser: this.state.isSameUsernameTreatedAsIdenticalUser,
+    });
+    return response;
+  }
+
 }

+ 62 - 2
src/server/routes/apiv3/security-setting.js

@@ -23,6 +23,11 @@ const validator = {
     body('hideRestrictedByOwner').isBoolean(),
     body('hideRestrictedByGroup').isBoolean(),
   ],
+  githubOAuth: [
+    body('githubClientId').isString(),
+    body('githubClientSecret').isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
+  ],
   twitterOAuth: [
     body('twitterConsumerKey').isString(),
     body('twitterConsumerSecret').isString(),
@@ -67,12 +72,23 @@ const validator = {
  *                  hideRestrictedByGroup:
  *                    type: boolean
  *                    description: enable hide by group
+ *          GitHubOAuthSetting:
+ *            type:object
+ *              githubClientId:
+ *                type: string
+ *                description: key of comsumer
+ *              githubClientSecret:
+ *                type: string
+ *                description: password of comsumer
+ *              isSameUsernameTreatedAsIdenticalUser
+ *                type: boolean
+ *                description: local account automatically linked the email matched
  *          TwitterOAuthSetting:
  *            type:object
- *              consumerKey:
+ *              twitterConsumerKey:
  *                type: string
  *                description: key of comsumer
- *              consumerSecret:
+ *              twitterConsumerSecret:
  *                type: string
  *                description: password of comsumer
  *              isSameUsernameTreatedAsIdenticalUser
@@ -268,6 +284,50 @@ module.exports = (crowi) => {
     }
   });
 
+  /**
+   * @swagger
+   *
+   *    /security-setting/github-oauth:
+   *      put:
+   *        tags: [SecuritySetting]
+   *        description: Update github OAuth
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schema:
+   *                $ref: '#/components/schemas/SecurityParams/GitHubOAuthSetting'
+   *        responses:
+   *          200:
+   *            description: Succeeded to update function
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  $ref: '#/components/schemas/SecurityParams/GitHubOAuthSetting'
+   */
+  router.put('/github-oauth', loginRequiredStrictly, adminRequired, csrf, validator.githubOAuth, ApiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'security:passport-github:clientId': req.body.githubClientId,
+      'security:passport-github:clientSecret': req.body.githubClientSecret,
+      'security:passport-github:isSameUsernameTreatedAsIdenticalUser': req.body.isSameUsernameTreatedAsIdenticalUser,
+    };
+
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
+      const securitySettingParams = {
+        githubClientId: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientId'),
+        githubClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientSecret'),
+        isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-github:isSameUsernameTreatedAsIdenticalUser'),
+      };
+      return res.apiv3({ securitySettingParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating githubOAuth';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-githubOAuth-failed'));
+    }
+  });
+
   /**
    * @swagger
    *