New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ohauth

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ohauth - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

github.html

54

index.js
'use strict';
var hashes = require('jshashes'),
xtend = require('xtend'),
sha1 = new hashes.SHA1();

@@ -83,2 +84,55 @@

/**
* Takes an options object for configuration (consumer_key,
* consumer_secret, version, signature_method, token) and returns a
* function that generates the Authorization header for given data.
*
* The returned function takes these parameters:
* - method: GET/POST/...
* - uri: full URI with protocol, port, path and query string
* - extra_params: any extra parameters (that are passed in the POST data),
* can be an object or a from-urlencoded string.
*
* Returned function returns full OAuth header with "OAuth" string in it.
*/
ohauth.headerGenerator = function(options) {
options = options || {};
var consumer_key = options.consumer_key || '',
consumer_secret = options.consumer_secret || '',
signature_method = options.signature_method || 'HMAC-SHA1',
version = options.version || '1.0',
token = options.token || '';
return function(method, uri, extra_params) {
method = method.toUpperCase();
if (typeof extra_params === 'string' && extra_params.length > 0) {
extra_params = ohauth.stringQs(extra_params);
}
var uri_parts = uri.split('?', 2),
base_uri = uri_parts[0];
var query_params = uri_parts.length === 2 ?
ohauth.stringQs(uri_parts[1]) : {};
var oauth_params = {
oauth_consumer_key: consumer_key,
oauth_signature_method: signature_method,
oauth_version: version,
oauth_timestamp: ohauth.timestamp(),
oauth_nonce: ohauth.nonce()
};
if (token) oauth_params.oauth_token = token;
var all_params = xtend({}, oauth_params, query_params, extra_params),
base_str = ohauth.baseString(method, base_uri, all_params);
oauth_params.oauth_signature = ohauth.signature(consumer_secret, token, base_str);
return 'OAuth ' + ohauth.authHeader(oauth_params);
};
};
module.exports = ohauth;

5

package.json
{
"name": "ohauth",
"version": "0.1.4",
"version": "0.2.0",
"description": "browser oauth",

@@ -51,4 +51,5 @@ "main": "index.js",

"dependencies": {
"jshashes": "~1.0.3"
"jshashes": "~1.0.3",
"xtend": "~2.0.3"
}
}

18

README.md

@@ -9,4 +9,2 @@ ## ohauth

This includes [Paul Johnston's venerable implementation of SHA1](http://pajhome.org.uk/crypt/md5/).
If you use this on a server [different from the one authenticated against](http://en.wikipedia.org/wiki/Same_origin_policy),

@@ -67,1 +65,17 @@ you'll need to [enable](http://enable-cors.org/) and use [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)

```
#### Just generating the headers
```js
// create a function holding configuration
var auth = ohauth.headerGenerator({
consumer_key: '...',
consumer_secret: '...'
});
// pass just the data to produce the OAuth header with optional
// POST data (as long as it'll be form-urlencoded in the request)
var header = auth('GET', 'http://.../?a=1&b=2', { c: 3, d: 4 });
// or pass the POST data as an form-urlencoded
var header = auth('GET', 'http://.../?a=1&b=2', 'c=3&d=4');
```

@@ -45,2 +45,9 @@ if (typeof require !== 'undefined') {

});
describe('#headerGenerator', function() {
it('generates a header function', function() {
expect(ohauth.headerGenerator({})).to.be.a(Function);
expect(ohauth.headerGenerator({})('GET', 'http://foo.com/')).to.be.a.string;
});
});
});

Sorry, the diff of this file is too big to display

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