Skip to content

Commit

Permalink
Rename Oauth.initiateLogin to Oauth.showPopup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily Stark committed Nov 20, 2013
1 parent b65815d commit d573464
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 26 deletions.
5 changes: 4 additions & 1 deletion packages/facebook/facebook_client.js
Expand Up @@ -32,5 +32,8 @@ Facebook.requestCredential = function (options, credentialRequestCompleteCallbac
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/facebook?close') + '&redirect_uri=' + Meteor.absoluteUrl('_oauth/facebook?close') +
'&display=' + display + '&scope=' + scope + '&state=' + credentialToken; '&display=' + display + '&scope=' + scope + '&state=' + credentialToken;


Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback); Oauth.showPopup(
loginUrl,
_.bind(credentialRequestCompleteCallack, null, credentialToken)
);
}; };
8 changes: 6 additions & 2 deletions packages/github/github_client.js
Expand Up @@ -29,6 +29,10 @@ Github.requestCredential = function (options, credentialRequestCompleteCallback)
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/github?close') + '&redirect_uri=' + Meteor.absoluteUrl('_oauth/github?close') +
'&state=' + credentialToken; '&state=' + credentialToken;


Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback,
{width: 900, height: 450}); Oauth.showPopup(
loginUrl,
_.bind(credentialRequestCompleteCallback, null, credentialToken),
{width: 900, height: 450}
);
}; };
9 changes: 5 additions & 4 deletions packages/google/google_client.js
Expand Up @@ -53,8 +53,9 @@ Google.requestCredential = function (options, credentialRequestCompleteCallback)
loginUrl += '&hd=' + encodeURIComponent(Accounts._options.restrictCreationByEmailDomain); loginUrl += '&hd=' + encodeURIComponent(Accounts._options.restrictCreationByEmailDomain);
} }


Oauth.initiateLogin(credentialToken, Oauth.showPopup(
loginUrl, loginUrl,
credentialRequestCompleteCallback, _.bind(credentialRequestCompleteCallback, null, credentialToken),
{ height: 406 }); { height: 406 }
);
}; };
7 changes: 5 additions & 2 deletions packages/meetup/meetup_client.js
Expand Up @@ -34,6 +34,9 @@ Meetup.requestCredential = function (options, credentialRequestCompleteCallback)
if (_.without(scope, 'basic').length) if (_.without(scope, 'basic').length)
height += 130; height += 130;


Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback, Oauth.showPopup(
{width: 900, height: height}); loginUrl,
_.bind(credentialRequestCompleteCallback, null, credentialToken),
{width: 900, height: height}
);
}; };
9 changes: 5 additions & 4 deletions packages/meteor-auth/meteor_auth_client.js
Expand Up @@ -55,9 +55,10 @@ MeteorAccounts.requestCredential = function (options, credentialRequestCompleteC
if (options._redirectToLogin) { if (options._redirectToLogin) {
window.location.assign(loginUrl); window.location.assign(loginUrl);
} else { } else {
Oauth.initiateLogin(credentialToken, Oauth.showPopup(
loginUrl, loginUrl,
credentialRequestCompleteCallback, _.bind(credentialRequestCompleteCallback, null, credentialToken),
{ height: 406 }); { height: 406 }
);
} }
}; };
30 changes: 20 additions & 10 deletions packages/oauth/oauth_client.js
@@ -1,20 +1,20 @@
Oauth = {}; 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 show
// @param url {String} url to page // @param callback {Function} Callback function to call on completion. Takes no
// @param credentialRequestCompleteCallback {Function} Callback function to call on // arguments.
// completion. Takes one argument, credentialToken on success, or Error on
// error.
// @param dimensions {optional Object(width, height)} The dimensions of // @param dimensions {optional Object(width, height)} The dimensions of
// the popup. If not passed defaults to something sane // the popup. If not passed defaults to something sane.
Oauth.initiateLogin = function(credentialToken, url, credentialRequestCompleteCallback, dimensions) { Oauth.showPopup = function (url, callback, dimensions) {
// default dimensions that worked well for facebook and google // default dimensions that worked well for facebook and google
var popup = openCenteredPopup( var popup = openCenteredPopup(
url, url,
(dimensions && dimensions.width) || 650, (dimensions && dimensions.width) || 650,
(dimensions && dimensions.height) || 331); (dimensions && dimensions.height) || 331
);


var checkPopupOpen = setInterval(function() { var checkPopupOpen = setInterval(function() {
try { try {
Expand All @@ -32,7 +32,7 @@ Oauth.initiateLogin = function(credentialToken, url, credentialRequestCompleteCa


if (popupClosed) { if (popupClosed) {
clearInterval(checkPopupOpen); clearInterval(checkPopupOpen);
credentialRequestCompleteCallback(credentialToken); callback();
} }
}, 100); }, 100);
}; };
Expand Down Expand Up @@ -61,3 +61,13 @@ var openCenteredPopup = function(url, width, height) {
newwindow.focus(); newwindow.focus();
return newwindow; 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
);
};
7 changes: 5 additions & 2 deletions packages/twitter/twitter_client.js
Expand Up @@ -29,9 +29,12 @@ Twitter.requestCredential = function (options, credentialRequestCompleteCallback


// url to app, enters "step 1" as described in // url to app, enters "step 1" as described in
// packages/accounts-oauth1-helper/oauth1_server.js // packages/accounts-oauth1-helper/oauth1_server.js
var url = '/_oauth/twitter/?requestTokenAndRedirect=' var loginUrl = '/_oauth/twitter/?requestTokenAndRedirect='
+ encodeURIComponent(callbackUrl) + encodeURIComponent(callbackUrl)
+ '&state=' + credentialToken; + '&state=' + credentialToken;


Oauth.initiateLogin(credentialToken, url, credentialRequestCompleteCallback); Oauth.showPopup(
loginUrl,
_.bind(credentialRequestCompleteCallback, null, credentialToken)
);
}; };
5 changes: 4 additions & 1 deletion packages/weibo/weibo_client.js
Expand Up @@ -27,5 +27,8 @@ Weibo.requestCredential = function (options, credentialRequestCompleteCallback)
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/weibo?close', {replaceLocalhost: true}) + '&redirect_uri=' + Meteor.absoluteUrl('_oauth/weibo?close', {replaceLocalhost: true}) +
'&state=' + credentialToken; '&state=' + credentialToken;


Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback); Oauth.showPopup(
loginUrl,
_.bind(credentialRequestCompleteCallback, null, credentialToken)
);
}; };

0 comments on commit d573464

Please sign in to comment.