var LOGINMODULE = LOGINMODULE || (function(){ var _clientID = ''; var _ipdUrl = ''; var _realm = ''; return { init : function(keycloakServer, realm, clientID) { _ipdUrl = keycloakServer; _realm = realm; _clientID = clientID; }, authenticate : async function() { if (window.location.hash) { var locHash = window.location.hash.substr(1), mylocation = locHash.substr(locHash.search(/access_token=/)) .split('&')[0] .split('=')[1]; if (mylocation) { await fetch(window.location.origin+'/refresh-cookies', { method: "GET", headers: { "Content-type": "application/json;charset=UTF-8", "Authorization": "Bearer "+mylocation } }); } window.location.replace(window.location.origin + window.location.pathname); } else { const encodedRedirectUrl = (window.location.href); if (_realm === '') { _realm = window.location.hostname.split(".")[0]; } window.location.replace(`${_ipdUrl}/auth/realms/${_realm}/protocol/openid-connect/auth?client_id=${_clientID}&response_type=token&redirect_uri=${encodedRedirectUrl}`); } } } }());