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 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class ReCaptchaService
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger _logger;
protected readonly IStringLocalizer S;
private HttpClient _httpClient;

private string _verifyHost;

public ReCaptchaService(
IHttpClientFactory httpClientFactory,
Expand Down Expand Up @@ -124,8 +125,10 @@ 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));
_verifyHost ??= $"{_reCaptchaSettings.ReCaptchaApiUri.TrimEnd('/')}/siteverify";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the constructor, make field readonly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros done. Is there a reason for this request? what I had did the same thing except that we don't initialize until needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't need to be tested for null each time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. let me know if you want anything else changed or let's merge it


var response = await httpClient.PostAsync(_verifyHost, content);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ReCaptchaResponse>(_jsonSerializerOptions);

Expand Down
Loading