Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@slack/oauth

Package Overview
Dependencies
Maintainers
15
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slack/oauth - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

1

dist/errors.js

@@ -16,2 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthorizationError = exports.UnknownError = exports.MissingStateError = exports.GenerateInstallUrlError = exports.InstallerInitializationError = exports.ErrorCode = void 0;
/**

@@ -18,0 +19,0 @@ * A dictionary of codes for errors produced by this package.

6

dist/index.d.ts

@@ -75,6 +75,4 @@ /// <reference types="node" />

export interface InstallationStore {
storeInstallation<AuthVersion extends 'v1' | 'v2'>(installation: Installation<AuthVersion, false>, logger?: Logger): Promise<void>;
storeOrgInstallation?(installation: OrgInstallation, logger?: Logger): Promise<void>;
fetchInstallation: (query: InstallationQuery<false>, logger?: Logger) => Promise<Installation<'v1' | 'v2', false>>;
fetchOrgInstallation?: (query: OrgInstallationQuery, logger?: Logger) => Promise<OrgInstallation>;
storeInstallation<AuthVersion extends 'v1' | 'v2'>(installation: Installation<AuthVersion, boolean>, logger?: Logger): Promise<void>;
fetchInstallation: (query: InstallationQuery<boolean>, logger?: Logger) => Promise<Installation<'v1' | 'v2', boolean>>;
}

@@ -81,0 +79,0 @@ /**

@@ -50,2 +50,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.InstallProvider = void 0;
var jsonwebtoken_1 = require("jsonwebtoken");

@@ -120,6 +121,3 @@ var web_api_1 = require("@slack/web-api");

if (!source.isEnterpriseInstall) return [3 /*break*/, 2];
if (this.installationStore.fetchOrgInstallation === undefined) {
throw new Error('Installation Store is missing the fetchOrgInstallation method');
}
return [4 /*yield*/, this.installationStore.fetchOrgInstallation(source, this.logger)];
return [4 /*yield*/, this.installationStore.fetchInstallation(source, this.logger)];
case 1:

@@ -352,7 +350,3 @@ queryResult = _a.sent();

if (!installation.isEnterpriseInstall) return [3 /*break*/, 14];
if (this.installationStore.storeOrgInstallation === undefined) {
// TODO: make this a coded error
throw new Error('Installation store is missing the storeOrgInstallation method');
}
return [4 /*yield*/, this.installationStore.storeOrgInstallation(installation, this.logger)];
return [4 /*yield*/, this.installationStore.storeInstallation(installation, this.logger)];
case 13:

@@ -438,21 +432,14 @@ _b.sent();

}
if (isNotOrgInstall(installation)) {
this.devDB[installation.team.id] = installation;
}
else {
throw new Error('Failed saving installation data to installationStore');
}
return [2 /*return*/];
});
});
};
MemoryInstallationStore.prototype.storeOrgInstallation = function (installation, logger) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (logger !== undefined) {
logger.warn('Storing Access Token. Please use a real Installation Store for production!');
}
if (isOrgInstall(installation)) {
if (logger !== undefined) {
logger.debug('storing org installation');
}
this.devDB[installation.enterprise.id] = installation;
}
else if (isNotOrgInstall(installation)) {
if (logger !== undefined) {
logger.debug('storing single team installation');
}
this.devDB[installation.team.id] = installation;
}
else {

@@ -471,3 +458,14 @@ throw new Error('Failed saving installation data to installationStore');

}
if (query.isEnterpriseInstall) {
if (query.enterpriseId !== undefined) {
if (logger !== undefined) {
logger.debug('fetching org installation');
}
return [2 /*return*/, this.devDB[query.enterpriseId]];
}
}
if (query.teamId !== undefined) {
if (logger !== undefined) {
logger.debug('fetching single team installation');
}
return [2 /*return*/, this.devDB[query.teamId]];

@@ -479,15 +477,2 @@ }

};
MemoryInstallationStore.prototype.fetchOrgInstallation = function (query, logger) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (logger !== undefined) {
logger.warn('Retrieving Access Token from DB. Please use a real Installation Store for production!');
}
if (query.enterpriseId !== undefined) {
return [2 /*return*/, this.devDB[query.enterpriseId]];
}
throw new Error('Failed fetching installation');
});
});
};
return MemoryInstallationStore;

