From 686106d544ecc3b6ffd4db2b665d3bc879a58d8c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 24 Sep 2012 16:22:07 -0400 Subject: ok --- node_modules/request/oauth.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 node_modules/request/oauth.js (limited to 'node_modules/request/oauth.js') diff --git a/node_modules/request/oauth.js b/node_modules/request/oauth.js new file mode 100644 index 0000000..25db669 --- /dev/null +++ b/node_modules/request/oauth.js @@ -0,0 +1,34 @@ +var crypto = require('crypto') + , qs = require('querystring') + ; + +function sha1 (key, body) { + return crypto.createHmac('sha1', key).update(body).digest('base64') +} + +function rfc3986 (str) { + return encodeURIComponent(str) + .replace('!','%21') + .replace('*','%2A') + .replace('(','%28') + .replace(')','%29') + .replace("'",'%27') + ; +} + +function hmacsign (httpMethod, base_uri, params, consumer_secret, token_secret, body) { + // adapted from https://dev.twitter.com/docs/auth/oauth + var base = + httpMethod + "&" + + encodeURIComponent( base_uri ) + "&" + + Object.keys(params).sort().map(function (i) { + // big WTF here with the escape + encoding but it's what twitter wants + return escape(rfc3986(i)) + "%3D" + escape(rfc3986(params[i])) + }).join("%26") + var key = consumer_secret + '&' + if (token_secret) key += token_secret + return sha1(key, base) +} + +exports.hmacsign = hmacsign +exports.rfc3986 = rfc3986 \ No newline at end of file -- cgit v1.2.3-70-g09d2