summaryrefslogtreecommitdiff
path: root/node_modules/request/oauth.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/request/oauth.js
ok
Diffstat (limited to 'node_modules/request/oauth.js')
-rw-r--r--node_modules/request/oauth.js34
1 files changed, 34 insertions, 0 deletions
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