[英]google invisible reCaptcha server side validation is failing
i have integrated the invisible reCaptcha in my application and the client side response is coming as part of solving the image challenge.我已经在我的应用程序中集成了不可见的 reCaptcha,并且客户端响应是解决图像挑战的一部分。 i am then calling a angular function to validate user response on server side using below code.
然后我调用一个角度函数来使用下面的代码验证服务器端的用户响应。 where onloginSubmit(token) is the success call back.
其中 onloginSubmit(token) 是成功回调。
<button id="btnLogin" ng-disabled="loginForm.$invalid"
class="g-recaptcha primarybtn margin-left-zero form-control-input"
data-sitekey="{{public_key}}"
data-callback='onloginSubmit'>{{'label_login' |
translate}}</button>
<script>
function onloginSubmit(token) {
angular.element(document.getElementById('loginForm')).scope().verifyReCaptcha(token);
};
</script>
in angular i am calling the verifyReCaptcha as below.在 angular 中,我调用 verifyReCaptcha 如下。
$scope.public_key = "------ My Site Key -------";
$scope.private_key = "------ My Secret Key -------";
$scope.verifyReCaptchaURL = "https://www.google.com/recaptcha/api/siteverify";
$scope.verifyReCaptcha = function(reCaptchaToken){
var captchaData = {
secret : $scope.private_key,
response : reCaptchaToken
}
$http({
headers: {
'Accept': 'application/json,text/plain',
'Content-Type': 'application/json;application/x-www-form-urlencoded;charset=utf-8;',
},
url: $scope.verifyReCaptchaURL,
method: 'POST',
data: captchaData
}).success(function (data) {
console.log("success");
$scope.login();
}).error(function (data) {
console.log("error");
$window.location.reload(true);
});
};
when i hit the api service https://www.google.com/recaptcha/api/siteverify .当我点击 api 服务https://www.google.com/recaptcha/api/siteverify 。 i get the below error.
我收到以下错误。
Failed to load https://www.google.com/recaptcha/api/siteverify: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 405.
i couldnt find more documentation for the issue.我找不到有关该问题的更多文档。
what is it that i am doing wrong and also if there is any error the recaptcha does not come up and the login button which i am using fails to respond.我做错了什么,如果有任何错误,recaptcha 不会出现,我使用的登录按钮也无法响应。
n the request i am mentioning the Method as Post, the method is over ridden as Options and the request payload which i am sending is not present.在我将方法称为 Post 的请求中,该方法被替代为选项,并且我发送的请求负载不存在。 this is what i got in the networks tab
这是我在网络标签中得到的
Request URL:https://www.google.com/recaptcha/api/siteverify Request Method:OPTIONS Status Code:405 Remote Address:10.120.118.50:8080 Referrer Policy:no-referrer-when-downgrade
Most of the thing you did a great job.大多数事情你做得很好。 One thing is to require in your application is communicate to an external domain so you can include HTTP header content type is include a JSONP format.
一件事是在您的应用程序中要求与外部域进行通信,以便您可以包含 HTTP 标头内容类型是包含 JSONP 格式。
$http({
headers: {
'Accept': 'application/json,text/plain',
'Content-Type': 'application/jsonp;application/x-www-form-urlencoded;charset=utf-8;',
},
url: $scope.verifyReCaptchaURL,
method: 'POST',
data: captchaData
}).success(function (data) {
console.log("success");
$scope.login();
}).error(function (data) {
console.log("error");
$window.location.reload(true);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.