forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth_common.js
59 lines (53 loc) · 2.1 KB
/
oauth_common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
};