diff --git a/examples/legacy-sign-in-with-slack/app.js b/examples/legacy-sign-in-with-slack/app.js deleted file mode 100644 index 56526392d..000000000 --- a/examples/legacy-sign-in-with-slack/app.js +++ /dev/null @@ -1,115 +0,0 @@ -// https://api.slack.com/legacy/sign-in-with-slack -const Koa = require('koa'); -const Router = require('@koa/router'); -const { WebClient } = require('@slack/web-api'); -const uuid = require('uuid'); - -const app = new Koa(); -const router = new Router(); - -router.get('/', async (ctx) => { - ctx.redirect('/slack/install'); -}); - -const clientId = process.env.SLACK_CLIENT_ID; -const clientSecret = process.env.SLACK_CLIENT_SECRET; -const legacyIdentityScopes = 'identity.basic,identity.email'; // identity.basic is required at least - -class MyStateStore { - constructor() { - this.activeStates = {}; - } - async generate() { - const newValue = uuid.v4(); - this.activeStates[newValue] = Date.now() + 10 * 60 * 1000; // 10 minutes - return newValue; - } - async validate(state) { - const expiresAt = this.activeStates[state]; - if (expiresAt && Date.now() <= expiresAt) { - delete this.activeStates[state]; - return true; - } - return false; - } -} -const myStateStore = new MyStateStore(); - -router.get('/slack/install', async (ctx) => { - const state = await myStateStore.generate(); - const url = `https://slack.com/oauth/v2/authorize?state=${state}&client_id=${clientId}&user_scope=${legacyIdentityScopes}`; - - ctx.headers['content-type'] = 'text/html; charset=utf-8'; - ctx.body = ` -
- -Try again from here
- - `; - return; - } - - const token = await client.oauth.v2.access({ - client_id: clientId, - client_secret: clientSecret, - code: ctx.query.code, - }); - console.log(`oauth.v2.access response: ${JSON.stringify(token, null, 2)}`); - - let userAccessToken = token.authed_user.access_token; - - if (token.refresh_token) { - // token.refresh_token can exist if the token rotation is enabled. - // The following lines of code demonstrate how to refresh the token. - // If you don't enable token rotation, you can safely remove this part. - const refreshedToken = await client.oauth.v2.access({ - client_id: clientId, - client_secret: clientSecret, - grant_type: 'refresh_token', - refresh_token: token.refresh_token, - }); - console.log(`oauth.v2.access (refresh) response: ${JSON.stringify(refreshedToken, null, 2)}`); - userAccessToken = refreshedToken.access_token; - } - - // TODO: you can do something meaningful here - // (e.g., storing the data in database + navigating the user to your service top paeg) - - // The is a quick example demonstrating how to perform users.identity with the given access token. - // You don't need to do this here. - const tokenWiredClient = new WebClient(userAccessToken); - const userInfo = await tokenWiredClient.users.identity(); - console.log(`users.identity response: ${JSON.stringify(userInfo, null, 2)}`); - - ctx.headers['content-type'] = 'text/html; charset=utf-8'; - ctx.body = ` - - -${JSON.stringify(userInfo, null, 2)}- - `; -}); - -// Enable the routes -app.use(router.routes()).use(router.allowedMethods()); -// Start the web app, which is available at http://localhost:3000/slack/* -app.listen(3000, () => { - console.log('app started'); -}); diff --git a/examples/legacy-sign-in-with-slack/app_manifest.yml b/examples/legacy-sign-in-with-slack/app_manifest.yml deleted file mode 100644 index c9ec8fe97..000000000 --- a/examples/legacy-sign-in-with-slack/app_manifest.yml +++ /dev/null @@ -1,12 +0,0 @@ -_metadata: - major_version: 1 - minor_version: 1 -display_information: - name: legacy-sign-in-with-slack -oauth_config: - redirect_urls: - - https://your-own-one.ngrok.io/slack/oauth_redirect - scopes: - user: - - identity.basic - - identity.email diff --git a/examples/legacy-sign-in-with-slack/link.sh b/examples/legacy-sign-in-with-slack/link.sh deleted file mode 100755 index 1f45ddaa6..000000000 --- a/examples/legacy-sign-in-with-slack/link.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -current_dir=`dirname $0` -cd ${current_dir} -npm unlink @slack/web-api \ - && npm i \ - && cd ../../packages/web-api \ - && npm link \ - && cd - \ - && npm i \ - && npm link @slack/web-api diff --git a/examples/legacy-sign-in-with-slack/package.json b/examples/legacy-sign-in-with-slack/package.json deleted file mode 100644 index 28e1b1825..000000000 --- a/examples/legacy-sign-in-with-slack/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "legacy-sign-in-with-slack-example", - "version": "1.0.0", - "description": "", - "main": "app.js", - "scripts": { - "start": "node app.js" - }, - "author": "Slack Technologies, LLC", - "license": "MIT", - "repository": "slackapi/node-slack-sdk", - "dependencies": { - "@koa/router": "^13.0.0", - "@slack/bolt": "^3.21.2", - "koa": "^2.13.1", - "uuid": "^11.0.2" - } -}