Comparing version 0.0.0 to 0.1.1
(function(context) { | ||
if (typeof module !== 'undefined') { | ||
var sha1 = require('./sha'); | ||
} | ||
var ohauth = {}; | ||
@@ -7,3 +11,4 @@ | ||
return Object.keys(obj).sort().map(function(key) { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]); | ||
return encodeURIComponent(key) + '=' + | ||
encodeURIComponent(obj[key]); | ||
}).join('&'); | ||
@@ -17,3 +22,4 @@ }; | ||
var parts = pair.split('='); | ||
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]); | ||
obj[parts[0]] = (null === parts[1]) ? | ||
'' : decodeURIComponent(parts[1]); | ||
return obj; | ||
@@ -23,17 +29,12 @@ }, {}); | ||
ohauth.xhr = function(method, url, auth, data, options, callback) { | ||
var xhr = new XMLHttpRequest(), | ||
twoHundred = /^20\d$/; | ||
ohauth.rawxhr = function(method, url, data, headers, callback) { | ||
var xhr = new XMLHttpRequest(), twoHundred = /^20\d$/; | ||
xhr.onreadystatechange = function() { | ||
if (4 == xhr.readyState && 0 !== xhr.status) { | ||
if (twoHundred.test(xhr.status)) { | ||
callback(null, xhr); | ||
} else { | ||
callback(xhr, null); | ||
} | ||
if (twoHundred.test(xhr.status)) callback(null, xhr); | ||
else return callback(xhr, null); | ||
} | ||
}; | ||
var headers = (options && options.header) || { 'Content-Type': 'application/x-www-form-urlencoded' }; | ||
xhr.onerror = function(e) { return callback(e, null); }; | ||
xhr.open(method, url, true); | ||
xhr.setRequestHeader('Authorization', 'OAuth ' + ohauth.authHeader(auth)); | ||
for (var h in headers) xhr.setRequestHeader(h, headers[h]); | ||
@@ -43,2 +44,10 @@ xhr.send(data); | ||
ohauth.xhr = function(method, url, auth, data, options, callback) { | ||
var headers = (options && options.header) || { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}; | ||
headers.Authorization = 'OAuth ' + ohauth.authHeader(auth); | ||
ohauth.rawxhr(method, url, data, headers, callback); | ||
}; | ||
ohauth.nonce = function() { | ||
@@ -61,4 +70,4 @@ for (var o = ''; o.length < 6;) { | ||
return encodeURIComponent(s) | ||
.replace(/\!/g, '%21').replace(/\'/g, '%27') | ||
.replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29'); | ||
.replace(/\!/g, '%21').replace(/\'/g, '%27') | ||
.replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29'); | ||
}; | ||
@@ -83,5 +92,5 @@ | ||
// export for npm/browserify compatibility | ||
if (typeof module !== 'undefined') module.exports = ohauth; | ||
})(this); | ||
{ | ||
"name": "ohauth", | ||
"version": "0.0.0", | ||
"version": "0.1.1", | ||
"description": "browser oauth", | ||
@@ -24,3 +24,3 @@ "main": "ohauth.js", | ||
"browsers": { | ||
"ie": [ 8, 9 ], | ||
"ie": [ 9, 10 ], | ||
"firefox": [ 13 ], | ||
@@ -27,0 +27,0 @@ "chrome": [ 20 ], |
## ohauth | ||
[![](http://ci.testling.com/osmlab/ohauth.png)](http://ci.testling.com/osmlab/ohauth) | ||
A most-of-the-way OAuth 1.0 client implementation in Javascript. Meant to be | ||
@@ -13,2 +15,9 @@ an improvement over the [default linked one](http://oauth.googlecode.com/svn/code/javascript/) | ||
### Compatibility | ||
* [OpenStreetMap](http://www.openstreetmap.org/) full & tested with iD | ||
* GitHub - partial, full flow is not possible because `access_token` API is not CORS-enabled | ||
### API | ||
```js | ||
@@ -15,0 +24,0 @@ // generates an oauth-friendly timestamp |
@@ -192,1 +192,2 @@ /* | ||
if (typeof module !== 'undefined') module.exports = sha1; |
if (typeof require !== 'undefined') { | ||
expect = require('expect.js'); | ||
ohauth = require('../'); | ||
} | ||
@@ -4,0 +5,0 @@ |
22294
10
282
55