【问题标题】:how does the meteor-accounts oauth workflow happen流星帐户 oauth 工作流程是如何发生的
【发布时间】:2016-09-04 01:01:33
【问题描述】:

我正在尝试将accounts-facebookIonic CLI 一起使用。我正在使用client side bundler script,但我无法完成整个oauth 工作流程。

我从meteor-angular-socially 项目设置了一个标准的account-facebook 配置,发现我卡在oauth 重定向URI 上。在我的客户端包中永远不会调用以下方法

// in script: oauth/oauth_client.js
// Called by the popup when the OAuth flow is completed, right before
// the popup closes.
OAuth._handleCredentialSecret = function (credentialToken, secret) {
  check(credentialToken, String);
  check(secret, String);
  if (! _.has(credentialSecrets,credentialToken)) {
    credentialSecrets[credentialToken] = secret;
  } else {
    throw new Error("Duplicate credential token from OAuth login");
  }
}; 

我从 oauth 获得以下重定向 URL,它应该会加载此页面

# http://localhost:3000/_oauth/facebook/?code=[...]&state=[...]
<!DOCTYPE html>
<html>
<body>
  <p id="completedText" style="display:none;">
    Login completed. <a href="#" id="loginCompleted">
      Click here</a> to close this window.
  </p>

  <div id="config" style="display:none;">{
    "setCredentialToken":false,
    "storagePrefix":"Meteor.oauth.credentialSecret-",
    "isCordova":false
  }</div>
  <script type="text/javascript" src="/_oauth/facebook/end_of_popup_response.js">
    # script included inline for ease of reading
    (function () {

      var config = JSON.parse(document.getElementById("config").innerHTML);

      if (config.setCredentialToken) {
        var credentialToken = config.credentialToken;
        var credentialSecret = config.credentialSecret;

        if (config.isCordova) {
          var credentialString = JSON.stringify({
            credentialToken: credentialToken,
            credentialSecret: credentialSecret
          });

          window.location.hash = credentialString;
        }

        if (window.opener && window.opener.Package &&
              window.opener.Package.oauth) {
          window.opener.Package.oauth.OAuth._handleCredentialSecret(
            credentialToken, credentialSecret);
        } else {
          try {
            localStorage[config.storagePrefix + credentialToken] = credentialSecret;
          } catch (err) {
            // We can't do much else, but at least close the popup instead
            // of having it hang around on a blank page.
          }
        }
      }

      if (! config.isCordova) {
        document.getElementById("completedText").style.display = "block";
        document.getElementById("loginCompleted").onclick = function(){ window.close(); };
        window.close();
      }
    })();
  </script>
</body>
</html>

在标准的meteor CLI 配置中,以某种方式/某处设置了config.setCredentialToken === trueconfig.setCredentialTokenconfig.credentialSecret。但我无法弄清楚发生的地点/时间。

在我的accounts-facebook-client-side.bundle.js 中,这些都没有发生。

更新

我意识到魔法发生在 Meteor 服务器端。如果我将我的 oauth redirect_uri 设置为 Meteor 服务器运行的端口,那么我会在 ./_oauth/facebook 页面中得到以下信息:

<div id="config" style="display:none;">{
"setCredentialToken":true,
"credentialToken":"bsgEZrFbK-UruR1iX81dEitIR0t5nC_a1HM4-EGSGx5",
"credentialSecret":"hi8rJxbyOsI0gVaoIHrr7N9kH9k2Fku1DYQXP5BmQMt",
"storagePrefix":"Meteor.oauth.credentialSecret-",
"isCordova":false
}</div>

但是,我猜如果我这样做,我将无法在我的 web.browser 客户端页面(端口 3000)上从 localstorage(?) 读取这些值

有什么解决方法的想法吗?

【问题讨论】:

    标签: meteor oauth meteor-accounts


    【解决方案1】:

    修复它的最简单方法是将 nginx 放在您的应用程序前面,并使用 proxy_pass 根据路径对 Ionic 的服务器和 Meteor 的服务器的调用进行排序:

    server {
        listen       80;
        server_name  domain.tld;
    
        location / {
            proxy_pass http://domain.tld:8100;
        }
        location /_oauth {
            proxy_pass http://domain.tld:3000;
        }
        location /packages {
            proxy_pass http://domain.tld:3000;
        }
    }
    

    我刚刚在 accounts-facebook 上尝试了这种方法并且工作正常(您需要将浏览器指向 http://domain.tld:80 而不是 http://domain.tld:8100),但我已经开始深入挖掘 Meteor 的代码,看看我是否可以完成某些事情更好的。如果我能找到更好的解决方案,我会编辑这个答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 2016-11-20
      相关资源
      最近更新 更多