mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Previously, the tool was hard-coded to use "?close" at the end of redirect uris when it did OAuth flows with e.g. package servers or build farms. Now, we use the same logic that the server uses to compute its redirect uri: we add "?close" if a loginStyle option is present in the configuration.
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
OAuth._storageTokenPrefix = "Meteor.oauth.credentialSecret-";
|
|
|
|
OAuth._redirectUri = function (serviceName, config, params, absoluteUrlOptions) {
|
|
// XXX COMPAT WITH 0.9.0
|
|
// The redirect URI used to have a "?close" query argument. We
|
|
// detect whether we need to be backwards compatible by checking for
|
|
// the absence of the `loginStyle` field, which wasn't used in the
|
|
// code which had the "?close" argument.
|
|
// This logic is duplicated in the tool so that the tool can do OAuth
|
|
// flow with <= 0.9.0 servers (tools/auth.js).
|
|
var query = config.loginStyle ? null : "close";
|
|
|
|
// Clone because we're going to mutate 'params'. The 'cordova' and
|
|
// 'android' parameters are only used for picking the host of the
|
|
// redirect URL, and not actually included in the redirect URL itself.
|
|
var isCordova = false;
|
|
var isAndroid = false;
|
|
if (params) {
|
|
params = _.clone(params);
|
|
isCordova = params.cordova;
|
|
isAndroid = params.android;
|
|
delete params.cordova;
|
|
delete params.android;
|
|
if (_.isEmpty(params)) {
|
|
params = undefined;
|
|
}
|
|
}
|
|
|
|
if (Meteor.isServer && isCordova) {
|
|
var rootUrl = process.env.MOBILE_ROOT_URL ||
|
|
__meteor_runtime_config__.ROOT_URL;
|
|
|
|
if (isAndroid) {
|
|
// Match the replace that we do in cordova boilerplate
|
|
// (boilerplate-generator package).
|
|
// XXX Maybe we should put this in a separate package or something
|
|
// that is used here and by boilerplate-generator? Or maybe
|
|
// `Meteor.absoluteUrl` should know how to do this?
|
|
var url = Npm.require("url");
|
|
var parsedRootUrl = url.parse(rootUrl);
|
|
if (parsedRootUrl.hostname === "localhost") {
|
|
parsedRootUrl.hostname = "10.0.2.2";
|
|
delete parsedRootUrl.host;
|
|
}
|
|
rootUrl = url.format(parsedRootUrl);
|
|
}
|
|
|
|
absoluteUrlOptions = _.extend({}, absoluteUrlOptions, {
|
|
// For Cordova clients, redirect to the special Cordova root url
|
|
// (likely a local IP in development mode).
|
|
rootUrl: rootUrl
|
|
});
|
|
}
|
|
|
|
return URL._constructUrl(
|
|
Meteor.absoluteUrl('_oauth/' + serviceName, absoluteUrlOptions),
|
|
query,
|
|
params);
|
|
};
|