@@ -545,3 +530,3 @@ }());

var logger_2 = require("./logger");
exports.LogLevel = logger_2.LogLevel;
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_2.LogLevel; } });
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLogger = void 0;
var logger_1 = require("@slack/logger");
var logger_2 = require("@slack/logger");
exports.LogLevel = logger_2.LogLevel;
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_2.LogLevel; } });
var instanceCount = 0;

@@ -7,0 +8,0 @@ /**

{
"name": "@slack/oauth",
"version": "1.4.0",
"version": "2.0.0",
"description": "Official library for interacting with Slack's Oauth endpoints",

@@ -19,3 +19,4 @@ "author": "Slack Technologies, Inc.",

"engines": {
"node": ">=10.0.0"
"node": ">=12.13.0",
"npm": ">=6.12.0"
},

@@ -44,3 +45,3 @@ "repository": "slackapi/node-slack-sdk",

"@types/jsonwebtoken": "^8.3.7",
"@types/node": ">=6.0.0",
"@types/node": ">=12",
"jsonwebtoken": "^8.5.1",

@@ -65,5 +66,5 @@ "lodash.isstring": "^4.0.1"

"tslint-config-airbnb": "^5.11.1",
"typescript": "^3.5.1",
"typescript": "^4.1",
"uncaughtException": "^1.0.0"
}
}
# Slack OAuth
<!-- TODO: per-job badge https://github.com/bjfish/travis-matrix-badges/issues/4 -->
[![Build Status](https://travis-ci.org/slackapi/node-slack-sdk.svg?branch=master)](https://travis-ci.org/slackapi/node-slack-sdk)
[![build-ci](https://github.com/slackapi/node-slack-sdk/workflows/CI%20Build/badge.svg)](https://github.com/slackapi/node-slack-sdk/actions?query=workflow%3A%22CI+Build%22)
<!-- TODO: per-flag badge https://docs.codecov.io/docs/flags#section-flag-badges-and-graphs -->

@@ -35,6 +34,6 @@ [![codecov](https://codecov.io/gh/slackapi/node-slack-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/slackapi/node-slack-sdk)

This package exposes an `InstallProvider` class, which sets up the required configuration and exposes methods such as `generateInstallUrl`, `handleCallback`, `authorize`, `orgAuthorize` for use within your apps. At a minimum, `InstallProvider` takes a `clientId` and `clientSecret` (both which can be obtained under the **Basic Information** of your app configuration). `InstallProvider` also requires a `stateSecret`, which is used to encode the generated state, and later used to decode that same state to verify it wasn't tampered with during the OAuth flow. **Note**: This example is not ready for production because it only stores installations (tokens) in memory. Please go to the [storing installations in a database](#storing-installations-in-a-database) section to learn how to plug in your own database.
This package exposes an `InstallProvider` class, which sets up the required configuration and exposes methods such as `generateInstallUrl`, `handleCallback`, `authorize` for use within your apps. At a minimum, `InstallProvider` takes a `clientId` and `clientSecret` (both which can be obtained under the **Basic Information** of your app configuration). `InstallProvider` also requires a `stateSecret`, which is used to encode the generated state, and later used to decode that same state to verify it wasn't tampered with during the OAuth flow. **Note**: This example is not ready for production because it only stores installations (tokens) in memory. Please go to the [storing installations in a database](#storing-installations-in-a-database) section to learn how to plug in your own database.
```javascript
const { InstallProvider } = require('@slack/oauth');;
const { InstallProvider } = require('@slack/oauth');

@@ -55,3 +54,3 @@ // initialize the installProvider

```javascript
const { InstallProvider } = require('@slack/oauth');;
const { InstallProvider } = require('@slack/oauth');

@@ -167,6 +166,4 @@ // initialize the installProvider

An installation store is an object that provides four methods: `storeInstallation`, `storeOrgInstallation`, `fetchInstallation` and `fetchOrgInstallation`. `storeInstallation` and `storeOrgInstallation` takes an `installation` as an argument, which is an object that contains all installation related data (like tokens, teamIds, enterpriseIds, etc). `fetchInstallation` and `fetchOrgInstallation` takes in a `installQuery`, which is used to query the database. The `installQuery` can contain `teamId`, `enterpriseId`, `userId`, and `conversationId`.
An installation store is an object that provides two methods: `storeInstallation`, and `fetchInstallation`. `storeInstallation` takes an `installation` as an argument, which is an object that contains all installation related data (like tokens, teamIds, enterpriseIds, etc). `fetchInstallation` takes in a `installQuery`, which is used to query the database. The `installQuery` can contain `teamId`, `enterpriseId`, `userId`, `conversationId` and `isEnterpriseInstall`.
**Note**: `fetchOrgInstallation` and `storeOrgInstallation` were introduced to support Org wide app installations (currently in beta).
In the following example, the `installationStore` option is used and the object is defined in line. The methods are implemented by calling an example database library with simple get and set operations.

@@ -184,36 +181,26 @@

// replace myDB.set with your own database or OEM setter
if (installation.team.id !== undefined) {
// non enterprise org app installation
if (installation.isEnterpriseInstall) {
// support for org wide app installation
return myDB.set(installation.enterprise.id, installation);
} else {
// single team app installation
return myDB.set(installation.team.id, installation);
} else {
throw new Error('Failed saving installation data to installationStore');
}
throw new Error('Failed saving installation data to installationStore');
},
// takes in an installQuery as an argument
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string'};
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean};
// returns installation object from database
fetchInstallation: async (installQuery) => {
// replace myDB.get with your own database or OEM getter
// non enterprise org app lookup
return await myDB.get(installQuery.teamId);
},
// takes in an installation object as an argument
// returns nothing
storeOrgInstallation: async (installation) => {
// replace myDB.set with your own database or OEM setter
if (installation.isEnterpriseInstall && installation.enterprise !== undefined) {
// enterprise app, org wide installation
return myDB.set(installation.enterprise.id, installation);
} else {
throw new Error('Failed saving installation data to installationStore');
if (query.isEnterpriseInstall && query.enterpriseId !== undefined) {
// org wide app installation lookup
return await myDB.get(installQuery.enterpriseId);
}
if (query.teamId !== undefined) {
// single team app installation lookup
return await myDB.get(installQuery.teamId);
}
throw new Error('Failed fetching installation');
},
// takes in an installQuery as an argument
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string'};
// returns installation object from database
fetchInstallation: async (installQuery) => {
// replace myDB.get with your own database or OEM getter
// enterprise org app installation lookup
return await myDB.get(installQuery.enterpriseId);
},
},

@@ -226,9 +213,8 @@ });

You can use the the `installationProvider.authorize()` function to fetch data that has been saved in your installation store. For Org wide app installations, you can use `installationProvider.orgAuthorize()`
You can use the the `installationProvider.authorize()` function to fetch data that has been saved in your installation store.
```javascript
// installer.authorize takes in an installQuery as an argument
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string'};
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string', isEnterpriseInstall: boolean};
const result = installer.authorize({teamId: 'my-team-ID'});
const orgResult = installer.orgAuthorize({enterpriseId: 'my-enterprise-ID'});
/*

@@ -240,2 +226,4 @@ result = {

botUserId: '',
teamId: '';
enterpriseId: '';
}

@@ -250,10 +238,9 @@ */

The `installer.authorize()`/`installer.orgAuthorize()` methods only returns a subset of the installation data returned by the installation store. To fetch the entire saved installation, use the `installer.installationStore.fetchInstallation()`/`installer.installationStore.fetchOrgInstallation()` methods.
The `installer.authorize()` method only returns a subset of the installation data returned by the installation store. To fetch the entire saved installation, use the `installer.installationStore.fetchInstallation()` method.
```javascript
// installer.installationStore.fetchInstallation takes in an installQuery as an argument
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string'};
// installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean};
// returns an installation object
const result = await installer.installationStore.fetchInstallation({teamId:'my-team-ID', enterpriseId:'my-enterprise-ID'});
const orgResult = await installer.installationStore.fetchOrgInstallation({enterpriseId:'my-enterprise-ID'});
```

@@ -260,0 +247,0 @@ </details>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc