Skip to content

Commit

Permalink
Cleanup ReCaptchaService after changing the registration type (#14587)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Oct 26, 2023
1 parent 24be30f commit 59521a1
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 59521a1

Please sign in to comment.