Skip to content

InstallationStore.fetchInstallation can fetch different user's token if userId is specified in the query and the user's installation is not found #12

Description

@forestaa

Hi, thank you for your awesome extensions!

I have a question about the behavior of PrismaInstallationStore.fetchInstallation (and other implementations in this repository), which is different from FileInstallationStore.fetchInstallation's if userId is specified in the query.
FileInstallationStore.fetchInstallation returns installation data without user.token if the specified user's installation data is not found. (see https://github.com/slackapi/node-slack-sdk/blob/664db4e58d5a7b7082d3006b969e82a4b459402e/packages/oauth/src/installation-stores/file-store.ts#L84-L87)
However, PrismaInstallationStore.fetchInstallation returns full installation data with different user's token even if the specified user's installation data is not found.

Is this behavior is expected?
(There will be no problem as long as all users install the app before use it because everyone's installation is always found, I think.)

Here is sample code.

import { PrismaClient } from "@prisma/client";
import { PrismaInstallationStore } from "@seratch_/bolt-prisma";
import { FileInstallationStore } from "@slack/bolt";

(async () => {
  const installation = {
    team: {
      id: "team",
      name: "test",
    },
    enterprise: { id: "test" },
    user: { id: "user1", token: "userToken", scopes: [] },
    bot: { id: "bot1", token: "botToken", scopes: [], userId: "botUser1" },
  };

  const prismaClient = new PrismaClient();
  const prismaInstallationStore = new PrismaInstallationStore({
    prismaTable: prismaClient.slackAppInstallation,
    clientId: "00000",
  });
  await prismaInstallationStore.storeInstallation(installation);
  const prismaInstallation = await prismaInstallationStore.fetchInstallation({
    teamId: "team",
    enterpriseId: "test",
    isEnterpriseInstall: false,
    userId: "user2", // different from uesr1
  });
  console.log(`prismaInstallationStore.fetchInstallation: ${JSON.stringify(prismaInstallation)}`);

  const fileInstallationStore = new FileInstallationStore({ clientId: "00000", baseDir: "./bolt-js-app-installation" });
  await fileInstallationStore.storeInstallation(installation);
  const fileInstallation = await fileInstallationStore.fetchInstallation({
    teamId: "team",
    enterpriseId: "test",
    isEnterpriseInstall: false,
    userId: "user2",
  });
  console.log(`fileInstallationStore.fetchInstallation: ${JSON.stringify(fileInstallation)}`);
})();

Execution result: fileInstallationStore.fetchInstallation deletes user.token and user.scopes, but PrismaInstallationStore doesn't and return user1's token.

prismaInstallationStore.fetchInstallation: {"team":{"id":"team","name":"test"},"enterprise":{"id":"test"},"user":{"id":"user1","token":"userToken","scopes":[""]},"bot":{"id":"bot1","userId":"botUser1","token":"botToken","scopes":[""]},"tokenType":"bot","isEnterpriseInstall":false,"authVersion":"v2"}
fileInstallationStore.fetchInstallation: {"team":{"id":"team","name":"test"},"enterprise":{"id":"test"},"user":{"id":"user1"},"bot":{"id":"bot1","token":"botToken","scopes":[],"userId":"botUser1"}}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions