Skip to content

Commit

Permalink
Update readme how to use the IReCaptchaService directly (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeuwen authored Dec 28, 2023
1 parent cc4450d commit 70a797c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion AspNetCore.ReCaptcha/ValidateReCaptchaAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private async Task ValidateRecaptcha(ActionContext context)
// Nothing to do - reCAPTCHA is not enabled / enforced.
return;
}

if (!context.HttpContext.Request.HasFormContentType)
{
context.ModelState.AddModelError("", GetErrorMessage(context));
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public IActionResult SubmitForm(ContactViewModel model)
}
```

### Manual Validation
If you need to validate a recaptcha but cannot use the `[ValidateReCaptcha]` attribute for some reason (maybe you're using a JSON POST instead of form POST).
In that case you can inject the `AspNetCore.ReCaptcha.IReCaptchaService` service and use one of the two methods on there:
`VerifyAsync` verifies the provided token against the recaptcha service and returns whether or not it is successful. For V3 this also checks if the score is greater than or equal to the ScoreThreshold that can be configured in the appsettings.
`GetVerifyResponseAsync` calls the recaptcha service with the provided token and returns the response. The response will contain whether it is successful or not and for V3 what the score is.

### Language support
By default, AspNetCore.ReCaptcha will use the language that is being used in the request. So we will make use of the Culture of the `HttpContext`. However, you can override this by specifying a language in the ReCaptcha element. This is shown in the next example:
```cshtml
Expand Down

0 comments on commit 70a797c

Please sign in to comment.