'Using NTLM/Kerberos on RestSharp since v107
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?
Solution 1:[1]
Both Credentials
and UseDefaultCredentials
are available, unlike you said, in RestClientOptions
:
/// <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; }
Solution 2:[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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexey Zimarev |
Solution 2 | Tawab Wakil |