From a2e74951dbb63103577609ca9add39b340cd88d1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 16 Nov 2018 16:09:12 +0800 Subject: [PATCH] Added formData to be part of signing opts when content type is application/x-www-form-urlencoded --- docker-compose.yml | 10 +++++----- src/handler.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7d48223..cd6733b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,17 +10,17 @@ services: SECURE: "false" # Forward proxy settings #HTTP_PROXY: https://abc:abc@266.266.266.266:333 - #USE_PROXY_AGENT: true - #TO_PROXY: true + #USE_PROXY_AGENT: "true" + #TO_PROXY: "true" # First Gateway - GATEWAY_IS_SINGLE: "true" + # GATEWAY_IS_SINGLE: "true" GATEWAY_1_HOST: .api.xxx.sg GATEWAY_1_SIGNING_HOST: .e.api.xxx.sg GATEWAY_1_PORT: 443 GATEWAY_1_TYPE: EXTERNAL GATEWAY_1_URL_PREFIX: app-internet GATEWAY_1_APP_ID: app-id1 - #GATEWAY_1_SECRET: private.pem + #GATEWAY_1_SECRET: secretpassword #GATEWAY_1_KEY_STRING: #GATEWAY_1_KEY_FILE: /private.pem # Second Gateway @@ -30,7 +30,7 @@ services: GATEWAY_2_TYPE: INTERNAL GATEWAY_2_URL_PREFIX: app-intranet GATEWAY_2_APP_ID: app-id2 - #GATEWAY_2_SECRET: + #GATEWAY_2_SECRET: secretpassword #GATEWAY_2_KEY_STRING: #GATEWAY_2_KEY_FILE: /private.pem expose: diff --git a/src/handler.ts b/src/handler.ts index ce49b13..ca5ce31 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -18,6 +18,7 @@ export const sign = ({ appId, httpMethod, urlPath, + formData, }, config?) => { let authPrefix; if(type === 'INTERNAL'){ @@ -43,6 +44,7 @@ export const sign = ({ httpMethod, authPrefix, urlPath, + formData, }; if(config && config.debug){ @@ -81,6 +83,7 @@ export const firstGateSignature = (req: http.IncomingMessage, config: IConfig): appId: gateway1AppId, httpMethod: method, urlPath, + formData: formData(req) }, config); }; @@ -111,6 +114,7 @@ export const secondGateSignature = (req: http.IncomingMessage, config: IConfig): appId: gateway2AppId, httpMethod: method, urlPath, + formData: formData(req), }, config); }; @@ -156,3 +160,11 @@ export const proxyHandler = ( } } }; + +function formData(req){ + const headers = get(req,'headers'); + if (get(headers,'content-type') === 'application/x-www-form-urlencoded') { + return req.body + } + return undefined +}