From ae4f754bfabcadc1b26cb5cb167034df27047502 Mon Sep 17 00:00:00 2001 From: Steven Quiroa <stevenkm92@gmail.com> Date: Thu, 9 Jun 2016 19:37:42 -0600 Subject: [PATCH] Only encode body in oauth signature if the content-type is x-www-form-urlencoded version 2 --- superagent-oauth.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/superagent-oauth.js b/superagent-oauth.js index 6750547..956760c 100644 --- a/superagent-oauth.js +++ b/superagent-oauth.js @@ -54,12 +54,26 @@ module.exports = function (superagent) { */ Request.prototype.signOAuth = function () { + var extra_params = this._oauth_query; + if ('application/x-www-form-urlencoded' == this.getHeader('content-type') && this.isObject(this._data)) { + if(extra_params) { + // merge + var keys = Object.keys(this._data), key; + for (var i = 0; i < keys.length; i++) { + key = keys[i]; + extra_params[key] = this._data[key]; + } + } else { + extra_params = this._data; + } + } + var params = this.oa._prepareParameters( this.token , this.secret , this.method , this.url - , this._data || this._oauth_query // XXX: what if there's query and body? merge? + , this.extra_params ); var header = this.oa._isEcho