簡體   English   中英

谷歌隱形 reCaptcha 服務器端驗證失敗

[英]google invisible reCaptcha server side validation is failing

我已經在我的應用程序中集成了不可見的 reCaptcha,並且客戶端響應是解決圖像挑戰的一部分。 然后我調用一個角度函數來使用下面的代碼驗證服務器端的用戶響應。 其中 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>

在 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);
        });
  };

當我點擊 api 服務https://www.google.com/recaptcha/api/siteverify 我收到以下錯誤。

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.

我找不到有關該問題的更多文檔。

我做錯了什么,如果有任何錯誤,recaptcha 不會出現,我使用的登錄按鈕也無法響應。

在我將方法稱為 Post 的請求中,該方法被替代為選項,並且我發送的請求負載不存在。 這是我在網絡標簽中得到的

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

大多數事情你做得很好。 一件事是在您的應用程序中要求與外部域進行通信,以便您可以包含 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM