Skip to content

auth.js

Mark Watson edited this page Sep 14, 2016 · 1 revision

When a page requires HTTP authentication (when the browsers displays a Basic/Digest/NTLM login dialog), you can set the username and password ahead of time, so that dialog is bypassed. Authentication still happens as it would if you manually typed in the username / password, with the initial request coming back with a 401 status code and then the browser making a follow up request with the 'Authentication' header set.

// Open the browser, but don't go to the page until we set the username / password
var b = pizza.open();

// Set username and password to be used for HTTP Authentication
// This will work with both Basic and Digest HTTP Authentication
b.setAuth("httpwatch", utils.randomString());

// Go to a page that requires authentication
b.open("http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx");

Clone this wiki locally