Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme how to use the IReCaptchaService directly #63

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading