"use strict";!function(){function initKeycloak(){var keycloak=new Keycloak(AUTH_CONFIG_PATH);auth.loggedIn=!1,keycloak.init({onLoad:"login-required"}).success(function(){auth.loggedIn=!0,auth.keycloak=keycloak,auth.logout=function(){auth.loggedIn=!1,auth.keycloak=null,window.location=keycloak.createLogoutUrl()},app.factory("Auth",function(){return auth}),angular.bootstrap(document,["upsConsole"])}).error(function(){window.location.reload()})}function configureAuth(){app.factory("Auth",function(){return auth}),app.factory("authInterceptor",function($q,Auth){return{request:function(config){var deferred=$q.defer();return"rest/sender"===config.url||"rest/registry/device/importer"===config.url?config:(Auth.keycloak&&Auth.keycloak.token&&Auth.keycloak.updateToken(5).success(function(){config.headers=config.headers||{},config.headers.Authorization="Bearer "+Auth.keycloak.token,deferred.resolve(config)}).error(function(){window.location.reload()}),deferred.promise)}}}),app.config(function($httpProvider){$httpProvider.interceptors.push("authInterceptor")})}var auth={},app=angular.module("upsConsole"),AUTH_CONFIG_PATH="rest/auth/config";angular.element(document).ready(function(){fetch(AUTH_CONFIG_PATH).then(function(response){return response.json()}).then(function(config){config["auth-enabled"]?(initKeycloak(),configureAuth()):(app.factory("Auth",function(){return auth.loggedIn=!0,auth.logout=function(){},auth}),angular.bootstrap(document,["upsConsole"]))})})}();