Skip to content

HttpClient - control of ImpersonationLevel lost by deprecation of HttpWebRequestΒ #100895

@mrsvk

Description

@mrsvk

Description

HttpWebRequest allows the user to specify the TokenImpersonationLevel for Windows Authentication in .NET Framework, and it defaulted to Delegation. On HttpClient, it defaults to Impersonation, and the user does not have the ability to change it as needed for a given request. This leaves no supported path in .NET to connect to web servers where Kerberos Delegation is required.

Reproduction Steps

Since this is a missing feature, I'll just link to documentation here:

.NET Framework documentation shows the available property on WebRequest: https://learn.microsoft.com/en-us/dotnet/api/system.net.webrequest.impersonationlevel?view=netframework-4.8.1

There is no corresponding property for .NET 6 or 8 for HttpClient, SocketsHttpHandler, or HttpRequestMessage.

Expected behavior

There should be a property somewhere that the user can use to specify the ability to use Delegation credentials for a specific request or set of requests.

Actual behavior

Using HttpClient to access our internal web servers that require delegable credentials fails.

Regression?

No response

Known Workarounds

While I am not endorsing this in any way, I was able to use https://www.nuget.org/packages/Lib.Harmony and reflection to inject code to only change the value of ImpersonationLevel to verify that is indeed the only reason this does not work. While that was workable as a test scenario, I would never endorse it for production code.

Configuration

No response

Other information

For .NET 8, this is hard-coded beyond user access in the function SendWithNtAuthAsync in System.Net.Http's AuthenticationHelper.NtAuth.cs, specifically in how it creates the NegotiateAuthentication helper class.

The NegotiateAuthentication class already supports the capability, as the user can already control it on NegotiateStream. All that is missing is a public property somewhere for the user to specify it when using HttpClient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions