Skip to content

Instantly share code, notes, and snippets.

@felixge
Created February 8, 2010 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixge/6411a0c3fcf4a4d15ddf to your computer and use it in GitHub Desktop.
Save felixge/6411a0c3fcf4a4d15ddf to your computer and use it in GitHub Desktop.
var base64 = require('../dep/base64');
// Guards a realm from unauthorized access
exports.fabware = function(user, pass, realm) {
var expected = 'Basic '+base64.encode(user+':'+pass);
realm = realm || 'Secure Area';
return function(handler) {
return function(respond) {
if (this.headers['authorization'] !== expected) {
return {
status: 401,
headers: {'WWW-Authenticate': 'Basic realm="'+realm+'"'},
};
}
// Stream the data if auth is successful
handler.call(this, respond);
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment