Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CredentialCache.DefaultCredentials and UseDefaultCredentials on .NET8 Core #2236

Open
yvovonBerg opened this issue Jul 8, 2024 · 5 comments
Labels

Comments

@yvovonBerg
Copy link

yvovonBerg commented Jul 8, 2024

Describe the bug
It appears that CredentialCache.DefaultCredentials is being used by RestSharp but it doesn't properly pass through the credentials for some reason. It should connect through Kerberos.

To Reproduce
Does not work on .NET 8 Core:

using System.Net;
using RestSharp;

class Program
{
	static void Main(string[] args)
	{
		var options = new RestClientOptions("https://secure.server.example.com") 
		{ 
			Credentials = CredentialCache.DefaultCredentials
		};

		RestClient Client = new RestClient(options);
		var request = new RestRequest("document/EXAMPLE-1");
		var response = Client.Execute(request);
		Console.WriteLine(response.ErrorMessage);
		Console.WriteLine(response.Content);
	}
}

But does work on .NETFramework v4.8

Expected behavior
It should authenticate correctly.

Stack trace
401 response from the webserver.

Desktop (please complete the following information):

  • OS: Windows 10 Enterprise
  • .NET version: .NET 8 Core
  • Version 111.3.0

Additional context
I've also tried to use the useDefaultCredentials flag and the workaround here: dotnet/runtime#84545 of swapping the credentials and useDefaultCredentials arguments but that does not resolve the issue sadly.

Thank you!

@yvovonBerg yvovonBerg added the bug label Jul 8, 2024
@alexeyzimarev
Copy link
Member

Have you tried setting UseDefaultCredentials to true?

@yvovonBerg
Copy link
Author

Have you tried setting UseDefaultCredentials to true?

Yes, the same result sadly.

@alexeyzimarev
Copy link
Member

RestSharp doesn't really do anything with those credentials apart from configuring the HTTP message handler with these parameters. I would suggest trying to use WinHttpMessageHandler as you are running on Windows. You can use RestClientOptions.ConfigureMessageHandler and configuring it explicitly.

@yvovonBerg
Copy link
Author

yvovonBerg commented Aug 1, 2024

Thanks, I tried with this as well:

			Client = new RestClient(new RestClientOptions(Url + Api)
			{
				UseDefaultCredentials = true,
				ConfigureMessageHandler = handler =>
				{
					if (handler is HttpClientHandler clientHandler)
					{
						clientHandler.UseDefaultCredentials = true;
					}

					return handler;
				}
			});

Same result :(

@alexeyzimarev
Copy link
Member

The code you tried doesn't do more than RestSharp does. I suggested using WinHttpHandler, but I don't know if it will work. If you can make it work with HttpClient, it will work with RestClient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants