Skip to content

Commit

Permalink
Add support for Basic Access Authentication in .NET RemoteWebDriver
Browse files Browse the repository at this point in the history
The username and password of the Uri wasn't used by the HttpWebRequest.

Usage example
new RemoteWebDriver(new Uri("http://user:pass@example.com/wd/hub"), DesiredCapabilities.Chrome());

Signed-off-by: Jim Evans <james.h.evans.jr@gmail.com>
  • Loading branch information
betrisey authored and jimevans committed Mar 27, 2018
1 parent c332712 commit 8910104
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ private static string GetTextOfWebResponse(HttpWebResponse webResponse)
private HttpResponseInfo MakeHttpRequest(HttpRequestInfo requestInfo)
{
HttpWebRequest request = HttpWebRequest.Create(requestInfo.FullUri) as HttpWebRequest;
if (!string.IsNullOrEmpty(requestInfo.FullUri.UserInfo) && requestInfo.FullUri.UserInfo.Contains(":"))
{
string[] userInfo = this.remoteServerUri.UserInfo.Split(new char[] { ':' }, 2);
request.Credentials = new NetworkCredential(userInfo[0], userInfo[1]);
request.PreAuthenticate = true;
}

request.Method = requestInfo.HttpMethod;
request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
request.Accept = RequestAcceptHeader;
Expand Down

0 comments on commit 8910104

Please sign in to comment.