diff --git a/packages/oauth/end_of_popup_response.html b/packages/oauth/end_of_popup_response.html
index e497038e7f..d09bc7dc0d 100644
--- a/packages/oauth/end_of_popup_response.html
+++ b/packages/oauth/end_of_popup_response.html
@@ -1,9 +1,14 @@
-
+
Login completed.
Click here to close this window.
+
+ ##CONFIG##
diff --git a/packages/oauth/end_of_redirect_response.html b/packages/oauth/end_of_redirect_response.html
index c67748da30..59ce2f2fd7 100644
--- a/packages/oauth/end_of_redirect_response.html
+++ b/packages/oauth/end_of_redirect_response.html
@@ -1,17 +1,24 @@
-
+
Logging In
+ ##CONFIG##
diff --git a/packages/oauth/oauth_client.js b/packages/oauth/oauth_client.js
index 565c46b121..98ee9694a6 100644
--- a/packages/oauth/oauth_client.js
+++ b/packages/oauth/oauth_client.js
@@ -13,6 +13,11 @@ OAuth.showPopup = function (url, callback, dimensions) {
//
//
OAuth._loginStyle = function (service, config, options) {
+
+ if (Meteor.isCordova) {
+ return "popup";
+ }
+
var loginStyle = (options && options.loginStyle) || config.loginStyle || 'popup';
if (! _.contains(["popup", "redirect"], loginStyle))
@@ -34,9 +39,10 @@ OAuth._loginStyle = function (service, config, options) {
};
OAuth._stateParam = function (loginStyle, credentialToken) {
- state = {
+ var state = {
loginStyle: loginStyle,
- credentialToken: credentialToken
+ credentialToken: credentialToken,
+ isCordova: Meteor.isCordova
};
if (loginStyle === 'redirect')
@@ -88,7 +94,7 @@ OAuth.getDataAfterRedirect = function () {
credentialToken: credentialToken,
credentialSecret: credentialSecret
};
-}
+};
// Launch an OAuth login flow. For the popup login style, show the
// popup. For the redirect login style, save the credential token for
@@ -155,6 +161,5 @@ OAuth._retrieveCredentialSecret = function (credentialToken) {
} else {
delete credentialSecrets[credentialToken];
}
- console.log("new secret: ", secret);
return secret;
};
diff --git a/packages/oauth/oauth_cordova.js b/packages/oauth/oauth_cordova.js
index 44ca7639cb..7612a3e669 100644
--- a/packages/oauth/oauth_cordova.js
+++ b/packages/oauth/oauth_cordova.js
@@ -9,36 +9,31 @@
// @param dimensions {optional Object(width, height)} The dimensions of
// the popup. If not passed defaults to something sane.
OAuth.showPopup = function (url, callback, dimensions) {
- console.log("showing url", url);
- var popup = window.open(url, '_blank', 'location=yes,hidden=yes');
- popup.addEventListener('loadstart', pageStartLoad);
- popup.addEventListener('loadstop', pageLoaded);
- popup.addEventListener('loaderror', fail);
- popup.addEventListener('exit', close);
- popup.show();
+ var fail = function (err) {
+ Meteor._debug("Error from OAuth popup:", err);
+ };
- function pageStartLoad (event) {
- console.log("page start load", JSON.stringify(event));
- }
- function fail (err) {
- Meteor._debug(err);
- }
+ var pageLoaded = function (event) {
+ if (event.url.indexOf(Meteor.absoluteUrl('_oauth')) === 0) {
+ var splitUrl = event.url.split("#");
+ var hashFragment = splitUrl[1];
- function close () {
- console.log("close");
- }
- function pageLoaded (event) {
- console.log("loaded", event.url);
- console.log("comparing to", Meteor.absoluteUrl('_oauth'));
- var url = decodeURI(event.url);
- console.log("decoded", url);
- if (url.indexOf(Meteor.absoluteUrl('_oauth')) === 0) {
- var credentials = JSON.parse(url.split('#')[1]);
+ if (! hashFragment) {
+ throw new Error("No hash fragment in OAuth popup?");
+ }
+
+ var credentials = JSON.parse(decodeURIComponent(hashFragment));
OAuth._handleCredentialSecret(credentials.credentialToken,
- credentials.credentialSecret);
+ credentials.credentialSecret);
popup.close();
callback();
}
- }
-};
\ No newline at end of file
+ };
+
+ var popup = window.open(url, '_blank', 'location=yes,hidden=yes');
+ popup.addEventListener('loadstop', pageLoaded);
+ popup.addEventListener('loaderror', fail);
+ popup.show();
+
+};
diff --git a/packages/oauth/oauth_server.js b/packages/oauth/oauth_server.js
index efc1146315..db561ece34 100644
--- a/packages/oauth/oauth_server.js
+++ b/packages/oauth/oauth_server.js
@@ -81,19 +81,26 @@ OAuth._stateFromQuery = function (query) {
}
OAuth._loginStyleFromQuery = function (query) {
- return OAuth._stateFromQuery(query).loginStyle;
+ var style = OAuth._stateFromQuery(query).loginStyle;
+ if (style !== "popup" && style !== "redirect") {
+ throw new Error("Unrecognized login style: " + style);
+ }
+ return style;
};
OAuth._credentialTokenFromQuery = function (query) {
return OAuth._stateFromQuery(query).credentialToken;
};
+OAuth._isCordovaFromQuery = function (query) {
+ return !! OAuth._stateFromQuery(query).isCordova;
+};
+
// Listen to incoming OAuth http requests
WebApp.connectHandlers.use(function(req, res, next) {
// Need to create a Fiber since we're using synchronous http calls and nothing
// else is wrapping this in a fiber automatically
- console.log(req.url);
Fiber(function () {
middleware(req, res, next);
}).run();
@@ -124,7 +131,6 @@ var middleware = function (req, res, next) {
throw new Error("Unexpected OAuth version " + service.version);
handler(service, req.query, res);
} catch (err) {
- console.log("error in middlware:", err.stack, req.url);
// if we got thrown an error, save it off, it will get passed to
// the appropriate login call (if any) and reported there.
//
@@ -231,7 +237,7 @@ OAuth._renderOauthResults = function(res, query, credentialSecret) {
details.error = "invalid_credential_token_or_secret";
}
}
- console.log("writing response to client");
+
OAuth._endOfLoginResponse(res, details);
}
};
@@ -247,40 +253,56 @@ var endOfRedirectResponseTemplate = Assets.getText(
// Renders the end of login response template into some HTML and JavaScript
// that closes the popup or redirects at the end of the OAuth flow.
-var renderEndOfLoginResponse = function (loginStyle, setCredentialToken, token, secret, redirectUrl) {
+//
+// options are:
+// - loginStyle ("popup" or "redirect")
+// - setCredentialToken (boolean)
+// - credentialToken
+// - credentialSecret
+// - redirectUrl
+// - isCordova (boolean)
+//
+var renderEndOfLoginResponse = function (options) {
// It would be nice to use Blaze here, but it's a little tricky
// because our mustaches would be inside a