Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Ensure the HttpClientFactory is being passed in (#1566)
Browse files Browse the repository at this point in the history
* httpclient null fix

* add validateNotNull
  • Loading branch information
jennyf19 authored and bgavrilMS committed Apr 1, 2019
1 parent c66dc64 commit d4caf90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ public AuthenticationContext(string authority, bool validateAuthority, TokenCach
/// <remarks>ADAL does not guarantee that it will not modify the HttpClient, for example by adding new headers.</remarks>
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,
Expand All @@ -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;
}

/// <summary>
/// Used to set the flag for AAD extended lifetime
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal static IServiceBundle CreateWithHttpClientFactory(IHttpClientFactory ht
{
if (httpClientFactory != null)
{
return new ServiceBundle(new HttpClientFactory());
return new ServiceBundle(httpClientFactory);
}
else
{
Expand Down

0 comments on commit d4caf90

Please # to comment.