Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup ReCaptchaService after changing the registration type #14587

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class ReCaptchaService
private readonly IEnumerable<IDetectRobots> _robotDetectors;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger _logger;
private readonly string _verifyHost;
protected readonly IStringLocalizer S;
private HttpClient _httpClient;

public ReCaptchaService(
IHttpClientFactory httpClientFactory,
Expand All @@ -40,6 +40,7 @@ public ReCaptchaService(
{
_httpClientFactory = httpClientFactory;
_reCaptchaSettings = optionsAccessor.Value;
_verifyHost = $"{optionsAccessor.Value.ReCaptchaApiUri?.TrimEnd('/')}/siteverify";
_robotDetectors = robotDetectors;
_httpContextAccessor = httpContextAccessor;
_logger = logger;
Expand Down Expand Up @@ -124,8 +125,8 @@ private async Task<bool> VerifyAsync(string responseToken)
{ "response", responseToken }
});

_httpClient ??= _httpClientFactory.CreateClient(nameof(ReCaptchaService));
var response = await _httpClient.PostAsync($"{_reCaptchaSettings.ReCaptchaApiUri.TrimEnd('/')}/siteverify", content);
var httpClient = _httpClientFactory.CreateClient(nameof(ReCaptchaService));
var response = await httpClient.PostAsync(_verifyHost, content);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ReCaptchaResponse>(_jsonSerializerOptions);

Expand Down
Loading