trigger redirect

This commit is contained in:
Konstantin Haase 2012-12-04 14:39:50 +01:00
parent a62948b047
commit d3ed96f165

View File

@ -272,6 +272,7 @@ console.log('refusing to send a token to <%= target_origin.inspect %>, not white
var url = window.location.pathname + '/iframe' + window.location.search; var url = window.location.pathname + '/iframe' + window.location.search;
var img = document.createElement('img'); var img = document.createElement('img');
var popUpWindow, timeout; var popUpWindow, timeout;
var handshake = location.protocol + "//" + location.host + "/auth/handshake?redirect_uri=";
img.src = "https://third-party-cookies.herokuapp.com/set"; img.src = "https://third-party-cookies.herokuapp.com/set";
@ -291,6 +292,16 @@ console.log('refusing to send a token to <%= target_origin.inspect %>, not white
function popUp() { function popUp() {
popUpWindow = window.open(url, 'Signing in...', 'height=400,width=800'); popUpWindow = window.open(url, 'Signing in...', 'height=400,width=800');
return (!popUpWindow || popUpWindow.closed || typeof popUpWindow.closed == 'undefined');
}
function uberParent(win) {
return win.parent === win ? win : uberParent(win.parent);
}
function redirect() {
win = uberParent(window);
win.location = handshake + win.location;
} }
window.addEventListener("message", function(event) { window.addEventListener("message", function(event) {
@ -307,13 +318,20 @@ console.log('refusing to send a token to <%= target_origin.inspect %>, not white
iframe(); iframe();
timeout = setTimeout(function() { timeout = setTimeout(function() {
console.log('handshake taking too long, creating pop-up'); console.log('handshake taking too long, creating pop-up');
popUp(); if(!popUp()) {
console.log("pop-up failed, redirecting");
redirect();
}
}, 5000); }, 5000);
} else { } else {
console.log("third party cookies disabled, creating pop-up"); console.log("third party cookies disabled, creating pop-up");
if(!popUp()) { if(!popUp()) {
console.log("pop-up failed, trying iframe anyhow"); console.log("pop-up failed, trying iframe anyhow");
iframe(); iframe();
timeout = setTimeout(function() {
console.log('handshake taking too long, redirecting');
if(!popUp()) { redirect(); }
}, 5000);
} }
} }
} }