-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oauth): gated setup for intercom dual mode
- Loading branch information
Henry Fontanier
committed
Jul 19, 2024
1 parent
51ebbf6
commit 193c459
Showing
6 changed files
with
96 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
connectors/src/connectors/intercom/lib/intercom_access_token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { getOAuthConnectionAccessToken } from "@dust-tt/types"; | ||
|
||
import { apiConfig } from "@connectors/lib/api/config"; | ||
import { getAccessTokenFromNango } from "@connectors/lib/nango_helpers"; | ||
import { isDualUseOAuthConnectionId } from "@connectors/lib/oauth"; | ||
import logger from "@connectors/logger/logger"; | ||
|
||
const { NANGO_INTERCOM_CONNECTOR_ID } = process.env; | ||
|
||
export async function getIntercomAccessToken( | ||
connectionId: string | ||
): Promise<string> { | ||
if (isDualUseOAuthConnectionId(connectionId)) { | ||
const tokRes = await getOAuthConnectionAccessToken({ | ||
config: apiConfig.getOAuthAPIConfig(), | ||
logger, | ||
provider: "intercom", | ||
connectionId, | ||
}); | ||
if (tokRes.isErr()) { | ||
logger.error( | ||
{ connectionId, error: tokRes.error }, | ||
"Error retrieving Intercom access token" | ||
); | ||
throw new Error("Error retrieving Intercom access token"); | ||
} | ||
|
||
return tokRes.value.access_token; | ||
} else { | ||
// TODO(@fontanierh) INTERCOM_MIGRATION remove once migrated | ||
if (!NANGO_INTERCOM_CONNECTOR_ID) { | ||
throw new Error("NANGO_INTERCOM_CONNECTOR_ID is not defined"); | ||
} | ||
return getAccessTokenFromNango({ | ||
connectionId: connectionId, | ||
integrationId: NANGO_INTERCOM_CONNECTOR_ID, | ||
useCache: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.