Selaa lähdekoodia

implement isValidAccessToken

itizawa 5 vuotta sitten
vanhempi
sitoutus
8e7fa79fb0
1 muutettua tiedostoa jossa 16 lisäystä ja 10 poistoa
  1. 16 10
      src/server/service/bolt.js

+ 16 - 10
src/server/service/bolt.js

@@ -74,17 +74,14 @@ class BoltService {
     }
     }
   }
   }
 
 
-  verifyAccessToken(body, command) {
+  // Check if the access token is correct
+  isValidAccessToken(body, command) {
     const slackBotAccessToken = body.slack_bot_access_token || null;
     const slackBotAccessToken = body.slack_bot_access_token || null;
-    if (slackBotAccessToken == null || slackBotAccessToken !== this.crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
-      logger.error('slack_bot_access_token is inValid.');
-      this.client.chat.postEphemeral({
-        channel: command.channel_id,
-        user: command.user_id,
-        blocks: [this.generateMarkdownSectionBlock('*Access token is inValid*')],
-      });
-      throw new Error('slack_bot_access_token is inValid');
+
+    if (slackBotAccessToken == null) {
+      return false;
     }
     }
+    return slackBotAccessToken === this.crowi.configManager.getConfig('crowi', 'slackbot:access-token');
   }
   }
 
 
   init() {
   init() {
@@ -92,7 +89,16 @@ class BoltService {
       command, client, body, ack,
       command, client, body, ack,
     }) => {
     }) => {
       await ack();
       await ack();
-      this.verifyAccessToken(body, command);
+
+      if (!this.isValidAccessToken(body, command)) {
+        logger.error('slack_bot_access_token is inValid.');
+        this.client.chat.postEphemeral({
+          channel: command.channel_id,
+          user: command.user_id,
+          blocks: [this.generateMarkdownSectionBlock('*Access token is inValid*')],
+        });
+        throw new Error('slack_bot_access_token is inValid');
+      }
 
 
       const args = command.text.split(' ');
       const args = command.text.split(' ');
       const firstArg = args[0];
       const firstArg = args[0];