Sha256: ec22f4b2b9cc8b25bb42919810d9fd4344493c977599a8c52e420a062bfa9f5d

Contents?: true

Size: 953 Bytes

Versions: 6

Compression:

Stored size: 953 Bytes

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vulcan-0.8.2 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js
vulcan-0.8.1 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js
vulcan-0.8.0 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js
vulcan-0.7.2 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js
vulcan-0.7.1 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js
vulcan-0.7.0 server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js