Skip to content

Commit

Permalink
Fixed little issue.
Browse files Browse the repository at this point in the history
Added a sign method.
  • Loading branch information
eschnou committed Feb 20, 2011
1 parent f8deb40 commit 15c8ef9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/ostatus/push.js
Expand Up @@ -63,23 +63,27 @@ function subscribe(url, config, callback) {
console.log("Data: " + data); console.log("Data: " + data);
Http.post(url, data, headers, function(err, response, body) { Http.post(url, data, headers, function(err, response, body) {
if (err) return callback(err); if (err) return callback(err);
if (response.statusCode == 200) { if (response.statusCode == 202) {
callback(null, "pending"); callback(null, "pending");
} else if (response.statusCode == 204) { } else if (response.statusCode == 204) {
callback(null, "accepted"); callback(null, "accepted");
} else { } else {
callback(new Error("Push subscribe returned http status code " + response.statusCode)); callback(new Error("Push subscribe http error " + response.statusCode + "\n" + body));
} }
}); });
} }


function sign(data, secret) {
var hmac = Crypto.createHmac("sha1", secret);
var hash = hmac.update(data);
return hmac.digest(encoding="hex");
}

function distribute(data, url, secret, callback) { function distribute(data, url, secret, callback) {
var headers = {"Content-Type": "application/atom-xml"}; var headers = {"Content-Type": "application/atom-xml"};


if (secret != undefined) { if (secret != undefined) {
var hmac = Crypto.createHmac("sha1", secret); var digest = "sha1="+ sign(data, secret);
var hash = hmac.update(data);
var digest = "sha1="+ hmac.digest(encoding="hex");
headers["X-Hub-Signature"] = digest; headers["X-Hub-Signature"] = digest;
console.log("Digest: " + digest); console.log("Digest: " + digest);
} }
Expand Down Expand Up @@ -107,3 +111,4 @@ function _secret(size) {
exports.verify = verify; exports.verify = verify;
exports.distribute = distribute; exports.distribute = distribute;
exports.subscribe = subscribe; exports.subscribe = subscribe;
exports.sign = sign;

0 comments on commit 15c8ef9

Please sign in to comment.