Skip to content

Commit

Permalink
Merge remote-tracking branch 'jfromaniello/bug129'
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranj committed Mar 5, 2013
2 parents a295a66 + 798157c commit 8be23c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
realHeaders['Host']= parsedUrl.host;

realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
if( access_token ) {
if( access_token && !('Authorization' in headers)) {
if( ! parsedUrl.query ) parsedUrl.query= {};
parsedUrl.query[this._accessTokenName]= access_token;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/oauth2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var vows = require('vows'),
assert = require('assert'),
https = require('https'),
OAuth2= require('../lib/oauth2').OAuth2;
OAuth2= require('../lib/oauth2').OAuth2,
url = require('url');

vows.describe('OAuth2').addBatch({
'Given an OAuth2 instance with clientId and clientSecret, ': {
Expand All @@ -16,6 +17,16 @@ vows.describe('OAuth2').addBatch({
assert.equal( refresh_token, "refresh");
});
},
'we should not include access token in both querystring and headers': function (oa) {
oa._request = new OAuth2("clientId", "clientSecret")._request.bind(oa);
oa._executeRequest= function( http_library, options, post_body, callback) {
callback(null, url.parse(options.path, true).query, options.headers);
};
oa.get("/userinfo", 'access', function(error, query, headers) {
assert.ok( !('access_token' in query), "access_token not in query");
assert.ok( 'Authorization' in headers, "Authorization in headers");
});
},
'we should correctly extract the token if received as a JSON literal': function (oa) {
oa._request= function(method, url, headers, post_body, access_token, callback) {
callback(null, '{"access_token":"access","refresh_token":"refresh"}');
Expand Down

0 comments on commit 8be23c3

Please sign in to comment.