Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oauth: clean-up Slack post migration #6362

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit would be nice to migrate those ones to the config pattern.


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;
}
Loading