diff --git a/src/Microsoft.IdentityModel.Clients.ActiveDirectory/AuthenticationContext.cs b/src/Microsoft.IdentityModel.Clients.ActiveDirectory/AuthenticationContext.cs index d77363ce9..972b526b8 100644 --- a/src/Microsoft.IdentityModel.Clients.ActiveDirectory/AuthenticationContext.cs +++ b/src/Microsoft.IdentityModel.Clients.ActiveDirectory/AuthenticationContext.cs @@ -121,12 +121,8 @@ public AuthenticationContext(string authority, bool validateAuthority, TokenCach /// ADAL does not guarantee that it will not modify the HttpClient, for example by adding new headers. public AuthenticationContext(string authority, bool validateAuthority, TokenCache tokenCache, IHttpClientFactory httpClientFactory) : this(null, authority, validateAuthority ? AuthorityValidationType.True : AuthorityValidationType.False, - tokenCache, httpClientFactory) + tokenCache, ValidateNotNull(httpClientFactory)) { - if (httpClientFactory == null) - { - throw new ArgumentNullException(nameof(httpClientFactory)); - } } internal AuthenticationContext(IServiceBundle serviceBundle, string authority, AuthorityValidationType validateAuthority, @@ -141,6 +137,15 @@ internal AuthenticationContext(IServiceBundle serviceBundle, string authority, A TokenCache?.SetServiceBundle(_serviceBundle); } + private static IHttpClientFactory ValidateNotNull(IHttpClientFactory httpClientFactory) + { + if (httpClientFactory == null) + { + throw new ArgumentNullException(nameof(httpClientFactory)); + } + return httpClientFactory; + } + /// /// Used to set the flag for AAD extended lifetime /// diff --git a/src/Microsoft.IdentityModel.Clients.ActiveDirectory/Core/ServiceBundle.cs b/src/Microsoft.IdentityModel.Clients.ActiveDirectory/Core/ServiceBundle.cs index c92587bc0..cc2b39a96 100644 --- a/src/Microsoft.IdentityModel.Clients.ActiveDirectory/Core/ServiceBundle.cs +++ b/src/Microsoft.IdentityModel.Clients.ActiveDirectory/Core/ServiceBundle.cs @@ -71,7 +71,7 @@ internal static IServiceBundle CreateWithHttpClientFactory(IHttpClientFactory ht { if (httpClientFactory != null) { - return new ServiceBundle(new HttpClientFactory()); + return new ServiceBundle(httpClientFactory); } else {