/* global wu_create_cookie, wu_sso_config, wu_read_cookie, detectIncognito */ (function(o) { window.wu = window.wu || {}; window.is_incognito = false; window.wu.sso_denied = function() { wu_create_cookie('wu_sso_denied', 1, o.expiration_in_minutes); }; // end if; window.wu.check_for_incognito_window = function() { detectIncognito(results => window.is_incognito = results.isPrivate); } // end is_incognito_window; window.wu.check_for_incognito_window(); window.addEventListener('error', wu.sso_denied, true); const w = document.createElement('script'); w.type = 'text/javascript'; w.async = true; w.defer = true; w.src = o.server_url + '?_jsonp=1'; const denied = wu_read_cookie('wu_sso_denied'); document.head.insertAdjacentHTML('beforeend', ` `); if (! o.is_user_logged_in && ! denied) { const s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(w, s); document.body.insertAdjacentHTML('beforeend', '
'); } // end if; window.wu.sso = function(payload) { const encodedLocation = encodeURIComponent(window.location.href); if (payload.code === 200) { if (o.use_overlay) { document.body.classList.add('sso-loading'); } // end if; /** * In case we're dealing with http (without ssl), * we force a redirect to bypass browser cookie * limitations. * * Otherwise, on the else block, * we redirect with the verification code attached, * to perform a regular SSO flow. */ if (payload.verify === 'must-redirect') { window.location.replace(`${ o.server_url }?return_url=${ encodedLocation }`); } else { window.location.replace(`${ o.server_url }?sso_verify=${ payload.verify }&return_url=${ encodedLocation }`); } // end if; } else { /** * If we are in a incognito window, * we give it another try with a full redirect, * as chrome settings might be blocking * cookies from being sent anyways. */ if (window.is_incognito) { if (o.use_overlay) { document.body.classList.add('sso-loading'); } // end if; window.location.replace(`${o.server_url}?return_url=${ encodedLocation }`); return; } // end if; window.wu.sso_denied(); document.body.classList.remove('sso-loading'); } // end if; }; // end sso; (function clean_up_query_args() { if (window.history.replaceState) { window.history.replaceState(null, null, o.filtered_url + window.location.hash); } // end if; }()); }(wu_sso_config));