Closed MG1376 closed 9 months ago
I wrote the server validate function as:
private async Task<ServerSideCaptchaValidationResultModel> ServerSideValidationHandler(ServerSideCaptchaValidationRequestModel requestModel)
{
var secretKey = await httpClient.GetStringAsync("api/account/getsecretkey");
var apiResult = await httpClient.GetFromJsonAsync<GoogleCaptchaCheckResponseResult?>
($"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={requestModel.CaptchaResponse}");
captchaSuccess = apiResult.Success;
return new ServerSideCaptchaValidationResultModel(apiResult.Success);
}
and the model:
public class GoogleCaptchaCheckResponseResult
{
[JsonPropertyName("success")]
public bool Success { get; set; }
[JsonPropertyName("error-codes")]
public List<string?>? ErrorCodes { get; set; }
[JsonPropertyName("hostname")]
public string? HostName { get; set; }
[JsonPropertyName("challenge_ts")]
public DateTime? ChallengeTS { get; set; }
}
while reCaptcha works and green tick appears, But no callbacks are called. I need the success result. Callbacks are not working.
Hi. Have you provided a delegate for the SuccessCallBack
event call back?
Take a look at the example: https://github.com/babaktaremi/GoogleCaptchaComponent/blob/master/GoogleCaptcha.Exmaple/Pages/Counter.razor
and PLEASE call https://www.google.com/recaptcha/api/siteverify endpoint from your backend API , don't expose your secret key
I solved the issue. I wrote the serverside function using https://www.google.com/recaptcha/api/siteverify?secret={encsk}&response={encrsp}"
but the problem was the client side used a get request to send captcha response to my server, since the response token is large a get request failed and callbacks were not called.
Note: I changed from above codes so that the google call happens on the server.
I solved the issue. I wrote the serverside function using
https://www.google.com/recaptcha/api/siteverify?secret={encsk}&response={encrsp}"
but the problem was the client side used a get request to send captcha response to my server, since the response token is large a get request failed and callbacks were not called.Note: I changed from above codes so that the google call happens on the server.
Great ! . Closing the issue
How to validate the Captcha in an api method? what is a secret key? is it relating to encryption? I have no clue how to write the api verification method. I've just created the api response model class. Help please.