Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fixes #1892 - add support for slack oauth v2
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown committed Mar 11, 2020
1 parent 61056cc commit e820414
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class FacebookAdapter extends BotAdapter {

this.middlewares = {
spawn: [
async (bot, next) => {
async (bot, next): Promise<void> => {
bot.api = await this.getAPI(bot.getConfig('activity'));
next();
}
Expand Down
5 changes: 5 additions & 0 deletions packages/botbuilder-adapter-slack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# botbuilder-adapter-slack changelog

# 1.0.9

* Update @slack/web-api to 5.8.0
* Add `oauthVersion` parameter to constructor. If set to `v2`, oauth features will use Slack's latest auth functions and urls.

# 1.0.8

* Update @slack/web-api to 5.7.0 which includes access to new Oauth features (see [#1890](https://github.com/howdyai/botkit/pull/1890))
Expand Down
4 changes: 2 additions & 2 deletions packages/botbuilder-adapter-slack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botbuilder-adapter-slack",
"version": "1.0.8",
"version": "1.0.9",
"description": "Connect Botkit or BotBuilder to Slack",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"url": "https://github.com/howdyai/botkit.git"
},
"dependencies": {
"@slack/web-api": "^5.7.0",
"@slack/web-api": "^5.8.0",
"botbuilder": "^4.7.1",
"botkit": "^4.6.2",
"debug": "^4.1.0"
Expand Down
32 changes: 20 additions & 12 deletions packages/botbuilder-adapter-slack/src/slack_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class SlackAdapter extends BotAdapter {
* clientId: process.env.CLIENT_ID, // oauth client id
* clientSecret: process.env.CLIENT_SECRET, // oauth client secret
* scopes: ['bot'], // oauth scopes requested
* oauthVersion: 'v1',
* redirectUri: process.env.REDIRECT_URI, // url to redirect post login defaults to `https://<mydomain>/install/auth`
* getTokenForTeam: async(team_id) => Promise<string>, // function that returns a token based on team id
* getBotUserByTeam: async(team_id) => Promise<string>, // function that returns a bot's user id based on team id
Expand Down Expand Up @@ -151,6 +152,11 @@ export class SlackAdapter extends BotAdapter {
debug('** Slack adapter running in multi-team mode.');
}

if (!this.options.oauthVersion) {
this.options.oauthVersion = 'v1';
}
this.options.oauthVersion = this.options.oauthVersion.toLowerCase();

if (this.options.enable_incomplete) {
const warning = [
'',
Expand Down Expand Up @@ -242,12 +248,11 @@ export class SlackAdapter extends BotAdapter {
* @returns A url pointing to the first step in Slack's oauth flow.
*/
public getInstallLink(): string {
let redirect = ''
let redirect = '';
if (this.options.clientId && this.options.scopes) {
if (this.options.oauthVersion == 'v2'|'V2'){
if (this.options.oauthVersion === 'v2') {
redirect = 'https://slack.com/oauth/v2/authorize?client_id=' + this.options.clientId + '&scope=' + this.options.scopes.join(',');
}
else {
} else {
redirect = 'https://slack.com/oauth/authorize?client_id=' + this.options.clientId + '&scope=' + this.options.scopes.join(',');
}
if (this.options.redirectUri) {
Expand Down Expand Up @@ -290,13 +295,12 @@ export class SlackAdapter extends BotAdapter {
client_id: this.options.clientId,
client_secret: this.options.clientSecret,
redirect_uri: this.options.redirectUri
}
let results = {};
if (this.options.oauthVersion == 'v2'|'V2'){
results = await slack.oauth.v2.access(details)
}
else {
results = await slack.oauth.access(details)
};
let results: any = {};
if (this.options.oauthVersion === 'v2') {
results = await slack.oauth.v2.access(details);
} else {
results = await slack.oauth.access(details);
}
if (results.ok) {
return results;
Expand Down Expand Up @@ -735,9 +739,13 @@ export interface SlackAdapterOptions {
*/
clientSecret?: string;
/**
* A an array of scope names that are being requested during the oauth process. Must match the scopes defined at api.slack.com
* A array of scope names that are being requested during the oauth process. Must match the scopes defined at api.slack.com
*/
scopes?: string[];
/**
* Which version of Slack's oauth protocol to use, v1 or v2. Defaults to v1.
*/
oauthVersion?: string;
/**
* The URL users will be redirected to after an oauth flow. In most cases, should be `https://<mydomain.com>/install/auth`
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/botbuilder-adapter-webex/src/webex_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class WebexAdapter extends BotAdapter {
// Botkit Plugin additions
this.middlewares = {
spawn: [
async (bot, next) => {
async (bot, next): Promise<void> => {
// make webex api directly available on a botkit instance.
bot.api = this._api;

Expand Down
1 change: 0 additions & 1 deletion packages/botkit/src/testClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export class BotkitTestClient {
return async (turnContext: TurnContext): Promise<void> => {
const dialogSet = new DialogSet(dialogState);
targetDialogs.forEach(targetDialog => dialogSet.add(targetDialog));

const dialogContext = await dialogSet.createContext(turnContext);
this.dialogTurnResult = await dialogContext.continueDialog();
if (this.dialogTurnResult.status === DialogTurnStatus.empty) {
Expand Down

0 comments on commit e820414

Please sign in to comment.