You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
While the library is definitely functional, debugging of failed captcha verifications is nigh impossible (as far as I can tell). The error-codes field in the response from Google reCAPTCHA is ignored and there is no out-of-the-box logging of responses
Describe the solution you'd like
I've forked the source code and took a stab at implementing something, I've:
added an ErrorCodes property for the ReCaptchaResponse class to receive the error codes returned by the API
[JsonPropertyName("error-codes")]
public string[] ErrorCodes { get; set; }
changed the ReCaptchaService.GetVerifyResponseAsync method to include the following:
var stringResult = await result.Content.ReadAsStringAsync();
var obj = JsonSerializer.Deserialize<ReCaptchaResponse>(stringResult);
_logger?.Log(obj.Success ? LogLevel.Information : LogLevel.Warning, stringResult);
return obj;
and injected an optional ILogger<IReCaptchaService> logger into the ctor.
It seems to work, if the above changes look ok to you, would you accept a PR with this? Alternatively feel free to add yourself if you like it.
Describe alternatives you've considered
One alternative that I've tried is decorating the registered IReCaptchaService service with a logging wrapper, but that is a bit clunky and does not really give access to the raw response from the reCAPTCHA API that still has the error codes property in it...
The text was updated successfully, but these errors were encountered:
Thanks for suggestion the change, this can be very useful to anyone. We've implemented handling of error codes in the latest version of the library v1.5.2.
Based on the type of error code returned we now either log a warning or debug level message, when the error code is one of missing-secret-key, invalid-secret-key, it will be logged as a warning, any other error will be logged at level debug. In addition to that, the full response will also be logged as a trace level message.
This should enable you to debug issues more easily by setting the log level to debug or trace when debugging, and not spam the logs for normal operations (if a user did not pass the recaptcha it will log this at level debug which is lower than the default log level of Information).
I'm closing this issue since we've implemented the error logging as mentioned by @sleeuwen.
If you feel any need to reopen this issue, please feel free to do so when needed.
Is your feature request related to a problem? Please describe.
While the library is definitely functional, debugging of failed captcha verifications is nigh impossible (as far as I can tell). The
error-codes
field in the response from Google reCAPTCHA is ignored and there is no out-of-the-box logging of responsesDescribe the solution you'd like
I've forked the source code and took a stab at implementing something, I've:
ErrorCodes
property for theReCaptchaResponse
class to receive the error codes returned by the APIReCaptchaService.GetVerifyResponseAsync
method to include the following:and injected an optional
ILogger<IReCaptchaService> logger
into the ctor.It seems to work, if the above changes look ok to you, would you accept a PR with this? Alternatively feel free to add yourself if you like it.
Describe alternatives you've considered
One alternative that I've tried is decorating the registered
IReCaptchaService
service with a logging wrapper, but that is a bit clunky and does not really give access to the raw response from the reCAPTCHA API that still has the error codes property in it...The text was updated successfully, but these errors were encountered: