Skip to content

Commit

Permalink
deal with login from email (bug 1095504, bug 1094498)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Short committed Nov 12, 2014
1 parent 3f996e4 commit 095c0c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
40 changes: 31 additions & 9 deletions src/media/js/views/fxa_authorize.js
@@ -1,29 +1,51 @@
define('views/fxa_authorize', ['log', 'login', 'utils', 'z'],
function(log, login, utils, z) {
define('views/fxa_authorize', ['capabilities', 'log', 'login', 'utils', 'z'],
function(capabilities, log, login, utils, z) {
'use strict';
var console = log('view', 'fxa-login');
return function(builder) {
var auth_code = window.location.href;
if (window.opener) {
var isPopup;
try {
// Accessing things on window.opener might raise a permission-denied
// exception, in which case we aren't executing in the login popup.
if (window.opener.location.protocol == window.location.protocol &&
window.opener.location.host == window.location.host) {
isPopup = true;
}
} catch (e) {
isPopup = false;
}
if (isPopup) {
window.opener.postMessage({auth_code: auth_code},
window.location.origin);
// This code will execute from a hosted origin, since the FxA login
// process redirects there. Nevertheless, this might be a window
// opened by the Marketplace packaged app. So, let's send this info
// to it, if so.
// to it, if so. (Note that this does not apply for yulelog.)
var packaged_origin = 'app://packaged.' + window.location.host;
console.log('Sending OAuth code to parent window ' +
packaged_origin);
window.opener.postMessage({auth_code: auth_code}, packaged_origin);

window.close();
} else {
// No popup, login was likely initiated via email. Let's make this
// window Marketplace.
console.log('Reusing window as Marketplace app');
// No popup, login was likely initiated via email.
var state = utils.getVars().state;
login.handle_fxa_login(auth_code, state);
z.page.trigger('navigate', '/');
if (capabilities.firefoxOS) {
console.log("Starting login webactivity");
// Kick off the Marketplace app rather than doing this in the browser.

new MozActivity({name: 'marketplace-app', data: {
type: 'login',
auth_code: auth_code,
state: state}})
window.close();
} else {
login.handle_fxa_login(auth_code, state);
// Let's make this window Marketplace.
console.log('Reusing window as Marketplace app');
z.page.trigger('navigate', '/');
}
}
};
});
9 changes: 7 additions & 2 deletions src/media/js/webactivities.js
@@ -1,4 +1,4 @@
define('webactivities', ['capabilities', 'log', 'urls', 'utils', 'z'], function(capabilities, log, urls, utils, z) {
define('webactivities', ['capabilities', 'log', 'login', 'urls', 'utils', 'z'], function(capabilities, log, login, urls, utils, z) {

// See https://github.com/mozilla/fireplace/wiki/Web-Activities
//
Expand All @@ -24,7 +24,12 @@ define('webactivities', ['capabilities', 'log', 'urls', 'utils', 'z'], function(

switch (name) {
case 'marketplace-app':
// Load up an app detail page.
// first: has this webactivity been hijacked to convey FxA login info?
if (data.type === 'login') {
login.handle_fxa_login(data.auth_code, data.state);
break;
}
// If not, load up an app detail page.
var slug = data.slug;
var manifest_url = data.manifest_url || data.manifest;
if (slug) {
Expand Down

0 comments on commit 095c0c8

Please sign in to comment.