public RecaptchaResponse Validate(RecaptchaRequest recaptchaRequest) { var result = new RecaptchaResponse { Success = false }; var request = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("secret", _configurationManager.GetAppSettingAs<string>(AppSettingsRecaptchaSecretKey)), new KeyValuePair<string, string>("response", recaptchaRequest.Token), new KeyValuePair<string, string>("remoteip", recaptchaRequest.IpAddress) }); var response = _client.PostAsync(ApiUrl, request).Result; if (response.IsSuccessStatusCode) { var contents = response.Content.ReadAsStringAsync().Result; if (!string.IsNullOrEmpty(contents)) { result = JsonConvert.DeserializeObject<RecaptchaResponse>(contents, new StringEnumConverter()); } } return result; }
public static void AddRecaptchaErrors(this ModelStateDictionary modelState, RecaptchaResponse recaptchaResponse) { if (recaptchaResponse?.ErrorCodes == null) return; foreach (var errorCode in recaptchaResponse.ErrorCodes) { modelState.AddModelError("ReCAPTCHA", errorCode.ToString()); } }