Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Created October 6, 2025 09:55
Show Gist options
  • Save uzbekdev1/ded2d03596947805724ba7a7543085eb to your computer and use it in GitHub Desktop.
Save uzbekdev1/ded2d03596947805724ba7a7543085eb to your computer and use it in GitHub Desktop.
google recaptcha
public class RecaptchaResponse
{
[JsonProperty("success")]
public bool Success { get; set; }
[JsonProperty("error-codes")]
public List<string> ErrorCodes { get; set; }
}
public class GoogleService
{
private readonly AppSettings _appSettings;
public GoogleService(AppSettings appSettings)
{
_appSettings = appSettings;
}
public async Task<bool> VerifyCaptcha(string token)
{
if (!_appSettings.Config.ReadyProduction)
{
return true;
}
if (string.IsNullOrWhiteSpace(token))
{
return false;
}
var client = new HttpClient();
var response = await client.GetAsync($"https://www.google.com/recaptcha/api/siteverify?secret={_appSettings.RecaptchaSecret}&response={token}");
if (!response.IsSuccessStatusCode)
{
return false;
}
var json = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<RecaptchaResponse>(json);
return result.Success;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment