Share via


BaseAbstractApplicationBuilder<T>.WithHttpClientFactory Method

Definition

Overloads

WithHttpClientFactory(IMsalHttpClientFactory)

Uses a specific IMsalHttpClientFactory to communicate with the IdP. This enables advanced scenarios such as setting a proxy, or setting the Agent.

WithHttpClientFactory(IMsalHttpClientFactory, Boolean)

Uses a specific IMsalHttpClientFactory to communicate with the IdP. This enables advanced scenarios such as setting a proxy, or setting the Agent.

WithHttpClientFactory(IMsalHttpClientFactory)

Uses a specific IMsalHttpClientFactory to communicate with the IdP. This enables advanced scenarios such as setting a proxy, or setting the Agent.

public T WithHttpClientFactory (Microsoft.Identity.Client.IMsalHttpClientFactory httpClientFactory);
member this.WithHttpClientFactory : Microsoft.Identity.Client.IMsalHttpClientFactory -> 'T
Public Function WithHttpClientFactory (httpClientFactory As IMsalHttpClientFactory) As T

Parameters

httpClientFactory
IMsalHttpClientFactory

HTTP client factory

Returns

T

The builder to chain the .With methods

Remarks

MSAL does not guarantee that it will not modify the HttpClient, for example by adding new headers. Prior to the changes needed in order to make MSAL's httpClients thread safe (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/pull/2046/files), the httpClient had the possibility of throwing an exception stating "Properties can only be modified before sending the first request". MSAL's httpClient will no longer throw this exception after 4.19.0 (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/releases/tag/4.19.0) see (https://aka.ms/msal-httpclient-info) for more information.

Applies to

WithHttpClientFactory(IMsalHttpClientFactory, Boolean)

Uses a specific IMsalHttpClientFactory to communicate with the IdP. This enables advanced scenarios such as setting a proxy, or setting the Agent.

public T WithHttpClientFactory (Microsoft.Identity.Client.IMsalHttpClientFactory httpClientFactory, bool retryOnceOn5xx);
member this.WithHttpClientFactory : Microsoft.Identity.Client.IMsalHttpClientFactory * bool -> 'T
Public Function WithHttpClientFactory (httpClientFactory As IMsalHttpClientFactory, retryOnceOn5xx As Boolean) As T

Parameters

httpClientFactory
IMsalHttpClientFactory

HTTP client factory

retryOnceOn5xx
Boolean

Configures MSAL to retry on 5xx server errors. When enabled (on by default), MSAL will wait 1 second after receiving a 5xx error and then retry the http request again.

Returns

T

The builder to chain the .With methods

Remarks

MSAL does not guarantee that it will not modify the HttpClient, for example by adding new headers. Prior to the changes needed in order to make MSAL's httpClients thread safe (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/pull/2046/files), the httpClient had the possibility of throwing an exception stating "Properties can only be modified before sending the first request". MSAL's httpClient will no longer throw this exception after 4.19.0 (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/releases/tag/4.19.0) see (https://aka.ms/msal-httpclient-info) for more information. If you only want to configure the retryOnceOn5xx parameter, set httpClientFactory to null and MSAL will use the default http client.

Applies to