Beispiel #1
0
        private async Task <HttpStatusCode> VerifyCaptcha(string token)
        {
            HttpResponseMessage verifyHTTPResponse = await _recaptchaService.VerifyTokenASync(token);

            string verifyBody = await verifyHTTPResponse.Content.ReadAsStringAsync();

            VerificationResponse verifyResponse = JsonConvert.DeserializeObject <VerificationResponse>(verifyBody);

            double threshold  = _options.ScoreThreshold;
            string actionName = _options.ActionName;

            if (!verifyResponse.Success)
            {
                _logger.LogWarning("Recaptcha was not successful: {0}", JsonConvert.SerializeObject(verifyResponse));
                return(HttpStatusCode.Unauthorized);
            }
            if (verifyResponse.Score < threshold || verifyResponse.Action != actionName)
            {
                _logger.LogWarning("Recaptcha could not verify humanity: {0}", JsonConvert.SerializeObject(verifyResponse));
                return(HttpStatusCode.Forbidden);
            }
            return(HttpStatusCode.OK);
        }