Skip to content

"Sign in with Slack" is unsupported by Bolt and its underlying OAuth module #1063

@justman00

Description

@justman00

Description

Currently, I am developing a slack app, build with bolt. I have implemented OAuth as suggested here. So, naturally bolt has created this endpoint /slack/install for installing and authorizing the slack app into a workspace, when I (the creator) click it and try to authorize it, it works perfectly fine, however from time to time with some small issuers, but when somebody else from the exterior does it, it always throws an error: Something went wrong when authorizing this app.. Logs:

[DEBUG]  web-api:WebClient:0 initialized
[DEBUG]  web-api:WebClient:0 apiCall('oauth.v2.access') start
[DEBUG]  web-api:WebClient:0 will perform http request
[DEBUG]  web-api:WebClient:0 http response received
[DEBUG]  web-api:WebClient:1 initialized
[DEBUG]  web-api:WebClient:1 apiCall('auth.test') start
[DEBUG]  web-api:WebClient:1 will perform http request
[DEBUG]  web-api:WebClient:1 http response received
[DEBUG]  web-api:WebClient:2 initialized
[DEBUG]  web-api:WebClient:2 apiCall('auth.test') start
[DEBUG]  web-api:WebClient:2 will perform http request
[DEBUG]  web-api:WebClient:2 http response received
[ERROR]  OAuth:InstallProvider:0 Error: An API error occurred: invalid_auth
    at Object.platformErrorFromResult (/path-to-/node_modules/@slack/web-api/dist/errors.js:51:33)
    at WebClient.apiCall (/path-to-/node_modules/node_modules/@slack/web-api/dist/WebClient.js:158:28)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'slack_webapi_platform_error',
  data: {
    ok: false,
    error: 'invalid_auth',
    response_metadata: { scopes: [Array] }
  }
}
[DEBUG]  OAuth:InstallProvider:0 calling passed in options.failure

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

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

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

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

Bug Report

Here is the code:

import { App, LogLevel, ExpressReceiver } from '@slack/bolt';
import { Low, JSONFile } from 'lowdb';
import { join } from 'path';
import { sendWelcomeMessage } from './views/messages.js';
import { createUserProfile } from './auth/authGetTilo.js';
import { newUserHomePage } from './views/homePage.js';

const file = join('./db.json');
const adapter = new JSONFile(file);
const db = new Low(adapter);

const receiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  logLevel: LogLevel.DEBUG,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  stateSecret: 'someStateSecret',
  scopes: ['commands', 'chat:write'],
  installationStore: {
    storeInstallation: async (installation) => {
      // change the line below so it saves to your database
      console.log('installation', installation);
      await db.read();
      db.data = db.data || {};
      db.data.installation = installation;
      await db.write();
      // save to db

      sendWelcomeMessage(app, installation);
      createUserProfile(app, installation, db)
    },
    fetchInstallation: async (installQuery) => {
      // change the line below so it fetches from your database
      console.log('installQuery', installQuery);
      await db.read();
      if (db.data.installation) {
        return db.data.installation;
      }

      throw new Error('Failed fetching installation');
    },
    deleteInstallation: async (installQuery) => {
      // change the line below so it deletes from your database
    },
  },
  installerOptions: {
    userScopes: ['identity.basic', 'identity.email'],
    callbackOptions: {
      success: (installation, installOptions, req, res) => {
        res.end('success');
      },
      failure: (error, installOptions, req, res) => {
        res.end('failure');
      },
    },
  },
});

const app = new App({ receiver });

// All the room in the world for your code
app.event('app_home_opened', params => newUserHomePage(params, db));

(async () => {
  // Start your app
  await app.start(process.env.PORT || 3000);

  console.log('⚡️ Bolt app is running!');
})();

please ignore the LowDB part, it's just for testing

Reproducible in:

package version: "^3.5.0"

node version: v14.13.1

OS version(s): macOS Big Sur

Expected result:

Users are able to correctly authorize the app

Actual result:

An error is being thrown, without any message on how to solve it

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionM-T: An issue where more input is needed to reach a decisionenhancementM-T: A feature request for new functionality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions