Files
meteor/packages/url/url_common.js
Andrew Wilcox 2fd00e58ba Implements the "redirect" login flow, for cases such as using a mobile
UIWebView which aren't able to use the preferred "popup" login flow.

See the specs for details:
  https://meteor.hackpad.com/OAuth-redirect-flow-spec-PeziTcaNPDP
  https://meteor.hackpad.com/OAuth-redirect-flow-part-II-vswwUKP4vXe

I extracted code to construct a URL from the `http` package into a new
`url` utility package.  The new package has no public API, it simply
has the original URL construction functions that were in `http` and
makes them available to oauth.

Fixes the Meetup account login, as Meetup now requires using
"https://api.meetup.com/2/members" instead of
"https://secure.meetup.com/2/members".

The `?close` parameter for the redirect URI is now not needed or used.
For backwards compatibility the `?close` parameter is included if the
login service configuration doesn't include the `loginStyle` field
(indicating it was created using old code).
2014-08-28 17:25:13 -07:00

40 lines
873 B
JavaScript

URL = {};
var encodeString = function(str) {
return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
};
URL._encodeParams = function(params) {
var buf = [];
_.each(params, function(value, key) {
if (buf.length)
buf.push('&');
buf.push(encodeString(key), '=', encodeString(value));
});
return buf.join('').replace(/%20/g, '+');
};
buildUrl = function(before_qmark, from_qmark, opt_query, opt_params) {
var url_without_query = before_qmark;
var query = from_qmark ? from_qmark.slice(1) : null;
if (typeof opt_query === "string")
query = String(opt_query);
if (opt_params) {
query = query || "";
var prms = URL._encodeParams(opt_params);
if (query && prms)
query += '&';
query += prms;
}
var url = url_without_query;
if (query !== null)
url += ("?"+query);
return url;
};