diff --git a/core/oauth/package.json b/core/oauth/package.json index d73aa2e3..04dc507d 100644 --- a/core/oauth/package.json +++ b/core/oauth/package.json @@ -25,11 +25,13 @@ "dotenv": "^16.4.5", "express": "^4.19.2", "handlebars": "^4.7.8", - "jsonwebtoken": "^9.0.2" + "jsonwebtoken": "^9.0.2", + "qs": "^6.13.0" }, "devDependencies": { "@types/express": "^4.17.21", "@types/jsonwebtoken": "^9.0.6", + "@types/qs": "^6.9.17", "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", "eslint": "^8.20.0", diff --git a/core/oauth/src/connections/jira/init.ts b/core/oauth/src/connections/jira/init.ts index 94a9532d..51b949d9 100644 --- a/core/oauth/src/connections/jira/init.ts +++ b/core/oauth/src/connections/jira/init.ts @@ -12,7 +12,10 @@ export const init = async ({ body }: DataObject): Promise => { const response = await axios({ url: 'https://auth.atlassian.com/oauth/token', method: 'POST', - params: { + headers: { + 'Content-Type': 'application/json', + }, + data: { grant_type: 'authorization_code', code, client_id, diff --git a/core/oauth/src/connections/jira/refresh.ts b/core/oauth/src/connections/jira/refresh.ts index aeea41e4..7116e4f0 100644 --- a/core/oauth/src/connections/jira/refresh.ts +++ b/core/oauth/src/connections/jira/refresh.ts @@ -13,7 +13,10 @@ export const refresh = async ({ body }: DataObject): Promise => { const response = await axios({ url: 'https://auth.atlassian.com/oauth/token', method: 'POST', - params: { + headers: { + 'Content-Type': 'application/json', + }, + data: { grant_type: 'refresh_token', refresh_token, client_id, diff --git a/core/oauth/src/connections/zoho/init.ts b/core/oauth/src/connections/zoho/init.ts index 638edac8..fd94175b 100644 --- a/core/oauth/src/connections/zoho/init.ts +++ b/core/oauth/src/connections/zoho/init.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import qs from 'qs'; import { DataObject, OAuthResponse } from '../../lib/types'; export const init = async ({ body }: DataObject): Promise => { @@ -14,11 +15,22 @@ export const init = async ({ body }: DataObject): Promise => { additionalData['accounts-server'], ); - let url = `${ZOHO_ACCOUNTS_DOMAIN}/oauth/v2/token?grant_type=authorization_code`; - url += `&client_id=${clientId}&client_secret=${clientSecret}`; - url += `&code=${code}&redirect_uri=${redirectUri}`; + const requestBody = { + grant_type: 'authorization_code', + client_id: clientId, + client_secret: clientSecret, + code, + redirect_uri: redirectUri, + }; - const response = await axios.post(url); + const response = await axios({ + url: `${ZOHO_ACCOUNTS_DOMAIN}/oauth/v2/token`, + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + data: qs.stringify(requestBody), + }); const { data: { diff --git a/core/oauth/src/connections/zoho/refresh.ts b/core/oauth/src/connections/zoho/refresh.ts index 899288a7..dbfec04b 100644 --- a/core/oauth/src/connections/zoho/refresh.ts +++ b/core/oauth/src/connections/zoho/refresh.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import qs from 'qs'; import { DataObject, OAuthResponse } from '../../lib/types'; export const refresh = async ({ body }: DataObject): Promise => { @@ -13,10 +14,21 @@ export const refresh = async ({ body }: DataObject): Promise => { let refreshToken = refresh_token; const ZOHO_ACCOUNTS_DOMAIN = meta.ZOHO_ACCOUNTS_DOMAIN; - let url = `${ZOHO_ACCOUNTS_DOMAIN}/oauth/v2/token?grant_type=refresh_token`; - url += `&client_id=${client_id}&client_secret=${client_secret}&refresh_token=${refresh_token}`; + const requestBody = { + grant_type: 'refresh_token', + client_id, + client_secret, + refresh_token, + }; - const response = await axios.post(url); + const response = await axios({ + url: `${ZOHO_ACCOUNTS_DOMAIN}/oauth/v2/token`, + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + data: qs.stringify(requestBody), + }); const { data: {