Permalink
Browse files

Fixed little issue.

Added a sign method.
  • Loading branch information...
1 parent f8deb40 commit 15c8ef94b8e243b7062ec1e891ed2d0441b4d576 @eschnou committed Feb 20, 2011
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/ostatus/push.js
View
@@ -63,23 +63,27 @@ function subscribe(url, config, callback) {
console.log("Data: " + data);
Http.post(url, data, headers, function(err, response, body) {
if (err) return callback(err);
- if (response.statusCode == 200) {
+ if (response.statusCode == 202) {
callback(null, "pending");
} else if (response.statusCode == 204) {
callback(null, "accepted");
} 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) {
var headers = {"Content-Type": "application/atom-xml"};
if (secret != undefined) {
- var hmac = Crypto.createHmac("sha1", secret);
- var hash = hmac.update(data);
- var digest = "sha1="+ hmac.digest(encoding="hex");
+ var digest = "sha1="+ sign(data, secret);
headers["X-Hub-Signature"] = digest;
console.log("Digest: " + digest);
}
@@ -107,3 +111,4 @@ function _secret(size) {
exports.verify = verify;
exports.distribute = distribute;
exports.subscribe = subscribe;
+exports.sign = sign;

0 comments on commit 15c8ef9

Please sign in to comment.