【发布时间】:2018-10-13 14:06:53
【问题描述】:
我正在使用流星 accounts-facebook 并希望按照 Facebook 的要求将其与 SSL 一起使用,但 redirect_uri 被传递为 http://,即使应用程序在 https:// 上运行。在facebook-oauth.js 中创建loginUrl 的代码如下:
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:');
我没有办法:
- 如何告诉accounts-facebook使用正确的协议,因为没有
absoluteUrlOptions参数被传递给OAuth._redirectUri - 如何设置
Meteor.absoluteUrl.defaultOptions.secure - 任何其他选项...
我唯一的解决方法是安装meteor add force-ssl,以便整个应用程序强制在 https 上运行。
【问题讨论】:
标签: javascript node.js meteor oauth