I have added invisible reCaptcha V3 to asp.net core 6.0 Angular SPA.
- Registration MVC page HTML:
. . .
<input type="hidden" name="captcha" id="captchaInput" value="" />
</form>
. . .
@section Scripts {
<script src="https://www.google.com/recaptcha/api.js?render=@Configuration["Recaptcha:siteKey"]"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('@Configuration["Recaptcha:siteKey"]', { action: 'contact' }).then(function (token) {
$("#captchaInput").val(token);
});
});
</script>
<partial name="_ValidationScriptsPartial" />
}
CS
if (ModelState.IsValid)
{
if (!await _captchaValidator.IsCaptchaPassedAsync(captcha))
ModelState.AddModelError("captcha", "Captcha validation failed");
There is OIDC controller with reCaptcha validator injected.
Everything is working. Until the validation fails (for example low score).
User cannot proceed forward from this point.
I would expect captcha to become regular visible challenge.
I need a workable solution - how to give a user second chance to prove they arent a robot in case when reCaptcha v3 validation failed (for whatever reason).
credits to: https://github.com/Jarda29/GoogleReCaptcha.V3