0.2.0 • Published 10 years ago

authlink v0.2.0

Weekly downloads
2
License
Unlicense
Repository
github
Last release
10 years ago

authlink

A simple node.js middleware to generate and check HMAC signed cookies for lightweight authentication.

 ~ npm start

> authlink@0.2.0 start /root/src/authlink
> node index.js

Call authlink.generate() for a keypair or add
authlink({hashes:['eYRYURogrkOdhnhmKbAiSpBFff/D+8x9OgGv9WvuY6U=']})
and then authenticate on authlink.sign with the querystring
?key=CKkPt%2B33Cl8hfWWNwrVcmWPLFCNIHxp4

sign generates the cookie as a standard request, and redirects to authlink({redirect:'url'}) or ?path=url.

function (req, res) {
  authlink.sign(req, res)
}

auth checks the generated cookie.

var authlink = require('authlink');
// [auth](/index.js#L19) is a request wrapper,
// throwing an error if there's not a specified key.
function (req, res) {
  authlink.auth(req, function(e) {
    if (!e) {
      res.writeHead(200);
      // ...
    }
  });
}
// Also allows authenticating socket.io requests.
io(server).use(function(socket, next) {
  authlink.auth(socket.request, next);
});
0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago