michaelvs97 / AspNetCore.ReCaptcha

Google ReCAPTCHA v2/v3 Library for .NET Core 3.x/5.x
https://www.nuget.org/packages/AspNetCore.ReCaptcha/
MIT License
73 stars 20 forks source link

Recaptcha keeps failing #40

Closed DustSwiffer closed 2 years ago

DustSwiffer commented 2 years ago

Hi guys!

I am trying to use your nuget but struggling with the intregration.
I have implemented the nuget like told in the readme but once I try to submit my request it will fail based the the Recaptcha Value. Just double checked if my appsettings is filled with the correct keys and it is. so thats not the case. @Html.Recaptcha() is rendering the badge without any error.

I hope you guys can help me out. (if you need anything else of information let me know)

part of the form where the recaptcha needs to be rendered

@using (Html.BeginForm("SendContactMessage", "Contact", FormMethod.Post, new { @class = "form" }))
{
  <div class="form-group">
    @Html.LabelFor(m => m.Message)
    @Html.TextAreaFor(m => m.Message, new { @class = "form-control message-area" })
    @Html.ValidationMessageFor(m => m.Message)
  </div>
  <div class="form-group">
    @Html.ReCaptcha(language: "nl-NL")
    <input class="btn btn-lg btn-dustswiffer" type="submit" value="Verstuur" />
  </div>
}

Part of method thats being called after submitting the form

[HttpPost]
[ValidateReCaptcha]
public async Task<IActionResult> SendContactMessage(ContactViewModel viewmodel, CancellationToken cancellationToken)
{
  if (!ModelState.IsValid)
  {
    return View("Index", viewmodel);
  }
}     

image

update: using v3

DustSwiffer commented 2 years ago

Solved apparently the nuget is using inline scripts which made it impossible to generate a key. sadly have to add unsafe-inline to my headers

chamaliperera512 commented 6 months ago

@DustSwiffer im facing the exact same issue, can you elaborate what you added in CSP?