21

I am trying to use NTLM authentication for my REST calls to TeamCity using RestSharp.

IRestClient _client=new RestClient(_url);
_client.Authenticator = new NtlmAuthenticator            
(System.Net.CredentialCache.DefaultNetworkCredentials);

However it is not working. Please suggest if I am missing something.

Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
pinaki
  • 251
  • 1
  • 3
  • 5
  • How to implement the same using jQuery ajax? I want to consume a rest service which is in.. svc format, and fetch the json data.. – samolpp2 Apr 16 '19 at 06:30

4 Answers4

41

This now appears to be working properly and can be done very easily utilizing the NTLMAuthenticator like so:

RestClient client = new RestClient(_baseURL);
client.Authenticator = new NtlmAuthenticator();
cjones26
  • 3,459
  • 1
  • 34
  • 51
  • 7
    If you use this method don't forget to add a `using RestSharp.Authenticators;` line. – Caltor May 03 '17 at 08:23
  • 3
    no longer works in RestSharp 1.07+, I switched to System.Net.WebClient due to the frustration this caused – Ekus Sep 27 '22 at 02:53
10

Try this:

var client = new RestClient(_baseURL)
{
     Authenticator = new RestSharp.Authenticators.NtlmAuthenticator()
};
arghtype
  • 4,376
  • 11
  • 45
  • 60
curt
  • 151
  • 1
  • 4
4

As of RestSharp v107, The NtlmAuthenticator is deprecated.

This worked for me:

var credentials = new NetworkCredential(username, password, domain);
var options = new RestClientOptions(_settings.ServiceEndPoint)
{
 UseDefaultCredentials = false,
 Credentials=credentials
};
var client = new RestClient(options);
0

Not supported currently. Refer to the below thread.

http://devnet.jetbrains.com/thread/451079?tstart=0

pinaki
  • 251
  • 1
  • 3
  • 5