From 701561cbdbd1c0d1b004c103e2d65f226cc0715b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 21 Jun 2018 15:28:57 +0200 Subject: [PATCH] split up auth mechanisms --- webtask-zoho.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/webtask-zoho.js b/webtask-zoho.js index ce342b7..40a70a9 100644 --- a/webtask-zoho.js +++ b/webtask-zoho.js @@ -5,22 +5,34 @@ const proxy = require('http-proxy-middleware') const server = express() -const onProxyReq = function (proxyReq, req) { - proxyReq.setHeader('Authorization', `Zoho-oauthtoken ${req.webtaskContext.secrets.ZOHO_TOKEN}`) +const onProxyReqZohoCRM = (proxyReq, req) => { + const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets + + proxyReq.setHeader('Authorization', `Zoho-oauthtoken ${ZOHO_CRM_TOKEN}`) +} + +const onProxyReqZohoCampaigns = (proxyReq, req) => { + const { ZOHO_CAMPAIGNS_TOKEN, ZOHO_CAMPAIGNS_LIST_KEY } = req.webtaskContext.secrets + + // + // Auth via query params + // https://www.zoho.com/campaigns/newhelp/api/contact-subscribe.html + // + proxyReq.path += `?authtoken=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo={First Name:mac,Last Name:Last Name,Contact Email:jai@zoho.com}` // eslint-disable-line max-len } const configZohoCRM = { target: 'https://www.zohoapis.com/crm/v2/', pathRewrite: { '^/zoho/crm/': '/' }, changeOrigin: true, - onProxyReq + onProxyReq: onProxyReqZohoCRM } const configZohoCampaigns = { target: 'https://campaigns.zoho.com/api/', pathRewrite: { '^/zoho/campaigns/': '/' }, changeOrigin: true, - onProxyReq + onProxyReq: onProxyReqZohoCampaigns } server.use(cors())