Skip to content

Commit 01559ef

Browse files
committed
fix: salesforce oauth redirect url mismatch issue fixed
1 parent 1cb2c80 commit 01559ef

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

frontend-dev/src/components/AllIntegrations/Salesforce/SalesforceAuthorization.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import CopyText from '../../Utilities/CopyText'
66
import { handleAuthorize } from './SalesforceCommonFunc'
77
import tutorialLinks from '../../../Utils/StaticData/tutorialLinks'
88
import TutorialLink from '../../Utilities/TutorialLink'
9+
import { $btcbi } from '../../../GlobalStates'
10+
import { useRecoilValue } from 'recoil'
911

1012
export default function SalesforceAuthorization({
1113
formID,
@@ -19,6 +21,7 @@ export default function SalesforceAuthorization({
1921
redirectLocation,
2022
isInfo
2123
}) {
24+
const btcbi = useRecoilValue($btcbi)
2225
const [isAuthorized, setisAuthorized] = useState(false)
2326
const [error, setError] = useState({
2427
dataCenter: '',
@@ -126,7 +129,8 @@ export default function SalesforceAuthorization({
126129
setError,
127130
setisAuthorized,
128131
setIsLoading,
129-
setSnackbar
132+
setSnackbar,
133+
btcbi
130134
)
131135
}
132136
className="btn btcd-btn-lg purple sh-sm flx"

frontend-dev/src/components/AllIntegrations/Salesforce/SalesforceCommonFunc.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ export const handleAuthorize = (
749749
setError,
750750
setisAuthorized,
751751
setIsLoading,
752-
setSnackbar
752+
setSnackbar,
753+
btcbi
753754
) => {
754755
if (!confTmp.clientId || !confTmp.clientSecret) {
755756
setError({
@@ -760,7 +761,8 @@ export const handleAuthorize = (
760761
}
761762

762763
setIsLoading(true)
763-
const apiEndpoint = `https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=${confTmp.clientId}&prompt=login%20consent&redirect_uri=${encodeURIComponent(window.location.href)}/redirect`
764+
const apiEndpoint = `https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=${confTmp.clientId}&prompt=login%20consent&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(btcbi.api.base)}/redirect`
765+
764766
const authWindow = window.open(apiEndpoint, 'salesforce', 'width=400,height=609,toolbar=off')
765767
const popupURLCheckTimer = setInterval(() => {
766768
if (authWindow.closed) {
@@ -789,17 +791,34 @@ export const handleAuthorize = (
789791
} else {
790792
const newConf = { ...confTmp }
791793
newConf.accountServer = grantTokenResponse['accounts-server']
792-
tokenHelper(grantTokenResponse, newConf, setConf, setisAuthorized, setIsLoading, setSnackbar)
794+
tokenHelper(
795+
grantTokenResponse,
796+
newConf,
797+
setConf,
798+
setisAuthorized,
799+
setIsLoading,
800+
setSnackbar,
801+
btcbi
802+
)
793803
}
794804
}
795805
}, 500)
796806
}
797807

798-
const tokenHelper = (grantToken, confTmp, setConf, setisAuthorized, setIsLoading, setSnackbar) => {
808+
const tokenHelper = (
809+
grantToken,
810+
confTmp,
811+
setConf,
812+
setisAuthorized,
813+
setIsLoading,
814+
setSnackbar,
815+
btcbi
816+
) => {
799817
const tokenRequestParams = { ...grantToken }
800818
tokenRequestParams.clientId = confTmp.clientId
801819
tokenRequestParams.clientSecret = confTmp.clientSecret
802-
tokenRequestParams.redirectURI = `${encodeURIComponent(window.location.href)}/redirect`
820+
tokenRequestParams.redirectURI = `${btcbi.api.base}/redirect`
821+
803822
bitsFetch(tokenRequestParams, 'selesforce_generate_token').then(result => {
804823
if (result && result.success) {
805824
const newConf = { ...confTmp }

0 commit comments

Comments
 (0)