-
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: added sage accounting oauth endpoints
- Loading branch information
1 parent
249acde
commit 8586636
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
integrationos-platform-oauth/src/connections/sageAccounting/init.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 axios from "axios"; | ||
import { DataObject, OAuthResponse } from "../../lib/types"; | ||
|
||
export const init = async ({ body }: DataObject): Promise<OAuthResponse> => { | ||
try { | ||
const requestBody = { | ||
grant_type: "authorization_code", | ||
code: body.metadata?.code, | ||
client_id: body.clientId, | ||
client_secret: body.clientSecret, | ||
redirect_uri: body.metadata?.redirectUri, | ||
}; | ||
|
||
const response = await axios.post( | ||
`https://oauth.accounting.sage.com/token`, | ||
requestBody | ||
); | ||
|
||
const { | ||
data: { | ||
access_token: accessToken, | ||
refresh_token: refreshToken, | ||
expires_in: expiresIn, | ||
requested_by_id: requestedById, | ||
}, | ||
} = response; | ||
|
||
return { | ||
accessToken, | ||
refreshToken, | ||
expiresIn, | ||
tokenType: '', | ||
meta: { | ||
requestedById, | ||
}, | ||
}; | ||
} catch (error) { | ||
throw new Error(`Error fetching access token for SageAccounting: ${error}`); | ||
} | ||
}; |
45 changes: 45 additions & 0 deletions
45
integrationos-platform-oauth/src/connections/sageAccounting/refresh.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,45 @@ | ||
import axios from "axios"; | ||
|
||
import { DataObject, OAuthResponse } from "../../lib/types"; | ||
export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => { | ||
try { | ||
const { | ||
OAUTH_CLIENT_ID: client_id, | ||
OAUTH_CLIENT_SECRET: client_secret, | ||
OAUTH_REFRESH_TOKEN: refresh_token, | ||
} = body; | ||
|
||
const requestBody = { | ||
grant_type: "refresh_token", | ||
client_id, | ||
client_secret, | ||
refresh_token, | ||
}; | ||
|
||
const response = await axios.post( | ||
`https://oauth.accounting.sage.com/token`, | ||
requestBody | ||
); | ||
|
||
const { | ||
data: { | ||
access_token: accessToken, | ||
refresh_token: refreshToken, | ||
expires_in: expiresIn, | ||
requested_by_id: requestedById, | ||
}, | ||
} = response; | ||
|
||
return { | ||
accessToken, | ||
refreshToken, | ||
expiresIn, | ||
tokenType: "", | ||
meta: { | ||
requestedById, | ||
}, | ||
}; | ||
} catch (error) { | ||
throw new Error(`Error fetching access token for SageAccounting: ${error}`); | ||
} | ||
}; |