【问题标题】:Safari Can't Get Uri Fragment After Google Oauth CallbackGoogle Oauth 回调后 Safari 无法获取 Uri 片段
【发布时间】:2016-04-04 08:19:53
【问题描述】:

我正在按照此文档实施 Google OAuth 2.0:https://developers.google.com/identity/protocols/OAuth2UserAgent

我设置了以下步骤:

  1. 用户单击登录按钮并打开一个新窗口。
  2. 格式化验证 URL 并将新窗口重定向到 Google。
  3. 用户完成身份验证登录,Google 将 access_token 重定向到我的回调
  4. 回调页面使用#(例如:https://oauth2-login-demo.appspot.com/oauthcallback#access_token=1/fFBGRNJru1FQd44AzqT3Zg&token_type=Bearer&expires_in=3600&nonce=DgkRrHXmyu3KLd0KDdfq)验证URI片段中返回的access_token

我的问题是,对于 Chrome 和 Firefox,它工作得很好。但是,桌面 Safari(9.0.1) 和移动 Safari(iOS 9.2) 都无法接收任何哈希参数:Safari Console

是我执行了错误的 OAuth 步骤吗?


我的部分代码:

  • 第一步

    let that = this;
    let oauthWindow = window.open("", "oauthWindow", "height=518,width=964");
    
    that.setState(Object.assign({}, that.state, {loaded: false}));
    
    Parse.Cloud.run("google_util_request_login").then(function(result) {
    
        console.log(decodeURIComponent(result));
    
        oauthWindow.location = decodeURIComponent(result);
    
    }, function (error) {
        that.setState(Object.assign({}, that.state, {errorMessage: error, loaded: false}));
    });
    
  • 第 2 步:google_util_request_login 是一个云函数,它将返回格式化 url。

    • Github 存储库:github.com/bblurock/parse-cloud-with-google-twitter-oauth/blob/master/index.js#L22-L40
      (很抱歉给您带来不便,我的声誉不足以发布两个以上的链接)

【问题讨论】:

  • 我也遇到了这个问题,你解决了吗?
  • 我也遇到了同样的问题,你找到解决办法了吗?然后请分享,以便我能够解决这个问题

标签: javascript oauth-2.0 google-authentication


【解决方案1】:

当服务器重定向到另一个 URI 时,Safari(与 Firefox 和 Chrome 不同)可能会从 URI 中删除 #...

在我的情况下,我使用的是 redirect_uri http://localhost:8080/auth-callback.html/,我的本地服务器正在重定向到 http://localhost:8080/files/auth-callback.html/

在您的示例中,您提到了 redirect_uri https://oauth2-login-demo.appspot.com/oauthcallback。当我转到该 uri 时,我不会被重定向到其他任何地方,因此这在您的特定情况下可能没有用,但如果该页面有更明确的路径,那么也许可以尝试一下。

很抱歉,如果这不能解决您的问题,但我相信它会帮助处于类似情况的其他人。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,使用 Asana 的 API 和 Oauth 创建应用...在 Chrome、FF 甚至 IE 11 上运行良好,但在 Safari 上运行良好。

    这最终对我有用: https://community.auth0.com/t/hash-gets-lost-on-safari-webkit-browsers/7263/8

    Safari 在重定向 URI 的末尾需要一个“/”: "https://www.somedomain.com/somepathname/"

    那个,并且不要在重定向 URI 的末尾包含实际文件,即“index.php”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 2022-08-24
      • 1970-01-01
      相关资源
      最近更新 更多