不是来自 Google API Oauth 的客户端的有效来源 [英] Not a valid origin for the client from Google API Oauth

查看:21
本文介绍了不是来自 Google API Oauth 的客户端的有效来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Google API Oauth 收到此错误:

<块引用>

idpiframe_initialization_failed",详细信息:不是客户端的有效来源:

这是我的代码:

<html itemscope itemtype="http://schema.org/Article"><头><!-- 开始先决条件--><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"><script src="https://apis.google.com/js/client:platform.js?onload=start" 异步延迟><!-- 结束先决条件--><!-- 继续 <head>部分 --><脚本>函数开始(){gapi.load('auth2', function() {auth2 = gapi.auth2.init({client_id: '我的客户 ID.apps.googleusercontent.com',//除了个人资料"和电子邮件"之外的请求范围//范围:'https://www.google.com/m8/feeds/'});});}<身体><button id="signinButton">使用 Google 登录</button><脚本>$('#signinButton').click(function() {//在步骤 6 中定义的 signInCallback.auth2.grantOfflineAccess().then(signInCallback);});<!-- 文件 index.html 中 BODY 元素的最后一部分 --><脚本>函数 signInCallback(authResult) {如果(authResult['代码']){//现在用户已获得授权,隐藏登录按钮,例如:$('#signinButton').attr('style', 'display: none');//将代码发送到服务器$.ajax({类型:'POST',url: 'http://example.com/storeauthcode',//在每个 AJAX 请求中总是包含一个 `X-Requested-With` 头,//防止 CSRF 攻击.标题:{'X-Requested-With': 'XMLHttpRequest'},contentType: '应用程序/八位字节流;字符集=utf-8',成功:功能(结果){//处理或验证服务器响应.},过程数据:假,数据:authResult['代码']});} 别的 {//有一个错误.}}<!-- ... -->

我该如何解决这个问题?

解决方案

如果对你来说都是一样的,请尝试添加 http://localhost:8887 改为您授权的 JavaScript 源.我自己在某个时候遇到过这个错误,这修复了它.知道您必须将这个 URL 用于您的请求以及事件,尽管它转换为 http://127.0.0.1:8887/.

I'm receiving this error from Google API Oauth:

idpiframe_initialization_failed", details: "Not a valid origin for the client: http://127.0.0.…itelist this origin for your project's client ID

I'm trying to send a request from this local path:

http://127.0.0.1:8887/

And I already added this URL to the Authorized JavaScript origins section:

This is my code:

<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
  <!-- BEGIN Pre-requisites -->
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
  </script>
  <script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
  </script>
  <!-- END Pre-requisites -->

<!-- Continuing the <head> section -->
  <script>
    function start() {
      gapi.load('auth2', function() {
        auth2 = gapi.auth2.init({
          client_id: 'MY CLIENT ID.apps.googleusercontent.com',
          // Scopes to request in addition to 'profile' and 'email'
          //scope: 'https://www.google.com/m8/feeds/'
        });
      });
    }
  </script>




</head>
<body>


<button id="signinButton">Sign in with Google</button>
<script>
  $('#signinButton').click(function() {
    // signInCallback defined in step 6.
    auth2.grantOfflineAccess().then(signInCallback);
  });
</script>



<!-- Last part of BODY element in file index.html -->
<script>
function signInCallback(authResult) {
  if (authResult['code']) {

    // Hide the sign-in button now that the user is authorized, for example:
    $('#signinButton').attr('style', 'display: none');

    // Send the code to the server
    $.ajax({
      type: 'POST',
      url: 'http://example.com/storeauthcode',
      // Always include an `X-Requested-With` header in every AJAX request,
      // to protect against CSRF attacks.
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      },
      contentType: 'application/octet-stream; charset=utf-8',
      success: function(result) {
        // Handle or verify the server response.
      },
      processData: false,
      data: authResult['code']
    });
  } else {
    // There was an error.
  }
}
</script>
  <!-- ... -->
</body>
</html>

How can I fix this?

解决方案

If it's all the same to you, try adding http://localhost:8887 to your authorized JavaScript origins instead. Had that error myself at some point and this fixed it. Know that you will have to use this URL for your request as well event though it translates to http://127.0.0.1:8887/.

这篇关于不是来自 Google API Oauth 的客户端的有效来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