5

我正在尝试在弹出窗口中通过 OAuth2 对 Constant Contact 进行身份验证。我$.postMessage用来在窗口之间发送数据,而且在大多数情况下,它工作得很好。

我的问题是 Safari。正常请求的 URL 如下所示:

https://example.com/oauth-v2/#access_token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx&token_type=Bearer&expires_in=xxxxxxxxx

但是在使用 Safari 发出请求时,整个哈希被截断了 URL 并且location.hash, window.location.hash,window.parent.location.hash都是空的。

身份验证流程相当标准:

  1. 用户单击身份验证按钮
  2. 使用 Constant Contact 进行身份验证的弹出窗口
  3. 允许申请
  4. 项目清单
  5. 返回应用程序站点以获取令牌

这是我们用来获取 URL 哈希信息的 javascript

jQuery(document).ready(function ($) {
  $.extend({
    getQueryParameters: function (str) {
      return (str || document.location.search || document.location.hash)
        .replace(/(^\?)|(^\#)/, '')
        .split("&")
        .map(function (n) { return n = n.split("="), this[n[0]] = n[1], this }.bind({}))[0];
    }
  });
  $.receiveMessage(function (event) {
    $.postMessage($.getQueryParameters(), event.origin, event.source);
    setTimeout(function () {
      window.close()
    }, 5000);
  });
});

缺少的哈希是 Safari 中的一个已知错误吗?我应该做其他事情来从 Constant Contact 获取信息吗?它适用于所有其他浏览器,所以我不想重新编写应用程序的这一部分。

4

0 回答 0