Skip to content

Commit 962697a

Browse files
committed
override "query()" to maintain a list of the query-string params being sent
This is required for signing OAuth 1.0 requests.
1 parent 84364e4 commit 962697a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

superagent-oauth.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ module.exports = function (superagent) {
77

88
var Request = superagent.Request;
99

10+
/**
11+
* Override .query() to collect the query values.
12+
* XXX: it would be nice if superagent offered an API for this...
13+
*
14+
* @api public
15+
*/
16+
17+
var oldQuery = Request.prototype.query;
18+
19+
Request.prototype.query = function (obj) {
20+
if (!this._oauth_query) this._oauth_query = {};
21+
// merge
22+
var keys = Object.keys(obj), key;
23+
for (var i = 0; i < keys.length; i++) {
24+
key = keys[i];
25+
this._oauth_query[key] = obj[keys];
26+
}
27+
return oldQuery.call(this, obj);
28+
};
29+
1030
/**
1131
* Add sign method.
1232
*
@@ -39,7 +59,7 @@ module.exports = function (superagent) {
3959
, this.secret
4060
, this.method
4161
, this.url
42-
, this._data || this._query // XXX: what if there's query and body? merge?
62+
, this._data || this._oauth_query // XXX: what if there's query and body? merge?
4363
);
4464

4565
var header = this.oa._isEcho

0 commit comments

Comments
 (0)