feat: add getClientAccessToken endpoint to retrieve access token for companyId and clientId
parent
526c016b99
commit
0cea41ea04
|
@ -17,7 +17,7 @@ const { createCRMContact,
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const { URL } = require('url')
|
const { URL } = require('url')
|
||||||
const { oauth2 } = require('../utils')
|
const { oauth2 } = require('../utils')
|
||||||
const { exchangeForTokens } = oauth2
|
const { exchangeForTokens, getAccessToken } = oauth2
|
||||||
const Company = require('../models/Company')
|
const Company = require('../models/Company')
|
||||||
const CRM = require('../models/CRM')
|
const CRM = require('../models/CRM')
|
||||||
const CustomError = require('../errors')
|
const CustomError = require('../errors')
|
||||||
|
@ -593,6 +593,22 @@ const webhook_crm = async (req, res) => {
|
||||||
return res.set('Content-Type', 'text/xml').status(StatusCodes.OK).send(responseXml)
|
return res.set('Content-Type', 'text/xml').status(StatusCodes.OK).send(responseXml)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getClientAccessToken = async (req, res) => {
|
||||||
|
const { companyId, clientId } = req.body;
|
||||||
|
console.log('========> getClientAccessToken companyId: ', companyId, ' clientId: ', clientId);
|
||||||
|
|
||||||
|
mustContainProperties(req, ['companyId', 'clientId']);
|
||||||
|
|
||||||
|
const accessToken = await getAccessToken(companyId, clientId);
|
||||||
|
|
||||||
|
if (!accessToken) {
|
||||||
|
console.error(`Access token not found for companyId: ${companyId} and clientId: ${clientId}`);
|
||||||
|
return res.status(StatusCodes.NOT_FOUND).send({ msg: "Access token not found!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(StatusCodes.OK).json({ accessToken });
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
contactCreate,
|
contactCreate,
|
||||||
uploadCrmConfig,
|
uploadCrmConfig,
|
||||||
|
@ -608,8 +624,7 @@ module.exports = {
|
||||||
sfCreateCase,
|
sfCreateCase,
|
||||||
sfUpdateCase,
|
sfUpdateCase,
|
||||||
createTicket,
|
createTicket,
|
||||||
checkContact,
|
getClientAccessToken
|
||||||
contactActivity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const { authorization, } = require('../middleware/authentication')
|
const { authorization, } = require('../middleware/authentication')
|
||||||
const { contactCreate, contactActivity, checkContact, sfCreateCase, sfUpdateCase, createTicket, testTemplate, webhook_crm, uploadCrmConfig, callJournaling, oauthCallBack, install, deleteCrm, deleteCompany, getCrms, webhook } = require('../controllers/crmController')
|
const { contactCreate, contactActivity, checkContact, sfCreateCase, sfUpdateCase, createTicket, testTemplate, webhook_crm, uploadCrmConfig, callJournaling, oauthCallBack, install, deleteCrm, deleteCompany, getCrms, webhook, getClientAccessToken } = require('../controllers/crmController')
|
||||||
const { fileUpload } = require("../utils")
|
const { fileUpload } = require("../utils")
|
||||||
|
|
||||||
router.route('/create-contact').post(authorization, contactCreate)
|
router.route('/create-contact').post(authorization, contactCreate)
|
||||||
|
@ -22,6 +22,7 @@ router.route('/test').post(testTemplate)
|
||||||
router.route('/webhook').post(webhook)
|
router.route('/webhook').post(webhook)
|
||||||
router.route('/webhook-crm').post(webhook_crm)
|
router.route('/webhook-crm').post(webhook_crm)
|
||||||
router.route('/:companyId').get(authorization, getCrms)
|
router.route('/:companyId').get(authorization, getCrms)
|
||||||
|
router.route('/:companyId/access-token').get(authorization, getClientAccessToken)
|
||||||
|
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
Loading…
Reference in New Issue