In an app I’m building, users can tweet within the app, and so we have to authenticate against Twitter using OAuth1.0a. As part of the process, we have to pop up a window in which the user can log into Twitter and grant permission to create posts on their behalf. After they grant permission, Twitter redirects them to a URL of our choice, and adds two query parameters for the tokens we need to post tweets on the user’s behalf.
That URL needs to load a page which executes JavaScript to grab the parameters from the URL, pass them back to the Ember app, and then close the page. The code I came up with to do that is:
var getParameter = function(parameter) {
return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(parameter).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
};
var oauth_token = getParameter('oauth_token');
var oauth_verifier = getParameter('oauth_verifier');
var twitterController = window.opener.App.__container__.lookup('controller:twitter-authentication');
twitterController.set('oauth_token', oauth_token);
twitterController.set('oauth_verifier', oauth_verifier);
twitterController.send('afterAuthentication');
window.close();
The part I’m concerned about is window.opener.App.__container__.lookup('controller:twitter-authentication');
. I understand that you’re not “supposed” to use App.__container__
except for debugging, but how else can I trigger an action on my app from the child window? Is there a better way to do this?
Thanks in advance!