6

I'm looking into phantomjs as a possible solution for UI automation in my latest project, but I can't seem to get windows authentication to work properly. I've tried setting the page.settings.userName and page.settings.password, but the snippet below always gets a 401 and the underlying stack makes no effort to resolve it. My search-fu has failed me, so I come to the community to ask for help.

var page = require('webpage').create();

page.onResourceReceived = function(response) {
    phantom.exit(response.status);
};

page.open('http://bing.com');
BenWurth
  • 790
  • 1
  • 7
  • 23
Neil
  • 417
  • 5
  • 12

3 Answers3

2

There is an open PhantomJS Issue with ongoing discussion. It appears that PhantomJS does not support (automatic/integrated) NTLM Authentication, meaning that it will not work against a server that requires Integrated Windows Authentication.

chiccodoro
  • 14,407
  • 19
  • 87
  • 130
Adrian Russell
  • 3,995
  • 5
  • 25
  • 26
  • Any updates on this issue? does phantomjs support windows auth now? – SharpCoder Nov 24 '15 at 21:52
  • It looks like Phantom JS 2.0 can be made to support NTLM/Kerberos authentication. Although it does not look like it does this out of the box. See - https://github.com/ariya/phantomjs/issues/13262 – Adrian Russell Nov 25 '15 at 05:10
0

You can add your domain credentials to the URL:

var driver = new PhantomJSDriver();
driver.Manage().Window.Size = new System.Drawing.Size(1024, 1024);
driver.Url = "http://myusername:mypassword@localhost/myapp";

I think this might be a version 2 thing, I'm not sure. AFAIK no support for passing through credentials of the current user, which is a shame.

BenWurth
  • 790
  • 1
  • 7
  • 23
Rocklan
  • 7,888
  • 3
  • 34
  • 49
0

For me this case works perfect. mike-rogers solution

var _driverOptions = new PhantomJSOptions();
var _driverService = PhantomJSDriverService.CreateDefaultService();
_driverOptions.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
_driver = new PhantomJSDriver(_driverService, _driverOptions);


using (Impersonation.LogonUser(domain, login, pass, LogonType.Interactive))
{
    using (var proxy = new NtlmProxy(new Uri("http://yoursite.com/"), options))
    {
        _driver.Navigate().GoToUrl(url);
    }
 }
BenWurth
  • 790
  • 1
  • 7
  • 23
Pavel Kononenko
  • 318
  • 3
  • 15