@slack/oauth
Advanced tools
Comparing version 1.1.0 to 1.2.0
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { WebClientOptions } from '@slack/web-api'; | ||
import { CodedError } from './errors'; | ||
@@ -23,3 +24,5 @@ import { Logger, LogLevel } from './logger'; | ||
private logger; | ||
constructor({ clientId, clientSecret, stateSecret, stateStore, installationStore, authVersion, logger, logLevel, }: InstallProviderOptions); | ||
private clientOptions; | ||
private authorizationUrl; | ||
constructor({ clientId, clientSecret, stateSecret, stateStore, installationStore, authVersion, logger, logLevel, clientOptions, authorizationUrl, }: InstallProviderOptions); | ||
/** | ||
@@ -45,3 +48,3 @@ * Fetches data from the installationStore. | ||
} | ||
interface InstallProviderOptions { | ||
export interface InstallProviderOptions { | ||
clientId: string; | ||
@@ -55,2 +58,4 @@ clientSecret: string; | ||
logLevel?: LogLevel; | ||
clientOptions?: Omit<WebClientOptions, 'logLevel' | 'logger'>; | ||
authorizationUrl?: string; | ||
} | ||
@@ -57,0 +62,0 @@ export interface InstallURLOptions { |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -57,3 +68,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
function InstallProvider(_a) { | ||
var clientId = _a.clientId, clientSecret = _a.clientSecret, _b = _a.stateSecret, stateSecret = _b === void 0 ? undefined : _b, _c = _a.stateStore, stateStore = _c === void 0 ? undefined : _c, _d = _a.installationStore, installationStore = _d === void 0 ? new MemoryInstallationStore() : _d, _e = _a.authVersion, authVersion = _e === void 0 ? 'v2' : _e, _f = _a.logger, logger = _f === void 0 ? undefined : _f, _g = _a.logLevel, logLevel = _g === void 0 ? logger_1.LogLevel.INFO : _g; | ||
var clientId = _a.clientId, clientSecret = _a.clientSecret, _b = _a.stateSecret, stateSecret = _b === void 0 ? undefined : _b, _c = _a.stateStore, stateStore = _c === void 0 ? undefined : _c, _d = _a.installationStore, installationStore = _d === void 0 ? new MemoryInstallationStore() : _d, _e = _a.authVersion, authVersion = _e === void 0 ? 'v2' : _e, _f = _a.logger, logger = _f === void 0 ? undefined : _f, _g = _a.logLevel, logLevel = _g === void 0 ? logger_1.LogLevel.INFO : _g, _h = _a.clientOptions, clientOptions = _h === void 0 ? {} : _h, _j = _a.authorizationUrl, authorizationUrl = _j === void 0 ? 'https://slack.com/oauth/v2/authorize' : _j; | ||
if (clientId === undefined || clientSecret === undefined) { | ||
@@ -88,2 +99,10 @@ throw new errors_1.InstallerInitializationError('You must provide a valid clientId and clientSecret'); | ||
this.authVersion = authVersion; | ||
this.authorizationUrl = authorizationUrl; | ||
if (authorizationUrl !== 'https://slack.com/oauth/v2/authorize' && authVersion === 'v1') { | ||
this.logger.info('You provided both an authorizationUrl and an authVersion! The authVersion will be ignored in favor of the authorizationUrl.'); | ||
} | ||
else if (authVersion === 'v1') { | ||
this.authorizationUrl = 'https://slack.com/oauth/authorize'; | ||
} | ||
this.clientOptions = __assign({ logLevel: this.logger.getLevel() }, clientOptions); | ||
} | ||
@@ -132,6 +151,3 @@ /** | ||
case 0: | ||
slackURL = new url_1.URL('https://slack.com/oauth/v2/authorize'); | ||
if (this.authVersion === 'v1') { | ||
slackURL.href = 'https://slack.com/oauth/authorize'; | ||
} | ||
slackURL = new url_1.URL(this.authorizationUrl); | ||
if (options.scopes === undefined) { | ||
@@ -208,3 +224,3 @@ throw new errors_1.GenerateInstallUrlError('You must provide a scope parameter when calling generateInstallUrl'); | ||
installOptions = _a.sent(); | ||
client = new web_api_1.WebClient(); | ||
client = new web_api_1.WebClient('', this.clientOptions); | ||
resp = void 0; | ||
@@ -233,3 +249,3 @@ installation = void 0; | ||
if (!(resp.bot !== undefined)) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, getBotId(resp.bot.bot_access_token)]; | ||
return [4 /*yield*/, getBotId(resp.bot.bot_access_token, this.clientOptions)]; | ||
case 3: | ||
@@ -260,3 +276,3 @@ botId = _a.sent(); | ||
resp = (_a.sent()); | ||
return [4 /*yield*/, getBotId(resp.access_token)]; | ||
return [4 /*yield*/, getBotId(resp.access_token, this.clientOptions)]; | ||
case 7: | ||
@@ -411,3 +427,3 @@ botId = _a.sent(); | ||
// Gets the bot_id using the `auth.test` method. | ||
function getBotId(token) { | ||
function getBotId(token, clientOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -418,3 +434,3 @@ var client, authResult; | ||
case 0: | ||
client = new web_api_1.WebClient(token); | ||
client = new web_api_1.WebClient(token, clientOptions); | ||
return [4 /*yield*/, client.auth.test()]; | ||
@@ -421,0 +437,0 @@ case 1: |
{ | ||
"name": "@slack/oauth", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Official library for interacting with Slack's Oauth endpoints", | ||
@@ -35,3 +35,5 @@ "author": "Slack Technologies, Inc.", | ||
"test": "nyc mocha --config .mocharc.json src/*.spec.js", | ||
"coverage": "codecov -F oauthhelper --root=$PWD" | ||
"coverage": "codecov -F oauthhelper --root=$PWD", | ||
"ref-docs:model": "api-extractor run", | ||
"watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm run build" | ||
}, | ||
@@ -48,2 +50,3 @@ "dependencies": { | ||
"@types/chai": "^4.2.11", | ||
"@microsoft/api-extractor": "^7.3.4", | ||
"chai": "^4.2.0", | ||
@@ -50,0 +53,0 @@ "codecov": "^3.0.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
68201
705
17