Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oauth

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth - npm Package Compare versions

Comparing version 0.9.11 to 0.9.12

29

lib/oauth.js

@@ -143,2 +143,3 @@ var crypto= require('crypto'),

for(var key in argumentsHash ) {
if (argumentsHash.hasOwnProperty(key)) {
var value= argumentsHash[key];

@@ -153,2 +154,3 @@ if( Array.isArray(value) ) {

}
}
}

@@ -171,4 +173,4 @@ return argument_pairs;

exports.OAuth.prototype._normaliseRequestParams= function(arguments) {
var argument_pairs= this._makeArrayOfArgumentsHash(arguments);
exports.OAuth.prototype._normaliseRequestParams= function(args) {
var argument_pairs= this._makeArrayOfArgumentsHash(args);
// First encode them #3.4.1.3.2 .1

@@ -280,3 +282,3 @@ for(var i=0;i<argument_pairs.length;i++) {

for( var key in extra_params ) {
oauthParameters[key]= extra_params[key];
if (extra_params.hasOwnProperty(key)) oauthParameters[key]= extra_params[key];
}

@@ -354,3 +356,12 @@ }

headers["Content-length"]= post_body ? Buffer.byteLength(post_body) : 0;
if( post_body ) {
if ( Buffer.isBuffer(post_body) ) {
headers["Content-length"]= post_body.length;
} else {
headers["Content-length"]= Buffer.byteLength(post_body);
}
} else {
headers["Content-length"]= 0;
}
headers["Content-Type"]= post_content_type;

@@ -380,3 +391,3 @@

var callbackCalled= false;
function passBackControl( response ) {
var passBackControl = function( response ) {
if(!callbackCalled) {

@@ -414,4 +425,6 @@ callbackCalled= true;

request.on("error", function(err) {
callbackCalled= true;
callback( err )
if(!callbackCalled) {
callbackCalled= true;
callback( err )
}
});

@@ -490,3 +503,3 @@

}
if( typeof post_body != "string" ) {
if ( typeof post_body != "string" && !Buffer.isBuffer(post_body) ) {
post_content_type= "application/x-www-form-urlencoded"

@@ -493,0 +506,0 @@ extra_params= post_body;

@@ -52,5 +52,13 @@ var querystring= require('querystring'),

exports.OAuth2.prototype._chooseHttpLibrary= function( parsedUrl ) {
var http_library= https;
// As this is OAUth2, we *assume* https unless told explicitly otherwise.
if( parsedUrl.protocol != "https:" ) {
http_library= http;
}
return http_library;
};
exports.OAuth2.prototype._request= function(method, url, headers, post_body, access_token, callback) {
var http_library= https;
var creds = crypto.createCredentials({ });

@@ -62,7 +70,5 @@ var parsedUrl= URL.parse( url, true );

// As this is OAUth2, we *assume* https unless told explicitly otherwise.
if( parsedUrl.protocol != "https:" ) {
http_library= http;
}
var http_library= this._chooseHttpLibrary( parsedUrl );
var realHeaders= {};

@@ -83,3 +89,12 @@ for( var key in this._customHeaders ) {

realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
if( post_body ) {
if ( Buffer.isBuffer(post_body) ) {
realHeaders["Content-Length"]= post_body.length;
} else {
realHeaders["Content-Length"]= Buffer.byteLength(post_body);
}
} else {
realHeaders["Content-length"]= 0;
}
if( access_token && !('Authorization' in realHeaders)) {

@@ -139,3 +154,3 @@ if( ! parsedUrl.query ) parsedUrl.query= {};

if( options.method == 'POST' && post_body ) {
if( (options.method == 'POST' || options.method == 'PUT') && post_body ) {
request.write(post_body);

@@ -142,0 +157,0 @@ }

{ "name" : "oauth"
, "description" : "Library for interacting with OAuth 1.0, 1.0A, 2 and Echo. Provides simplified client access and allows for construction of more complex apis and OAuth providers."
, "version" : "0.9.11"
, "version" : "0.9.12"
, "directories" : { "lib" : "./lib" }

@@ -5,0 +5,0 @@ , "main" : "index.js"

@@ -9,2 +9,4 @@ node-oauth

[![Clone in Koding](http://learn.koding.com/btn/clone_d.png)][koding]
[koding]: https://koding.com/Teamwork?import=https://github.com/ciaranj/node-oauth/archive/master.zip&c=git1

@@ -20,3 +22,3 @@ Installation

To run examples/tests insall Mocha `$ npm install -g mocha` and run `$ mocha you-file-name.js`:
To run examples/tests install Mocha `$ npm install -g mocha` and run `$ mocha you-file-name.js`:

@@ -27,3 +29,3 @@ ## OAuth1.0

describe('OAuth1.0',function(){
var OAuth = require('OAuth');
var OAuth = require('oauth');

@@ -42,3 +44,3 @@ it('tests trends Twitter API v1.1',function(done){

'https://api.twitter.com/1.1/trends/place.json?id=23424977',
'your user toke for this app', //test user token
'your user token for this app', //test user token
'your user secret for this app', //test user secret

@@ -57,3 +59,3 @@ function (e, data, res){

describe('OAuth2',function(){
var OAuth = require('OAuth');
var OAuth = require('oauth');

@@ -83,7 +85,12 @@ it('gets bearer token', function(done){

* 0.9.12
- OAuth1/2: Can now pass Buffer instance directly for PUTs+POSTs (thank you Evan Prodromou)
- OAuth1: Improve interoperability with libraries that mess with the prototype. (thank you Jose Ignacio Andres)
- OAuth2: Adds PUT support for OAuth2 (thank you Derek Brooks)
- OAuth1: Improves use_strict compatibility (thank you Ted Goddard)
* 0.9.11
- OAuth2: No longer sends the type=webserver argument with the OAuth2 requests (thank you bendiy)
- OAuth2: Provides a default (and overrideable) User-Agent header (thanks to Andrew Martens & Daniel Mahlow)
- OAuth1: New followRedirects client option (true by default) (thanks to Pieter Joost van de Sande)
- OAuth1: Adds RSA-SHA1 support (thanks to Jeffrey D. Van Alstine & Michael Garvin & Andreas Knecht)
- OAuth2: No longer sends the type=webserver argument with the OAuth2 requests (thank you bendiy)
- OAuth2: Provides a default (and overrideable) User-Agent header (thanks to Andrew Martens & Daniel Mahlow)
- OAuth1: New followRedirects client option (true by default) (thanks to Pieter Joost van de Sande)
- OAuth1: Adds RSA-SHA1 support (thanks to Jeffrey D. Van Alstine & Michael Garvin & Andreas Knecht)
* 0.9.10

@@ -156,2 +163,6 @@ - OAuth2: Addresses 2 issues that came in with 0.9.9, #129 & #125 (thank you José F. Romaniello)

* Evan Prodromou
* Jose Ignacio Andres
* Ted Goddard
* Derek Brooks
* Ciaran Jessup - ciaranj@gmail.com

@@ -158,0 +169,0 @@ * Mark Wubben - http://equalmedia.com/

@@ -379,3 +379,53 @@ var vows = require('vows'),

},
'if the post_body is not a string' : {
'if the post_body is a buffer' : {
"It should be passed through as is, and the original content-type (if specified) should be passed through": function(oa) {
var op= oa._createClient;
try {
var callbackCalled= false;
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
assert.equal(headers["Content-Type"], "image/jpeg")
return {
write: function(data){
callbackCalled= true;
assert.equal(data.length, 4);
},
on: function() {},
end: function() {
}
};
}
var request= oa.post("http://foo.com/blah", "token", "token_secret", new Buffer([10,20,30,40]), "image/jpeg")
assert.equal(callbackCalled, true);
}
finally {
oa._createClient= op;
}
},
"It should be passed through as is, and no content-type is specified.": function(oa) {
//Should probably actually set application/octet-stream, but to avoid a change in behaviour
// will just document (here) that the library will set it to application/x-www-form-urlencoded
var op= oa._createClient;
try {
var callbackCalled= false;
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded")
return {
write: function(data){
callbackCalled= true;
assert.equal(data.length, 4);
},
on: function() {},
end: function() {
}
};
}
var request= oa.post("http://foo.com/blah", "token", "token_secret", new Buffer([10,20,30,40]))
assert.equal(callbackCalled, true);
}
finally {
oa._createClient= op;
}
}
},
'if the post_body is not a string or a buffer' : {
"It should be url encoded and the content type set to be x-www-form-urlencoded" : function(oa) {

@@ -556,2 +606,52 @@ var op= oa._createClient;

},
'if the post_body is a buffer' : {
"It should be passed through as is, and the original content-type (if specified) should be passed through": function(oa) {
var op= oa._createClient;
try {
var callbackCalled= false;
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
assert.equal(headers["Content-Type"], "image/jpeg")
return {
write: function(data){
callbackCalled= true;
assert.equal(data.length, 4);
},
on: function() {},
end: function() {
}
};
}
var request= oa.put("http://foo.com/blah", "token", "token_secret", new Buffer([10,20,30,40]), "image/jpeg")
assert.equal(callbackCalled, true);
}
finally {
oa._createClient= op;
}
},
"It should be passed through as is, and no content-type is specified.": function(oa) {
//Should probably actually set application/octet-stream, but to avoid a change in behaviour
// will just document (here) that the library will set it to application/x-www-form-urlencoded
var op= oa._createClient;
try {
var callbackCalled= false;
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded")
return {
write: function(data){
callbackCalled= true;
assert.equal(data.length, 4);
},
on: function() {},
end: function() {
}
};
}
var request= oa.put("http://foo.com/blah", "token", "token_secret", new Buffer([10,20,30,40]))
assert.equal(callbackCalled, true);
}
finally {
oa._createClient= op;
}
}
},
'if the post_body is not a string' : {

@@ -558,0 +658,0 @@ "It should be url encoded and the content type set to be x-www-form-urlencoded" : function(oa) {

@@ -128,3 +128,3 @@ var vows = require('vows'),

{ 'SomeHeader': '123' }),
'When calling get': {
'When GETing': {
'we should see the custom headers mixed into headers property in options passed to http-library' : function(oa) {

@@ -135,5 +135,104 @@ oa._executeRequest= function( http_library, options, callback ) {

oa.get("", {});
}
},
}
},
'Given an OAuth2 instance with a clientId and clientSecret': {
topic: new OAuth2("clientId", "clientSecret"),
'When POSTing': {
'we should see a given string being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "text/plain");
assert.equal(options.headers["Content-Length"], 26);
assert.equal(options.method, "POST");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(body, "THIS_IS_A_POST_BODY_STRING")
}
}
}
};
}
oa._request("POST", "", {"Content-Type":"text/plain"}, "THIS_IS_A_POST_BODY_STRING");
assert.ok( bodyWritten );
},
'we should see a given buffer being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "application/octet-stream");
assert.equal(options.headers["Content-Length"], 4);
assert.equal(options.method, "POST");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(4, body.length)
}
}
}
};
}
oa._request("POST", "", {"Content-Type":"application/octet-stream"}, new Buffer([1,2,3,4]));
assert.ok( bodyWritten );
}
},
'When PUTing': {
'we should see a given string being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "text/plain");
assert.equal(options.headers["Content-Length"], 25);
assert.equal(options.method, "PUT");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(body, "THIS_IS_A_PUT_BODY_STRING")
}
}
}
};
}
oa._request("PUT", "", {"Content-Type":"text/plain"}, "THIS_IS_A_PUT_BODY_STRING");
assert.ok( bodyWritten );
},
'we should see a given buffer being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "application/octet-stream");
assert.equal(options.headers["Content-Length"], 4);
assert.equal(options.method, "PUT");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(4, body.length)
}
}
}
};
}
oa._request("PUT", "", {"Content-Type":"application/octet-stream"}, new Buffer([1,2,3,4]));
assert.ok( bodyWritten );
}
}
},
'When the user passes in the User-Agent in customHeaders': {

@@ -140,0 +239,0 @@ topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc