bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

Authorization of incoming event did not succeed with Bolt OAuth

Open stephaniel96 opened this issue 5 years ago • 8 comments

Description

I'm using the built-in Bolt OAuth on version 3.2.0. The installation store logic is correctly executing, but once I install my app to a workspace and try to take an action (e.g. opening a modal), I get this error:

[WARN]  bolt-app Authorization of incoming event did not succeed. No listeners will be called.
[ERROR]  bolt-app Error: Cannot read property 'token' of undefined

I recognize that https://github.com/slackapi/bolt-js/issues/567 describes a similar issue, but I am correctly adding the app from the slack/install endpoint and have set theredirect_url in the Oauth tab. I've gone through all the documentation but it seems like I'm missing something. My code is here:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  stateSecret: "a-secret",
  scopes: [
    "commands",
    "chat:write",
    "channels:read",
    "users:read",
    "channels:manage",
  ],
  installationStore: {
    storeInstallation: async (installation: any) => {
      try {
        if (installation.isEnterpriseInstall) {
          return await appService.createInstallation(
            installation.enterprise.id,
            installation
          );
        } else {
          return await appService.createInstallation(
            installation.team.id,
            installation
          );
        }
      } catch (er) {
        console.error("Failed saving installation data to installationStore");
      }
    },
    fetchInstallation: async (installQuery: any) => {
      if (
        installQuery.isEnterpriseInstall &&
        installQuery.enterpriseId !== undefined
      ) {
        return await appService.getInstallation(installQuery.enterpriseId);
      }
      if (installQuery.teamId !== undefined) {
        return await appService.getInstallation(installQuery.teamId);
      }
      throw new Error("Failed fetching installation");
    },
  },
});

// Code for handling opening the modal
app.shortcut(
  "open_modal",
  async ({
    shortcut,
    ack,
    client,
  }: {
    shortcut: any;
    ack: any;
    client: any;
  }) => {
    try {
      await ack();

      await client.views.open({
        trigger_id: shortcut.trigger_id,
        view: {
                  title: {
                    type: "plain_text",

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] example code related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version:

node version:

OS version(s):

Steps to reproduce:

1. 2. 3.

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

stephaniel96 avatar Feb 24 '21 22:02 stephaniel96

Ah, it turns out that I wasn't properly returning the installation object. Nevermind!

stephaniel96 avatar Feb 24 '21 22:02 stephaniel96

What is the correct structure? I am having this exact same issue and can't find any docs on what the installation object is supposed to look like.

6lick avatar Jan 27 '22 08:01 6lick

@6lick Please refer to the type definition in the underlying package: https://github.com/slackapi/node-slack-sdk/blob/%40slack/oauth%402.4.0/packages/oauth/src/index.ts#L645-L720

seratch avatar Jan 27 '22 08:01 seratch

Thank you- is user.token supposed to always have a value?

6lick avatar Jan 27 '22 09:01 6lick

@6lick No, it can exist only when your app installation has user scopes. By the way, this issue is already closed. Please feel free to create a new question issue if you have more to ask!

seratch avatar Jan 27 '22 09:01 seratch

Ok thats what I thought... then I am very confused what is wrong with my implementation. Will have to open up a new issue.

6lick avatar Jan 27 '22 09:01 6lick

@stephaniel96 you said you weren't correctly returning the installation object, could you tell us how you fixed this? What the object you are returning looks like? Seems as if me and @6lick aren't returning it correctly either, and I'm sure that means many other lurkers aren't either...

nhayling avatar Jul 30 '22 06:07 nhayling

Hi guys! I'm also experiencing the exact same issue lol. Was there a solution for that? The installation object I'm returning looks like this:

const installation: Installation<"v1" | "v2"> = {
    team: {
      id: "some-id",
      name: "some-name"
    },
    enterprise: {
      id: "some-id",
      name: "some-name"
    },
    user: {
      token: "token-that-was-received-from-code-grant-flow",
      id: "user-id",
      scopes: "scopes",
    },
  };

david1542 avatar Apr 25 '24 12:04 david1542