Skip to content

Commit

Permalink
oauth: clean-up Slack post migration (#6362)
Browse files Browse the repository at this point in the history
* clean-up slac

* oauth: clean-up slack
  • Loading branch information
spolu authored Jul 19, 2024
1 parent 572bb16 commit 74710f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
10 changes: 1 addition & 9 deletions connectors/src/connectors/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import { ConnectorResource } from "@connectors/resources/connector_resource";
import { SlackConfigurationResource } from "@connectors/resources/slack_configuration_resource";
import type { DataSourceConfig } from "@connectors/types/data_source_config.js";

const { NANGO_SLACK_CONNECTOR_ID, SLACK_CLIENT_ID, SLACK_CLIENT_SECRET } =
process.env;
const { SLACK_CLIENT_ID, SLACK_CLIENT_SECRET } = process.env;

export class SlackConnectorManager extends BaseConnectorManager<SlackConfigurationType> {
static async create({
Expand Down Expand Up @@ -88,10 +87,6 @@ export class SlackConnectorManager extends BaseConnectorManager<SlackConfigurati
}: {
connectionId?: string | null;
}): Promise<Result<string, ConnectorsAPIError>> {
if (!NANGO_SLACK_CONNECTOR_ID) {
throw new Error("NANGO_SLACK_CONNECTOR_ID not set");
}

const c = await ConnectorResource.fetchById(this.connectorId);
if (!c) {
logger.error({ connectorId: this.connectorId }, "Connector not found");
Expand Down Expand Up @@ -719,9 +714,6 @@ export class SlackConnectorManager extends BaseConnectorManager<SlackConfigurati
}

export async function uninstallSlack(connectionId: string) {
if (!NANGO_SLACK_CONNECTOR_ID) {
throw new Error("NANGO_SLACK_CONNECTOR_ID is not defined");
}
if (!SLACK_CLIENT_ID) {
throw new Error("SLACK_CLIENT_ID is not defined");
}
Expand Down
47 changes: 16 additions & 31 deletions connectors/src/connectors/slack/lib/slack_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import type {
} from "@slack/web-api";
import { ErrorCode, WebClient } from "@slack/web-api";

import { apiConfig } from "@connectors/lib/api/config";
import {
ExternalOauthTokenError,
ProviderWorkflowError,
} from "@connectors/lib/error";
import { getAccessTokenFromNango } from "@connectors/lib/nango_helpers";
import { isDualUseOAuthConnectionId } from "@connectors/lib/oauth";
import { ConnectorResource } from "@connectors/resources/connector_resource";
const { NANGO_SLACK_CONNECTOR_ID } = process.env;
import { apiConfig } from "@connectors/lib/api/config";
import logger from "@connectors/logger/logger";
import { ConnectorResource } from "@connectors/resources/connector_resource";

// Timeout in ms for all network requests;
const SLACK_NETWORK_TIMEOUT_MS = 30000;
Expand Down Expand Up @@ -186,31 +183,19 @@ export async function getSlackConversationInfo(
export async function getSlackAccessToken(
connectionId: string
): Promise<string> {
if (isDualUseOAuthConnectionId(connectionId)) {
const tokRes = await getOAuthConnectionAccessToken({
config: apiConfig.getOAuthAPIConfig(),
logger,
provider: "slack",
connectionId,
});
if (tokRes.isErr()) {
logger.error(
{ connectionId, error: tokRes.error },
"Error retrieving Slack access token"
);
throw new Error("Error retrieving Slack access token");
}

return tokRes.value.access_token;
} else {
// TODO(spolu) SLACK_MIGRATION remove once migrated
if (!NANGO_SLACK_CONNECTOR_ID) {
throw new Error("NANGO_SLACK_CONNECTOR_ID is not defined");
}
return getAccessTokenFromNango({
connectionId: connectionId,
integrationId: NANGO_SLACK_CONNECTOR_ID,
useCache: true,
});
const tokRes = await getOAuthConnectionAccessToken({
config: apiConfig.getOAuthAPIConfig(),
logger,
provider: "slack",
connectionId,
});
if (tokRes.isErr()) {
logger.error(
{ connectionId, error: tokRes.error },
"Error retrieving Slack access token"
);
throw new Error("Error retrieving Slack access token");
}

return tokRes.value.access_token;
}

0 comments on commit 74710f9

Please sign in to comment.