-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Intercom OAuth Integration (#167)
- Loading branch information
1 parent
58a9ce2
commit d64af29
Showing
2 changed files
with
54 additions
and
0 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
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}`); | ||
} | ||
}; |
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,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}`); | ||
} | ||
}; |