-
-
Save felixge/6411a0c3fcf4a4d15ddf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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