Skip to content

NTLM Authorization #3457

@DavidM29

Description

@DavidM29

Hello,

I have been searching, but I have not been able to find how to use NTLM Authorization when using OData Connected Service DataServiceContext.

Only way I have found for now is to ConfigureHttpClientDefaults like this:

builder.Services.AddHttpClient();
builder.Services.ConfigureHttpClientDefaults(clientBuilder =>
{
    clientBuilder.ConfigurePrimaryHttpMessageHandler(() =>
    {
        string domain = string.Empty;
        string serviceUsername = ApplicationSettings.ServiceUsername;
        string servicePassword = ApplicationSettings.ServicePassword;

        if (serviceUsername.Contains('\\'))
        {
            var domainAndUser = serviceUsername.Split('\\');
            domain = domainAndUser[0];
            serviceUsername = domainAndUser[1];
        }

        HttpClientHandler handler = new HttpClientHandler();
        handler.Credentials = new NetworkCredential(serviceUsername, servicePassword, domain);
        return handler;
    });
});

and then use the IHttpClientFactory with the DataServiceContext.

This works well, but my issue with it is that I have to configure the default HttpClients generated by the IHttpClientFactory to use NTLM Authorization, so now if I want to use a HttpClient without the NTLM Authorization, I have to use a named HttpClient. I think It would be more convenient if we were able to use named HttpClients with DataServiceContext.

Originally posted by @DavidM29 in #3248

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions