Skip to content

Commit

Permalink
fix: recaptcha verification POST must include parameters in body
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed May 17, 2024
1 parent a5cad62 commit 3ee9301
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.hc.core5.http.HttpResponse;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import java.nio.charset.StandardCharsets;

/**
Expand All @@ -40,8 +41,11 @@ public boolean validate(final String recaptchaResponse, final String userAgent)
val exec = HttpExecutionRequest.builder()
.method(HttpMethod.POST)
.url(recaptchaProperties.getVerifyUrl())
.headers(CollectionUtils.wrap("User-Agent", userAgent, "Accept-Language", "en-US,en;q=0.5"))
.parameters(CollectionUtils.wrap("secret", recaptchaProperties.getSecret(), "response", recaptchaResponse))
.headers(CollectionUtils.wrap(
"User-Agent", userAgent,
"Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE,
"Accept-Language", "en-US,en;q=0.5"))
.entity("secret=%s&response=%s".formatted(recaptchaProperties.getSecret(), recaptchaResponse))
.build();

response = HttpUtils.execute(exec);
Expand Down

0 comments on commit 3ee9301

Please sign in to comment.