Skip to content

Negotiate to NTLM authentication fallback not working #119298

@FixRM

Description

@FixRM

Description

Hello! I faced the same issue as #28531 but on Windows and net9.0.

Thank you.

Reproduction Steps

I.m using YARP to proxy requests to IIS powered WebApi service that is using Windows authentication. SocketsHttpHandler is used in the following way:

.ConfigureHttpClient((ForwarderHttpClientContext context, SocketsHttpHandler handler) =>
{
    // https://github.com/dotnet/yarp/issues/166#issuecomment-1286334749
    handler.Credentials = CredentialCache.DefaultNetworkCredentials;
})

It works well for instances that have valid Kerberos configuration but it returns 401 if it's not instead of switching to NTLMv2.

Expected behavior

SocketsHttpHandler is autenticated

Actual behavior

I got 401 HTTP response

Regression?

Framework-based HTTP clients seems to be working

Known Workarounds

I can workaround it with custom ICredentials implementation that is forcing to use NTML like this:

public class FallbackToNtmlCredentialManager : ICredentials
{
    public NetworkCredential? GetCredential(Uri uri, string authType)
    {
        if (!string.Equals(authType, "NTLM", StringComparison.InvariantCultureIgnoreCase))
            return null;
        
        return CredentialCache.DefaultNetworkCredentials;        
    }
}

Configuration

net9.0
Windows Server 2016
x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.Httpneeds-author-actionAn issue or pull request that requires more info or actions from the author.questionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions