Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deprecate HttpClient property
Deprecate the HttpClient property and use the built-in Backchannel property instead.
  • Loading branch information
martincostello committed Sep 14, 2019
commit 7786f45a99133c5b20587060e5789ea131a60810
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(OpenIdAuthenticationConstants.Media.Json));

// Return the authentication ticket as-is if the userinfo request failed.
var response = await Options.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
var response = await Options.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
if (!response.IsSuccessStatusCode)
{
Logger.LogWarning("The userinfo request failed because an invalid response was received: the identity provider " +
Expand Down
2 changes: 1 addition & 1 deletion src/AspNet.Security.OpenId/OpenIdAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private async Task<bool> VerifyAssertionAsync([NotNull] OpenIdAuthenticationMess
Content = new FormUrlEncodedContent(payload)
};

var response = await Options.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
var response = await Options.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
if (!response.IsSuccessStatusCode)
{
Logger.LogWarning("The authentication failed because an invalid check_authentication response was received: " +
Expand Down
19 changes: 8 additions & 11 deletions src/AspNet.Security.OpenId/OpenIdAuthenticationInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ public void PostConfigure([NotNull] string name, [NotNull] TOptions options)
options.HtmlParser = new HtmlParser();
}

if (options.HttpClient == null)
if (options.Backchannel == null)
{
options.HttpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(30),
MaxResponseContentBufferSize = 1024 * 1024 * 10
};

options.HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("ASP.NET Core OpenID 2.0 middleware");
options.Backchannel = new HttpClient(options.BackchannelHttpHandler ?? new HttpClientHandler());
options.Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("ASP.NET Core OpenID 2.0 middleware");
options.Backchannel.Timeout = options.BackchannelTimeout;
options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB
}

if (options.ConfigurationManager == null)
Expand Down Expand Up @@ -140,13 +137,13 @@ public void PostConfigure([NotNull] string name, [NotNull] TOptions options)

options.ConfigurationManager = new ConfigurationManager<OpenIdAuthenticationConfiguration>(
options.MetadataAddress?.AbsoluteUri ?? options.Authority.AbsoluteUri,
new OpenIdAuthenticationConfiguration.Retriever(options.HttpClient, options.HtmlParser)
new OpenIdAuthenticationConfiguration.Retriever(options.Backchannel, options.HtmlParser)
{
MaximumRedirections = options.MaximumRedirections
},
new HttpDocumentRetriever(options.HttpClient) { RequireHttps = options.RequireHttpsMetadata });
new HttpDocumentRetriever(options.Backchannel) { RequireHttps = options.RequireHttpsMetadata });
}
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/AspNet.Security.OpenId/OpenIdAuthenticationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ public OpenIdAuthenticationOptions()
/// <summary>
/// Gets or sets the HTTP client used to communicate with the OpenID provider.
/// </summary>
public HttpClient HttpClient { get; set; }
[Obsolete("Use the Backchannel property instead.")]
public HttpClient HttpClient
{
get => Backchannel;
set => Backchannel = value;
}

/// <summary>
/// Gets or sets the HTML parser used to parse discovery documents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected OpenIdTests()
protected virtual void ConfigureDefaults(AuthenticationBuilder builder, TOptions options)
{
options.Backchannel = CreateBackchannel(builder);
options.HttpClient = options.Backchannel;
}

/// <summary>
Expand Down