Permalink
Browse files

Rename Oauth.initiateLogin to Oauth.showPopup.

  • Loading branch information...
1 parent b65815d commit d573464f92594a301a94aebeabd9898c6ee7e0aa Emily Stark committed Nov 20, 2013
@@ -32,5 +32,8 @@ Facebook.requestCredential = function (options, credentialRequestCompleteCallbac
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/facebook?close') +
'&display=' + display + '&scope=' + scope + '&state=' + credentialToken;
- Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback);
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallack, null, credentialToken)
+ );
};
@@ -29,6 +29,10 @@ Github.requestCredential = function (options, credentialRequestCompleteCallback)
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/github?close') +
'&state=' + credentialToken;
- Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback,
- {width: 900, height: 450});
+
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken),
+ {width: 900, height: 450}
+ );
};
@@ -53,8 +53,9 @@ Google.requestCredential = function (options, credentialRequestCompleteCallback)
loginUrl += '&hd=' + encodeURIComponent(Accounts._options.restrictCreationByEmailDomain);
}
- Oauth.initiateLogin(credentialToken,
- loginUrl,
- credentialRequestCompleteCallback,
- { height: 406 });
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken),
+ { height: 406 }
+ );
};
@@ -34,6 +34,9 @@ Meetup.requestCredential = function (options, credentialRequestCompleteCallback)
if (_.without(scope, 'basic').length)
height += 130;
- Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback,
- {width: 900, height: height});
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken),
+ {width: 900, height: height}
+ );
};
@@ -55,9 +55,10 @@ MeteorAccounts.requestCredential = function (options, credentialRequestCompleteC
if (options._redirectToLogin) {
window.location.assign(loginUrl);
} else {
- Oauth.initiateLogin(credentialToken,
- loginUrl,
- credentialRequestCompleteCallback,
- { height: 406 });
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken),
+ { height: 406 }
+ );
}
};
@@ -1,20 +1,20 @@
Oauth = {};
-// Open a popup window pointing to a OAuth handshake page
+// Open a popup window, centered on the screen, and call a callback when it
+// closes.
//
-// @param credentialToken {String} The OAuth credentialToken generated by the client
-// @param url {String} url to page
-// @param credentialRequestCompleteCallback {Function} Callback function to call on
-// completion. Takes one argument, credentialToken on success, or Error on
-// error.
+// @param url {String} url to show
+// @param callback {Function} Callback function to call on completion. Takes no
+// arguments.
// @param dimensions {optional Object(width, height)} The dimensions of
-// the popup. If not passed defaults to something sane
-Oauth.initiateLogin = function(credentialToken, url, credentialRequestCompleteCallback, dimensions) {
+// the popup. If not passed defaults to something sane.
+Oauth.showPopup = function (url, callback, dimensions) {
// default dimensions that worked well for facebook and google
var popup = openCenteredPopup(
url,
(dimensions && dimensions.width) || 650,
- (dimensions && dimensions.height) || 331);
+ (dimensions && dimensions.height) || 331
+ );
var checkPopupOpen = setInterval(function() {
try {
@@ -32,7 +32,7 @@ Oauth.initiateLogin = function(credentialToken, url, credentialRequestCompleteCa
if (popupClosed) {
clearInterval(checkPopupOpen);
- credentialRequestCompleteCallback(credentialToken);
+ callback();
}
}, 100);
};
@@ -61,3 +61,13 @@ var openCenteredPopup = function(url, width, height) {
newwindow.focus();
return newwindow;
};
+
+// XXX COMPAT WITH 0.6.6.3
+// Private interface but probably used by many oauth clients in atmosphere.
+Oauth.initiateLogin = function (credentialToken, url, callback, dimensions) {
+ Oauth.showPopup(
+ url,
+ _.bind(callback, null, credentialToken),
+ dimensions
+ );
+};
@@ -29,9 +29,12 @@ Twitter.requestCredential = function (options, credentialRequestCompleteCallback
// url to app, enters "step 1" as described in
// packages/accounts-oauth1-helper/oauth1_server.js
- var url = '/_oauth/twitter/?requestTokenAndRedirect='
+ var loginUrl = '/_oauth/twitter/?requestTokenAndRedirect='
+ encodeURIComponent(callbackUrl)
+ '&state=' + credentialToken;
- Oauth.initiateLogin(credentialToken, url, credentialRequestCompleteCallback);
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken)
+ );
};
@@ -27,5 +27,8 @@ Weibo.requestCredential = function (options, credentialRequestCompleteCallback)
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/weibo?close', {replaceLocalhost: true}) +
'&state=' + credentialToken;
- Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback);
+ Oauth.showPopup(
+ loginUrl,
+ _.bind(credentialRequestCompleteCallback, null, credentialToken)
+ );
};

0 comments on commit d573464

Please sign in to comment.