Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Created February 14, 2014 10:32
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 walterhiggins/8998964 to your computer and use it in GitHub Desktop.
Save walterhiggins/8998964 to your computer and use it in GitHub Desktop.
var username, password, creds;
var challenge = function( res ) {
res.writeHead( 401, { 'WWW-Authenticate': 'Basic realm="Acme Web Application"'} );
res.end();
};
if ( req.headers.authorization ) {
creds = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString('utf8').split(':');
username = creds[0];
password = creds[1];
// authenticate here
} else {
challenge(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment