Meteor accounts-facebook 没有为 redirect_uri 使用 https 的选项

Meteor accounts-facebook has no option to use https for redirect_uri

我正在使用 meteor accounts-facebook and want to use it with SSL as required by Facebook, but the redirect_uri is passed as http://, even if the app is running on https://. The code which creates a loginUrl in facebook-oauth.js 如下:

var loginUrl =
        'https://www.facebook.com/v2.9/dialog/oauth?client_id=' + config.appId +
        '&redirect_uri=' + OAuth._redirectUri('facebook', config) +
        '&display=' + display + '&scope=' + scope +
        '&state=' + OAuth._stateParam(loginStyle, credentialToken, options && options.redirectUrl);

再次调用 OAuth:

OAuth._redirectUri = function (serviceName, config, params, absoluteUrlOptions) {
  ...
  Meteor.absoluteUrl('_oauth/' + serviceName, absoluteUrlOptions)
  ...
}

如果 Meteor.absoluteUrl.defaultOptions.secure 为真,则在 Meteor.absoluteUrl 中首先删除 SSL,然后再重新添加:

  // merge options with defaults
  options = Object.assign({}, Meteor.absoluteUrl.defaultOptions, options || {});
  ...
  if (!/^http[s]?:\/\//i.test(url)) // url starts with 'http://' or 'https://'
    url = 'http://' + url; // we will later fix to https if options.secure is set
  ...
  // turn http to https if secure option is set, and we're not talking
  // to localhost.
  if (options.secure &&
      /^http:/.test(url) && // url starts with 'http:'
      !/http:\/\/localhost[:\/]/.test(url) && // doesn't match localhost
      !/http:\/\/127\.0\.0\.1[:\/]/.test(url)) // or 127.0.0.1
    url = url.replace(/^http:/, 'https:');

我没有办法:

  1. 如何告诉 accounts-facebook 使用正确的协议,因为没有 absoluteUrlOptions 参数传递给 OAuth._redirectUri
  2. 如何设置Meteor.absoluteUrl.defaultOptions.secure
  3. 任何其他选项...

我唯一的 解决方法 是安装 meteor add force-ssl 因此整个应用程序 运行 强制使用 https。

解决方法 是安装 force-ssl,因此整个应用程序 运行 在 https 上。

meteor add force-ssl 

更新: 显然你也可以在应用程序的早期在正确的位置设置 Meteor.absoluteUrl.defaultOptions.secure = true,例如client/lib/...