5

Since some time it seems the NtlmAuthenticator of RestSharp is deprecated. The somewhere mentioned method of setting setting.UseDefaultCredentials = true; isn't available either.

So how can I use NTLM or Kerberos with RestSharp?
AND NO! I cannot say the other program, that I want to use LDAP or OAuth2.0 or whatever you think is appropriate. I have a program that says: "I have an API and you can authorize by LDAP/Kerberos and then you get data!" and I am not the programmer of that API.

Has anyone an idea of how to get my data with the newer versions of RestSharp or do I have to go back to old versions?

Marcel Grüger
  • 885
  • 1
  • 9
  • 25

2 Answers2

2

To expand on Alexey's answer, here's the basic code to get v107 working with Windows authentication:

var clientOptions = new RestClientOptions("http://<server>:<port>/")
{
    UseDefaultCredentials = true  // send the current user's credentials
};

using (var client = new RestClient(clientOptions))
{
    var request = new RestRequest("users?id=117");
    var response = await client.GetAsync(request);
}
Tawab Wakil
  • 1,737
  • 18
  • 33
1

Both Credentials and UseDefaultCredentials are available, unlike you said, in RestClientOptions:

https://github.com/restsharp/RestSharp/blob/8b388fbe832633d5c89e2a42e5cf078aa36e6a28/src/RestSharp/RestClientOptions.cs#L44-L53

/// <summary>
/// In general you would not need to set this directly. Used by the NtlmAuthenticator.
/// </summary>
public ICredentials? Credentials { get; set; }

/// <summary>
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is
/// running) will be sent along to the server. The default is false.
/// </summary>
public bool UseDefaultCredentials { get; set; }
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
  • You are right, but a small explanation, that all options were transported to an underlying object, that has to be created before the client and cannot be changed after the client was created would have been nice. I found a link later where the changed from 107 to 106 were explained and there was the answer I was looking for. But thanks anyway... – Marcel Grüger Feb 01 '22 at 07:01
  • It's actually described https://restsharp.dev/v107/#restclient-and-options – Alexey Zimarev Feb 01 '22 at 08:36