1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2024-11-24 02:55:13 +01:00

split up auth mechanisms

This commit is contained in:
Matthias Kretschmann 2018-06-21 15:28:57 +02:00
parent e0ddc2f3cf
commit 701561cbdb
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -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())