-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #977 Add a way to turn off web page rendering for "/slack/install" #1079
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
657b94b
Fix #977 Add a way to turn off web page rendering for "/slack/install"
seratch 70a8525
Remove package-lock.json from the example app
seratch a2bfbd0
Apply suggestions from code review
seratch fec8b60
Add bolt to dependencies
seratch 62eafc3
Comment out the new flag in the example app
seratch 516d5b7
Rename directInstallUrlEnabled to directInstall
seratch c1c7b9c
Apply suggestions from code review
seratch File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# node / npm | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Bolt for JavaScript OAuth Test App | ||
|
||
This is a quick example app to test [OAuth](https://api.slack.com/authentication/oauth-v2) with Bolt for JavaScript. | ||
|
||
If using OAuth, Slack requires a public URL where it can send requests. In this guide, we'll be using [`ngrok`](https://ngrok.com/download). Checkout [this guide](https://api.slack.com/tutorials/tunneling-with-ngrok) for setting it up. OAuth installation is only needed for public distribution. For internal apps, we recommend installing via your app configuration. | ||
|
||
Before we get started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create). You also need to [create a new app](https://api.slack.com/apps?new_app=1) if you haven’t already. You will need to enable Socket Mode and generate an App Level Token. | ||
|
||
## Install Dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Setup Environment Variables | ||
|
||
This app requires you setup a few environment variables. You can find these values in your [app configuration](https://api.slack.com/apps). | ||
|
||
```bash | ||
export SLACK_CLIENT_ID=YOUR_SLACK_CLIENT_ID | ||
export SLACK_CLIENT_SECRET=YOUR_SLACK_CLIENT_SECRET | ||
export SLACK_SIGNING_SECRET=YOUR_SLACK_SIGNING_SECRET | ||
``` | ||
|
||
## Run the App | ||
|
||
Start the app with the following command: | ||
|
||
``` | ||
npm start | ||
``` | ||
|
||
### Running with OAuth | ||
|
||
Only implement OAuth if you plan to distribute your application across multiple workspaces. Uncomment out the OAuth specific comments in the code. If you are on dev instance, you will have to uncomment out those options as well. | ||
|
||
Start `ngrok` so we can access the app on an external network and create a redirect URL for OAuth. | ||
|
||
``` | ||
ngrok http 3000 | ||
``` | ||
|
||
This output should include a forwarding address for `http` and `https` (we'll use the `https` one). It should look something like the following: | ||
|
||
``` | ||
Forwarding https://3cb89939.ngrok.io -> http://localhost:3000 | ||
``` | ||
|
||
Then navigate to **OAuth & Permissions** in your app configuration and click **Add a Redirect URL**. The redirect URL should be set to your `ngrok` forwarding address with the `slack/oauth_redirect` path appended. ex: | ||
|
||
``` | ||
https://3cb89939.ngrok.io/slack/oauth_redirect | ||
``` | ||
|
||
Start the OAuth flow from https://{your own subdomain}.ngrok.io/slack/install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const { App, LogLevel } = require('@slack/bolt'); | ||
|
||
const databaseData = {}; | ||
const database = { | ||
set: async (key, data) => { | ||
databaseData[key] = data | ||
}, | ||
get: async (key) => { | ||
return databaseData[key]; | ||
}, | ||
}; | ||
|
||
const app = new App({ | ||
logLevel: LogLevel.DEBUG, | ||
signingSecret: process.env.SLACK_SIGNING_SECRET, | ||
clientId: process.env.SLACK_CLIENT_ID, | ||
clientSecret: process.env.SLACK_CLIENT_SECRET, | ||
stateSecret: 'my-state-secret', | ||
scopes: ['chat:write'], | ||
installationStore: { | ||
storeInstallation: async (installation) => { | ||
// change the line below so it saves to your database | ||
if (installation.isEnterpriseInstall && installation.enterprise !== undefined) { | ||
// support for org wide app installation | ||
return await database.set(installation.enterprise.id, installation); | ||
} | ||
if (installation.team !== undefined) { | ||
// single team app installation | ||
return await database.set(installation.team.id, installation); | ||
} | ||
throw new Error('Failed saving installation data to installationStore'); | ||
}, | ||
fetchInstallation: async (installQuery) => { | ||
// change the line below so it fetches from your database | ||
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { | ||
// org wide app installation lookup | ||
return await database.get(installQuery.enterpriseId); | ||
} | ||
if (installQuery.teamId !== undefined) { | ||
// single team app installation lookup | ||
return await database.get(installQuery.teamId); | ||
} | ||
throw new Error('Failed fetching installation'); | ||
}, | ||
deleteInstallation: async (installQuery) => { | ||
// change the line below so it deletes from your database | ||
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { | ||
// org wide app installation deletion | ||
return await database.delete(installQuery.enterpriseId); | ||
} | ||
if (installQuery.teamId !== undefined) { | ||
// single team app installation deletion | ||
return await database.delete(installQuery.teamId); | ||
} | ||
throw new Error('Failed to delete installation'); | ||
}, | ||
}, | ||
installerOptions: { | ||
// If this is true, /slack/install redirects installers to the Slack authorize URL | ||
// without rendering the web page with "Add to Slack" button. | ||
// This flag is available in @slack/bolt v3.7 or higher | ||
// directInstall: true, | ||
} | ||
}); | ||
|
||
(async () => { | ||
await app.start(process.env.PORT || 3000); | ||
console.log('⚡️ Bolt app started'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
current_dir=`dirname $0` | ||
cd ${current_dir} | ||
npm unlink @slack/bolt \ | ||
&& npm i \ | ||
&& cd ../.. \ | ||
&& npm link \ | ||
&& cd - \ | ||
&& npm i \ | ||
&& npm link @slack/bolt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "bolt-oauth-example", | ||
"version": "1.0.0", | ||
"description": "Example app using OAuth", | ||
"main": "app.js", | ||
"scripts": { | ||
"start": "node app.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Slack Technologies, Inc.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@slack/bolt": "^3.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the installer option would be available in 3.7.0 release, it's probably okay with the
^
, but since you've pointed out already that the flag is available to 3.7.0 and on perhaps this should be^3.7.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the flag is commented out now, the example app works even with v3.6.0. I am using
npm link
for verifying the behavior with the flag. Once we release v3.7, we can upgrade the minimum version here.