【问题标题】:X-Frame-Options errorX-Frame-Options 错误
【发布时间】:2014-05-10 07:17:23
【问题描述】:

我一直在使用 google+ 登录 API,

  1. 当用户链接他的新帐户时(通过尚未登录的方式 Google+ 社交网络)在我创建的 api 应用中
  2. 系统会引导用户创建 Google+ 个人资料屏幕。
  3. 按下提交按钮时,它被定向到一个 URL,然后它不再加载,使屏幕空白不知道是否 用户的帐户是在 google+ 中创建的。

我已经追踪到包含这个的错误:

Load denied by X-Frame-Options: https://accounts.google.com/o/oauth2/auth?XXXXXXXX does not permit cross-origin framing.

因此它不会继续访问该 url,因为 X-Frame-Options 正在阻止它。

我研究了X-Frame-Options,说应该在header中设置。

我将如何在这个标题中设置它:

<meta name="google-signin-clientid" content="{{=response.CLIENT_ID}}" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" />
<meta name="google-signin-requestvisibleactions" content="http://schemas.google.com/AddActivity" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />

我正在以这种方式渲染我的按钮:

(function() {
   var po = document.createElement('script');
   po.type = 'text/javascript'; po.async = true;
   po.src = 'https://apis.google.com/js/client:plusone.js?onload=render';
   var s = document.getElementsByTagName('script')[0];
   s.parentNode.insertBefore(po, s);
 })();
 function render() {

   // Additional params including the callback, the rest of the params will
   // come from the page-level configuration.
   var additionalParams = {
     'callback': signinCallback,
     'immediate': false,

   };
   // Attach a click listener to a button to trigger the flow.
   var signinButton = document.getElementById('signinButton');
   signinButton.addEventListener('click', function() {
     gapi.auth.signIn(additionalParams); // Will use page level configuration
   });
 }

或者还有什么其他的设置方法?或者如何解决这个错误?我的后端部分是 python。

【问题讨论】:

    标签: javascript jquery python html google-api


    【解决方案1】:

    我也遇到了这个问题,但我发现了我到底发生了什么。

    我正在努力创建一个在 Golang 的 Google App Engine 上运行的应用程序。我获取了设置 Google+ 登录按钮按钮所需的代码 sn-p,并将其粘贴到我的模板中。代码如下所示,直接取自Google Documentation

            <span
               class="g-signin"
               data-callback="signinCallback"
               data-clientid="CLIENT_ID"
               data-cookiepolicy="single_host_origin"
               data-requestvisibleactions="http://schema.org/AddAction"
               data-scope="https://www.googleapis.com/auth/plus.login">
    

    我没有用 CLIENT_ID 替换我的真实 clientId,这就是问题所在。我用我的 Google App Engine CLIENT_ID 替换了字符串“CLIENT_ID”,它为我解决了这个问题。我通过使用 Chrome 开发者工具查看网络选项卡上的网络请求/响应信息来观察到这一点,并观察到这个奇怪的请求是使用 CLIENT_ID,这看起来是错误的。

    进一步检查代码,这确实是我的问题。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-27
      • 2019-10-15
      • 2012-08-17
      • 1970-01-01
      • 2013-05-10
      • 2015-04-15
      • 2015-12-04
      • 2014-09-06
      相关资源
      最近更新 更多