Skip to content

Instantly share code, notes, and snippets.

@vitallium
Created March 31, 2013 09:35
Show Gist options
  • Select an option

  • Save vitallium/5280125 to your computer and use it in GitHub Desktop.

Select an option

Save vitallium/5280125 to your computer and use it in GitHub Desktop.
var page = require('webpage').create();
var server = require('webserver').create();
server.listen(12345, function(request, response) {
if (request.headers['Authorization']) {
var encAuth = request.headers['Authorization'].substring(6);
var credentials = atob(encAuth);
response.statusCode = 200
response.write('Provided credentials:' + credentials);
console.log(credentials);
} else {
response.statusCode = 401;
response.setHeader('WWW-Authenticate', 'Basic realm="Basic Auth test"');
response.write('Authentication Required');
response.close();
}
});
page.settings.userName = 'test';
page.settings.password = 'pwd';
page.open('http://localhost:12345', function(status) {
if (status === 'success') {
phantom.exit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment