var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,b,d){if(null==a)throw new TypeError("The 'this' value for String.prototype."+d+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+d+" must not be a regular expression");return a+""};
$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){if(d.get||d.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,b,d,e){if(b){d=$jscomp.global;a=a.split(".");for(e=0;e<a.length-1;e++){var c=a[e];c in d||(d[c]={});d=d[c]}a=a[a.length-1];e=d[a];b=b(e);b!=e&&null!=b&&$jscomp.defineProperty(d,a,{configurable:!0,writable:!0,value:b})}};
$jscomp.polyfill("String.prototype.endsWith",function(a){return a?a:function(a,d){var b=$jscomp.checkStringArgs(this,a,"endsWith");a+="";void 0===d&&(d=b.length);for(var c=Math.max(0,Math.min(d|0,b.length)),g=a.length;0<g&&0<c;)if(b[--c]!=a[--g])return!1;return 0>=g}},"es6-impl","es3");
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,d){var b=$jscomp.checkStringArgs(this,a,"startsWith");a+="";for(var c=b.length,g=a.length,h=Math.max(0,Math.min(d|0,b.length)),f=0;f<g&&h<c;)if(b[h++]!=a[f++])return!1;return f>=g}},"es6-impl","es3");
var userManager=function(){function a(){try{var a=JSON.parse(this.responseText)}catch(h){console.error("oidc unable to parse post token response",h)}a.error?console.error("oidc post token failed",a):e&&(window.location.href=window.location.origin+window.location.pathname)}function b(c){var b=new XMLHttpRequest;c="token="+c.access_token;e&&(c+="&new=true");b.open("POST","kopano.php?service=token",!0);b.setRequestHeader("Content-type","application/x-www-form-urlencoded");b.addEventListener("load",a);
b.send(c)}function d(){window.onunload=function(){};window.location="?logout"}var e=!1,c;Oidc.Log.logger=console;Oidc.Log.level=Oidc.Log.DEBUG;return{init:function(a,h){e=h;var f=window.location.href;f.endsWith("/")||(f+="/");a.redirect_uri=f+"#oidc-callback";a.post_logout_redirect_uri=f+"?logout";a.silent_redirect_uri=f+"?oidc-silent-refresh";c=new Oidc.UserManager(a);c.clearStaleState();c.events.addAccessTokenExpired(function(){console.warn("oidc token expired");c.removeUser();d()});c.events.addSilentRenewError(function(a){console.error("oidc silent renew error",
a.error);if(a)switch(a.error){case "interaction_required":case "login_required":c.removeUser(),d()}});c.events.addUserLoaded(function(a){c.getUser().then(function(a){b(a)})});c.events.addUserSignedOut(function(){c.removeUser()});c.events.addUserUnloaded(function(){d()});e&&window.location.hash.startsWith("#oidc-callback")?c.signinRedirectCallback().then(function(a){b(a);return a})["catch"](function(a){console.error("oidc failed to complete authentication",a);return null}).then(function(a){var b=window.location.toString();
0<b.indexOf("#")&&(b=b.substring(0,b.indexOf("#")),window.history.replaceState({},document.title,b));a||c.signinRedirect()}):c.getUser().then(function(a){a?b(a):c.signinSilent().then(function(a){a&&b(a);return a})["catch"](function(a){console.error("oidc signin silent failed",a);return null}).then(function(a){!a&&e&&(console.debug("oidc signin silent did not return a user"),c.signinRedirect().then(function(a){console.debug("oidc signing redirect",a)}))})})},signOut:function(){c.signoutRedirect()}}}();
document.addEventListener("DOMContentLoaded",function(){var a=document.getElementById("oidc-settings");if(a){var b=JSON.parse(a.getAttribute("content")),a=""===a.getAttribute("logon");userManager.init(b,a)}});
