Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
language: node_js
node_js:
- 0.10

before_script:
- export PHANTOMJS_BIN=/usr/local/phantomjs/bin/phantomjs
- 0.10
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OAuth 1.0a signature generator for node and the browser
### Compliant with [RFC 5843](http://tools.ietf.org/html/rfc5849) + [Errata ID 2550](http://www.rfc-editor.org/errata_search.php?rfc=5849) and [OAuth 1.0a](http://oauth.net/core/1.0a)
### Compliant with [RFC 5843](http://tools.ietf.org/html/rfc5849) + [Errata ID 2550](http://www.rfc-editor.org/errata_search.php?rfc=5849) and [community spec](http://oauth.net/core/1.0a)

[![Build Status](https://travis-ci.org/bettiolo/oauth-signature-js.png?branch=master)](https://travis-ci.org/bettiolo/oauth-signature-js)
[![Bower version](https://badge.fury.io/bo/oauth-signature-js.svg)](http://badge.fury.io/bo/oauth-signature-js)
[![Bower version](https://badge.fury.io/bo/oauth-signature.svg)](http://badge.fury.io/bo/oauth-signature-js)
[![NPM version](https://badge.fury.io/js/oauth-signature.png)](http://badge.fury.io/js/oauth-signature)
[![Dependency Status](https://david-dm.org/bettiolo/oauth-signature-js.png?theme=shields.io)](https://david-dm.org/bettiolo/oauth-signature-js)

Expand Down Expand Up @@ -85,7 +85,7 @@ http://photos.example.net/photos?file=vacation.jpg&size=original&oauth_consumer_

## Advantages

This project has an extensive test coverage for all the corner cases present in the OAuth specifications ([RFC 5843](http://tools.ietf.org/html/rfc5849) + [Errata ID 2550](http://www.rfc-editor.org/errata_search.php?rfc=5849) and [OAuth.net community version](http://oauth.net/core/1.0a))
This project has an extensive test coverage for all the corner cases present in the OAuth specifications ([RFC 5843](http://tools.ietf.org/html/rfc5849) + [Errata ID 2550](http://www.rfc-editor.org/errata_search.php?rfc=5849) and [OAuth.net community-based specification](http://oauth.net/core/1.0a))

Take a look at the test file [src/app/signature.tests.js](src/app/oauth-signature.tests.js)

Expand Down Expand Up @@ -121,3 +121,5 @@ And you can hit the echo OAuth endpoints at this url: http://echo.lab.madgex.com
A url similar to this one will be generated: `http://echo.lab.madgex.com/echo.ashx?foo=bar&oauth_consumer_key=key&oauth_nonce=643377115&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1410807318&oauth_token=accesskey&oauth_version=1.0&oauth_signature=zCmKoF9rVlNxAkD8wUCizFUajs4%3D`

Click on the generated link on the right hand side and you will see the echo server returning `foo=bar`

{'methodName': string, 'params': array}
18 changes: 9 additions & 9 deletions dist/oauth-signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>
/*! url - v1.8.6 - 2013-11-22 */window.url=function(){function a(a){return!isNaN(parseFloat(a))&&isFinite(a)}return function(b,c){var d=c||window.location.toString();if(!b)return d;b=b.toString(),"//"===d.substring(0,2)?d="http:"+d:1===d.split("://").length&&(d="http://"+d),c=d.split("/");var e={auth:""},f=c[2].split("@");1===f.length?f=f[0].split(":"):(e.auth=f[0],f=f[1].split(":")),e.protocol=c[0],e.hostname=f[0],e.port=f[1]||("https"===e.protocol.split(":")[0].toLowerCase()?"443":"80"),e.pathname=(c.length>3?"/":"")+c.slice(3,c.length).join("/").split("?")[0].split("#")[0];var g=e.pathname;"/"===g.charAt(g.length-1)&&(g=g.substring(0,g.length-1));var h=e.hostname,i=h.split("."),j=g.split("/");if("hostname"===b)return h;if("domain"===b)return/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(h)?h:i.slice(-2).join(".");if("sub"===b)return i.slice(0,i.length-2).join(".");if("port"===b)return e.port;if("protocol"===b)return e.protocol.split(":")[0];if("auth"===b)return e.auth;if("user"===b)return e.auth.split(":")[0];if("pass"===b)return e.auth.split(":")[1]||"";if("path"===b)return e.pathname;if("."===b.charAt(0)){if(b=b.substring(1),a(b))return b=parseInt(b,10),i[0>b?i.length+b:b-1]||""}else{if(a(b))return b=parseInt(b,10),j[0>b?j.length+b:b]||"";if("file"===b)return j.slice(-1)[0];if("filename"===b)return j.slice(-1)[0].split(".")[0];if("fileext"===b)return j.slice(-1)[0].split(".")[1]||"";if("?"===b.charAt(0)||"#"===b.charAt(0)){var k=d,l=null;if("?"===b.charAt(0)?k=(k.split("?")[1]||"").split("#")[0]:"#"===b.charAt(0)&&(k=k.split("#")[1]||""),!b.charAt(1))return k;b=b.substring(1),k=k.split("&");for(var m=0,n=k.length;n>m;m++)if(l=k[m].split("="),l[0]===b)return l[1]||"";return null}}return""}}(),"undefined"!=typeof jQuery&&jQuery.extend({url:function(a,b){return window.url(a,b)}});
;(function() {
'use strict';

// In node there is no global Window object
var isNode = (typeof window === 'undefined');

// Check the existence of module and module.exports to detect node
var isNode = (typeof module != 'undefined' && typeof module.exports != 'undefined');
function OAuthSignature() {
}

Expand Down Expand Up @@ -126,18 +126,18 @@ e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>
};
},
parseInNode : function () {
var url = require('url'),
var url = require('uri-js'),
parsedUri = url.parse(this._url),
scheme = parsedUri.protocol;
scheme = parsedUri.scheme;
// strip the ':' at the end of the scheme added by the url module
if (scheme.charAt(scheme.length - 1) == ":") {
scheme = scheme.substring(0, scheme.length - 1);
}
return {
scheme : scheme,
authority : parsedUri.hostname,
authority : parsedUri.host,
port : parsedUri.port,
path : parsedUri.pathname
path : parsedUri.path
};
}
};
Expand Down Expand Up @@ -305,4 +305,4 @@ e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>
} else {
window.oauthSignature = oauthSignature;
}
})();
})();
2 changes: 1 addition & 1 deletion dist/oauth-signature.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions oauth-signature-js/src/app/chance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script src="oauth-signature-js/src/app/oauth-signature.tests.js"></script>
<script src="oauth-signature-js/src/app/oauth-signature.js"></script>
<script>
var mySeed;
$.get("https://www.random.org/integers/", {num: "1", col: "1", min: "1", max: "1000000000", base: "10", format: "plain", rnd: "new"}, function(randNum) {
mySeed = randNum;

// Instantiate Chance with this truly random number as the seed
var my_seeded_chance = new Chance(mySeed);
console.log(my_seeded_chance.natural());
});
</script>
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oauth-signature",
"description": "OAuth 1.0a signature generator",
"version": "1.3.0",
"description": "OAuth 1.0a signature generator (RFC 5849)",
"version": "1.3.1",
"author": "Marco Bettiolo <[email protected]> (https://github.com/bettiolo)",
"homepage": "https://github.com/bettiolo/oauth-signature-js",
"repository": {
Expand Down Expand Up @@ -46,6 +46,7 @@
}
},
"dependencies": {
"crypto-js": "~3.1.2-5"
"crypto-js": "~3.1.5",
"uri-js": "^2.1.1"
}
}
18 changes: 9 additions & 9 deletions src/app/oauth-signature.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
;(function() {
'use strict';

// In node there is no global Window object
var isNode = (typeof window === 'undefined');

// Check the existence of module and module.exports to detect node
var isNode = (typeof module != 'undefined' && typeof module.exports != 'undefined');
function OAuthSignature() {
}

Expand Down Expand Up @@ -98,18 +98,18 @@
};
},
parseInNode : function () {
var url = require('url'),
var url = require('uri-js'),
parsedUri = url.parse(this._url),
scheme = parsedUri.protocol;
scheme = parsedUri.scheme;
// strip the ':' at the end of the scheme added by the url module
if (scheme.charAt(scheme.length - 1) == ":") {
scheme = scheme.substring(0, scheme.length - 1);
}
return {
scheme : scheme,
authority : parsedUri.hostname,
authority : parsedUri.host,
port : parsedUri.port,
path : parsedUri.pathname
path : parsedUri.path
};
}
};
Expand Down Expand Up @@ -277,4 +277,4 @@
} else {
window.oauthSignature = oauthSignature;
}
})();
})();
8 changes: 8 additions & 0 deletions src/app/oauth-signature.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,12 @@ test('Produces the expected decoded signature when optional token not provided',
'The generated GET signature should match the expected RFC 3986 encoded signature by default');
assert.equal(unencodedSignature, expectedDecodedSignature,
'The generated unencoded GET signature should match the expected unencoded signature');
});

suite('Node or Browser Detection');
test('Node or Browser properly detected', function () {
var oldIsNode = (typeof window === 'undefined');
var newIsNode = (typeof module != 'undefined' && typeof module.exports != 'undefined');
assert.equal(oldIsNode, newIsNode,
'Both methods of detection should produce the same value');
});