forked from mozilla/fireplace
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deal with login from email (bug 1095504, bug 1094498)
- Loading branch information
Allen Short
committed
Nov 12, 2014
1 parent
3f996e4
commit 095c0c8
Showing
2 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', '/'); | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters