From 3f434e0b9152217dfbab570d51dda2a5793532b5 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 23 Oct 2019 13:17:19 -0700 Subject: [PATCH 1/6] sign in oauth1 case --- lib/axios.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/axios.ts b/lib/axios.ts index 656b7dd..dd28e51 100644 --- a/lib/axios.ts +++ b/lib/axios.ts @@ -28,8 +28,17 @@ export default async function(step: any, config) { } */ -export default async function(step: any, config) { +export default async function(step: any, config, sign?) { // XXX warn about mutating config object... or clone? + if (sign) { + const payload = { + request_data: config, + sign, + } + const oauthEndpoint = "entye5w7a3mw209.m.pipedream.net" + const oauthSignature = (await axios.post(`https://${oauthEndpoint}?pipedream_response=1`, payload)).data + config.headers = oauthSignature + } for (const k in config.headers || {}) { if (typeof config.headers[k] === "undefined") { delete config.headers[k] From 72d3dc3c65e573ccb75f9588a54826ed8f610f7b Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 23 Oct 2019 14:00:39 -0700 Subject: [PATCH 2/6] use new endpoint --- lib/axios.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/axios.ts b/lib/axios.ts index dd28e51..92df2ce 100644 --- a/lib/axios.ts +++ b/lib/axios.ts @@ -35,8 +35,8 @@ export default async function(step: any, config, sign?) { request_data: config, sign, } - const oauthEndpoint = "entye5w7a3mw209.m.pipedream.net" - const oauthSignature = (await axios.post(`https://${oauthEndpoint}?pipedream_response=1`, payload)).data + const oauthEndpoint = "enlb0ktwajm8sen" + const oauthSignature = (await axios.post(`https://${oauthEndpoint}.m.pipedream.net?pipedream_response=1`, payload)).data config.headers = oauthSignature } for (const k in config.headers || {}) { From 4555f39ce5693a48e643595d0474fd201a141ae0 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 23 Oct 2019 14:28:37 -0700 Subject: [PATCH 3/6] pr feedback --- lib/axios.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/axios.ts b/lib/axios.ts index 92df2ce..2d6e977 100644 --- a/lib/axios.ts +++ b/lib/axios.ts @@ -28,16 +28,17 @@ export default async function(step: any, config) { } */ -export default async function(step: any, config, sign?) { +export default async function(step: any, config, signConfig?) { // XXX warn about mutating config object... or clone? - if (sign) { + if (signConfig) { const payload = { request_data: config, - sign, + sign: signConfig, } const oauthEndpoint = "enlb0ktwajm8sen" const oauthSignature = (await axios.post(`https://${oauthEndpoint}.m.pipedream.net?pipedream_response=1`, payload)).data - config.headers = oauthSignature + if (!config.headers) config.headers = {} + config.headers.Authorization = oauthSignature } for (const k in config.headers || {}) { if (typeof config.headers[k] === "undefined") { From 40bdf1fcc6f0334d271eeb6a8c0fafada09eaec7 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 25 Oct 2019 16:45:47 -0700 Subject: [PATCH 4/6] encoding fun --- lib/axios.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/axios.ts b/lib/axios.ts index 2d6e977..1f79263 100644 --- a/lib/axios.ts +++ b/lib/axios.ts @@ -28,15 +28,31 @@ export default async function(step: any, config) { } */ +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI +// see non-escaped chars +// this handles not encoding [!'()*] +function encodeReservedChars(str) { + return str.replace(/[!'()*]/g, function(c) { + return '%' + c.charCodeAt(0).toString(16) + }) +} + export default async function(step: any, config, signConfig?) { // XXX warn about mutating config object... or clone? + // OAuth1 request if (signConfig) { + const {oauthSignerUri, token} = signConfig + + // this handles encoding query string to make sure we match what we sign + const url = new URL(config.url) + url.search = encodeReservedChars(url.search.substr(1)) + config.url = url.toString() + const payload = { - request_data: config, - sign: signConfig, + requestData: config, + token, } - const oauthEndpoint = "enlb0ktwajm8sen" - const oauthSignature = (await axios.post(`https://${oauthEndpoint}.m.pipedream.net?pipedream_response=1`, payload)).data + const oauthSignature = (await axios.post(oauthSignerUri, payload)).data if (!config.headers) config.headers = {} config.headers.Authorization = oauthSignature } From d2291adbc14ee722efabee5aecc8eb4b9050aa66 Mon Sep 17 00:00:00 2001 From: jsendo Date: Tue, 29 Oct 2019 16:38:48 -0700 Subject: [PATCH 5/6] this works, need to fix versions and other package.json stuff (#3) need to clean up package.json --- dist/axios.d.ts | 2 +- dist/axios.js | 26 +++++++++++++++++++++++++- package-lock.json | 45 ++++++++++++++++++++++++++++++++------------- package.json | 7 +++---- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/dist/axios.d.ts b/dist/axios.d.ts index 3665ccf..f6e011c 100644 --- a/dist/axios.d.ts +++ b/dist/axios.d.ts @@ -1 +1 @@ -export default function (step: any, config: any): Promise; +export default function (step: any, config: any, signConfig?: any): Promise; diff --git a/dist/axios.js b/dist/axios.js index 53d8ce8..fe3ec62 100644 --- a/dist/axios.js +++ b/dist/axios.js @@ -28,8 +28,32 @@ export default async function(step: any, config) { } } */ -async function default_1(step, config) { +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI +// see non-escaped chars +// this handles not encoding [!'()*] +function encodeReservedChars(str) { + return str.replace(/[!'()*]/g, function (c) { + return '%' + c.charCodeAt(0).toString(16); + }); +} +async function default_1(step, config, signConfig) { // XXX warn about mutating config object... or clone? + // OAuth1 request + if (signConfig) { + const { oauthSignerUri, token } = signConfig; + // this handles encoding query string to make sure we match what we sign + const url = new URL(config.url); + url.search = encodeReservedChars(url.search.substr(1)); + config.url = url.toString(); + const payload = { + requestData: config, + token, + }; + const oauthSignature = (await axios_1.default.post(oauthSignerUri, payload)).data; + if (!config.headers) + config.headers = {}; + config.headers.Authorization = oauthSignature; + } for (const k in config.headers || {}) { if (typeof config.headers[k] === "undefined") { delete config.headers[k]; diff --git a/package-lock.json b/package-lock.json index 6a42055..b1df334 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@pipedreamhq/platform", - "version": "0.2.2", + "name": "@jsendo/platform", + "version": "0.2.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2346,7 +2346,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2367,12 +2368,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2387,17 +2390,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2514,7 +2520,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2526,6 +2533,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2540,6 +2548,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2547,12 +2556,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2571,6 +2582,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2651,7 +2663,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2663,6 +2676,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2748,7 +2762,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2784,6 +2799,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2803,6 +2819,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2846,12 +2863,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index 5573251..1f6ca2d 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { - "name": "@pipedreamhq/platform", - "version": "0.2.2", + "name": "@jsendo/platform", + "version": "0.2.6", "description": "Pipedream platform globals (typing and runtime type checking)", - "homepage": "https://pipedream.com", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { @@ -13,7 +12,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/PipedreamHQ/platform.git" + "url": "https://github.com/jsendo/platform.git" }, "dependencies": { "axios": "^0.19.0", From cf6a97fafe86daceaac575c824fbada910594513 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 29 Oct 2019 16:50:50 -0700 Subject: [PATCH 6/6] cleaning up version and other package.json stuff --- package-lock.json | 4 ++-- package.json | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index b1df334..8a8cbd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@jsendo/platform", - "version": "0.2.5", + "name": "@pipedreamhq/platform", + "version": "0.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1f6ca2d..38dd9b4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { - "name": "@jsendo/platform", - "version": "0.2.6", + "name": "@pipedreamhq/platform", + "version": "0.2.3", "description": "Pipedream platform globals (typing and runtime type checking)", + "homepage": "https://pipedream.com", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { @@ -12,7 +13,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/jsendo/platform.git" + "url": "https://github.com/PipedreamHQ/platform.git" }, "dependencies": { "axios": "^0.19.0",