Esempio n. 1
0
        public async Task <bool> ValidateRecaptcha(string ApiSecretKey, string TokenResponse)
        {
            if (string.IsNullOrEmpty(TokenResponse))
            {
                throw new ArgumentException(nameof(TokenResponse));
            }

            using (HttpClient webClient = this._clientFactory.CreateClient())
            {
                FormUrlEncodedContent content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("secret", ApiSecretKey),
                    new KeyValuePair <string, string>("response", TokenResponse)
                });
                HttpResponseMessage response = await webClient.PostAsync(API_VERIFICATION_LINK, content);

                string json = await response.Content.ReadAsStringAsync();

                ReCaptchaResponse reCaptchaResponse = JsonConvert.FromMessage <ReCaptchaResponse>(json);
                if (reCaptchaResponse != null && reCaptchaResponse.success)
                {
                    return(true);
                }
            }

            return(false);
        }