Skip to content

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

License

Notifications You must be signed in to change notification settings

johntoopublic/authlink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

authlink npm downloads npm version license

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);
});

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published