Skip to content

Commit

Permalink
feat: Intercom OAuth Integration (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-bhansali authored Sep 30, 2024
1 parent 58a9ce2 commit d64af29
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
35 changes: 35 additions & 0 deletions integrationos-oauth/src/connections/intercom/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import axios from 'axios';
import { DataObject, OAuthResponse } from '../../lib/types';

export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
clientId: client_id,
clientSecret: client_secret,
metadata: { code },
} = body;

const response = await axios({
url: 'https://api.intercom.io/auth/eagle/token',
method: 'POST',
params: {
code,
client_id,
client_secret,
},
});

const { access_token: accessToken, token_type: tokenType } =
response.data;

return {
accessToken,
refreshToken: '',
expiresIn: 2147483647,
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
meta: {},
};
} catch (error) {
throw new Error(`Error fetching access token for Intercom: ${error}`);
}
};
19 changes: 19 additions & 0 deletions integrationos-oauth/src/connections/intercom/refresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DataObject, OAuthResponse } from '../../lib/types';

export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
OAUTH_METADATA: { accessToken, refreshToken, tokenType, meta },
} = body;

return {
accessToken,
refreshToken,
expiresIn: 2147483647,
tokenType,
meta,
};
} catch (error) {
throw new Error(`Error fetching access token for Intercom: ${error}`);
}
};

0 comments on commit d64af29

Please sign in to comment.