fix: temporary adjustment for Salesforce OAuth2 template handling

master
adriano 2024-09-24 10:23:08 -03:00
parent 75659672bf
commit 6691427b37
1 changed files with 34 additions and 18 deletions

View File

@ -133,16 +133,32 @@ const oauthCallBack = async (req, res) => {
client_id: crmOauth.crm.authentication.crmClientId, client_id: crmOauth.crm.authentication.crmClientId,
client_secret: crmOauth.crm.authentication.crmClientSecret, client_secret: crmOauth.crm.authentication.crmClientSecret,
redirect_uri: process.env.URL_OAUTH_CALLBACK, redirect_uri: process.env.URL_OAUTH_CALLBACK,
code
}
//remove this // Refactor this. This is for salesforce only oauth2 that need a code_verifier. Try to find another
// refactor this. To salesforce only when using oauth2 // way of gettig the code without need the code_verifier
const rest = crmOauth.crm.crmRest
const salesforceUrls = rest.map(endpoint => {
const key = Object.keys(endpoint)[0]
const url = endpoint[key].request.url
if (url.includes("salesforce")) {
return `${key} URL: ${url}`
}
}).filter(Boolean)
if (salesforceUrls.find(url => url.includes('salesforce'))) {
authCodeProof = {
...authCodeProof, ...{
code_verifier: `gwkPueV2GSzkFvGFiHbNjpRuq_XBEGBsihM59pMaiFalZrOQ_7J4hgtBR8GIbLHutcuUwba2k0xeKhD8ELjWEswE3xv-H2e6Jh8EOwOccj2i_rYPUlMGdPDqpuRs8D3w`, code_verifier: `gwkPueV2GSzkFvGFiHbNjpRuq_XBEGBsihM59pMaiFalZrOQ_7J4hgtBR8GIbLHutcuUwba2k0xeKhD8ELjWEswE3xv-H2e6Jh8EOwOccj2i_rYPUlMGdPDqpuRs8D3w`,
code: `${code.split('%')[0]}` code: `${code.split('%')[0]}`
}
}
}
// //
//enable this
// code
}
// Exchange the authorization code for an access token and refresh token // Exchange the authorization code for an access token and refresh token
await exchangeForTokens(crmOauth, authCodeProof) await exchangeForTokens(crmOauth, authCodeProof)