Skip to content

Commit

Permalink
Merge Pull Request meteor#574 into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
avital committed Dec 27, 2012
2 parents 7c007a7 + 7cd4082 commit 297f20d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
20 changes: 14 additions & 6 deletions packages/accounts-oauth1-helper/oauth1_binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ OAuth1Binding.prototype._getSignature = function(method, url, rawHeaders, access

var signatureBase = [
method,
encodeURIComponent(url),
encodeURIComponent(parameters)
self._encodeString(url),
self._encodeString(parameters)
].join('&');

var signingKey = encodeURIComponent(self._secret) + '&';
var signingKey = self._encodeString(self._secret) + '&';
if (accessTokenSecret)
signingKey += encodeURIComponent(accessTokenSecret);
signingKey += self._encodeString(accessTokenSecret);

return crypto.createHmac('SHA1', signingKey).update(signatureBase).digest('base64');
};
Expand All @@ -125,21 +125,29 @@ OAuth1Binding.prototype._call = function(method, url, headers, params) {

if (response.error) {
Meteor._debug('Error sending OAuth1 HTTP call', response.content, method, url, params, authString);
if (response.statusCode) response.error.statusCode = response.statusCode;
if (response.data) response.error.data = response.data;
throw response.error;
}

return response;
};

OAuth1Binding.prototype._encodeHeader = function(header) {
var self = this;
return _.reduce(header, function(memo, val, key) {
memo[encodeURIComponent(key)] = encodeURIComponent(val);
memo[self._encodeString(key)] = self._encodeString(val);
return memo;
}, {});
};

OAuth1Binding.prototype._encodeString = function(str) {
return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
};

OAuth1Binding.prototype._getAuthHeaderString = function(headers) {
var self = this;
return 'OAuth ' + _.map(headers, function(val, key) {
return encodeURIComponent(key) + '="' + encodeURIComponent(val) + '"';
return self._encodeString(key) + '="' + self._encodeString(val) + '"';
}).sort().join(', ');
};
7 changes: 6 additions & 1 deletion packages/http/httpcall_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ Meteor.http = Meteor.http || {};
(function() {

Meteor.http._encodeParams = function(params) {
self = this;
var buf = [];
_.each(params, function(value, key) {
if (buf.length)
buf.push('&');
buf.push(encodeURIComponent(key), '=', encodeURIComponent(value));
buf.push(self._encodeString(key), '=', self._encodeString(value));
});
return buf.join('').replace(/%20/g, '+');
};

Meteor.http._encodeString = function(str) {
return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
};

Meteor.http._buildUrl = function(before_qmark, from_qmark, opt_query, opt_params) {
var url_without_query = before_qmark;
var query = from_qmark ? from_qmark.slice(1) : null;
Expand Down
3 changes: 2 additions & 1 deletion packages/http/httpcall_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ testAsyncMulti("httpcall - headers", [

testAsyncMulti("httpcall - params", [
function(test, expect) {

var do_test = function(method, url, params, opt_opts, expect_url, expect_body) {
var opts = {};
if (typeof opt_opts === "string") {
Expand Down Expand Up @@ -324,6 +323,8 @@ testAsyncMulti("httpcall - params", [
do_test("GET", "/", {foo:"bar", fruit:"apple"}, "/?foo=bar&fruit=apple", "");
do_test("POST", "/", {foo:"bar", fruit:"apple"}, "/", "foo=bar&fruit=apple");
do_test("POST", "/", {foo:"bar", fruit:"apple"}, "/", "foo=bar&fruit=apple");
do_test("GET", "/", {'foo!':"bang!"}, {}, "/?foo%21=bang%21", "");
do_test("POST", "/", {'foo!':"bang!"}, {}, "/", "foo%21=bang%21");
do_test("POST", "/", {foo:"bar", fruit:"apple"}, {
content: "stuff!"}, "/?foo=bar&fruit=apple", "stuff!");
do_test("POST", "/", {foo:"bar", greeting:"Hello World"}, {
Expand Down

0 comments on commit 297f20d

Please sign in to comment.