/*! adal-angular-experimental v2.0.0-experimental 2015-10-22 */ "use strict";"undefined"!=typeof module&&module.exports&&(module.exports.inject=function(a){return new AuthenticationContext(a)}),function(){if(angular){var a=angular.module("AdalAngular",[]);a.provider("adalAuthenticationService",function(){var a=null,b={isAuthenticated:!1,userName:"",loginError:"",profile:""},c=function(c){c===a.config.clientId&&(c=[a.config.clientId]),a._validateInputScope(c);var d=a.getCachedToken(c);b.isAuthenticated=null!==d&&d.length>0;var e=a.getCachedUser()||{userName:""};b.userName=e.userName,b.profile=e.profile,b.loginError=a.getLoginError()};this.init=function(b,d){if(!b)throw new Error("You must set configOptions, when calling init");var e=window.location.hash,f=window.location.href;e&&(f=f.replace(e,"")),b.redirectUri=b.redirectUri||f,b.postLogoutRedirectUri=b.postLogoutRedirectUri||f,d&&d.interceptors&&d.interceptors.push("ProtectedResourceInterceptor"),a=new AuthenticationContext(b),c(a.config.clientId)},this.$get=["$rootScope","$window","$q","$location","$timeout",function(d,e,f,g,h){function i(a,b){return b.requireADLogin?a.requireADLogin!==!1:!!a.requireADLogin}var j=function(){var f=e.location.hash;if(a.isCallback(f)){var i=a.getRequestInfo(f);if(a.saveTokenFromHash(i),g.$$html5?e.location=e.location.origin+e.location.pathname:e.location.hash="",i.requestType!==a.REQUEST_TYPE.LOGIN&&(a.callback=e.parent.AuthenticationContext().callback,i.requestType===a.REQUEST_TYPE.RENEW_TOKEN&&(a.callback=e.parent.callBackMappedToRenewStates[i.stateResponse])),i.stateMatch)if("function"==typeof a.callback){if(i.requestType===a.REQUEST_TYPE.RENEW_TOKEN){if(i.parameters.access_token)return void a.callback(a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION),i.parameters.access_token);if(i.parameters.id_token)return void a.callback(a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION),i.parameters.id_token)}}else c(a.config.clientId),b.userName?(h(function(){c(a.config.clientId),d.userInfo=b;var e=a._getItem(a.CONSTANTS.STORAGE.START_PAGE);e&&g.path(e)},1),d.$broadcast("adal:loginSuccess")):d.$broadcast("adal:loginFailure",a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION))}else a.log(a.config.clientId,"No callback. App resumes after closing or moving to new page."),c(a.config.clientId),a._renewActive||b.isAuthenticated||!b.userName||a._getItem(a.CONSTANTS.STORAGE.FAILED_RENEW)||a.acquireTokenSilent(a.config.clientId,null,function(a,c){a?d.$broadcast("adal:loginFailure","auto renew failure"):c&&(b.isAuthenticated=!0)});h(function(){c(a.config.clientId),d.userInfo=b},1)},k=function(){a._logstatus("Login event for:"+g.$$path),a.config&&a.config.localLoginUrl?g.path(a.config.localLoginUrl):(a._saveItem(a.CONSTANTS.STORAGE.START_PAGE,g.$$path),a._logstatus("Start login at:"+window.location.href),d.$broadcast("adal:loginRedirect"),a.login(null))},l=function(c,d){d&&d.$$route&&i(d.$$route,a.config)&&(b.isAuthenticated||(a._logstatus("Route change event for:"+g.$$path),k()))},m=function(c,d){d&&i(d,a.config)&&(b.isAuthenticated||(a._logstatus("State change event for:"+g.$$path),k()))};return d.$on("$routeChangeStart",l),d.$on("$stateChangeStart",m),d.$on("$locationChangeStart",j),c(a.config.clientId),d.userInfo=b,{config:a.config,login:function(b){a.login(b)},loginInProgress:function(){return a.loginInProgress()},logOut:function(){a.logOut()},getCachedToken:function(b){return a.getCachedToken(b)},userInfo:b,acquireTokenSilent:function(b){var c=f.defer();return a.acquireTokenSilent(b,function(b,d){b?(a._logstatus("err :"+b),c.reject(b)):c.resolve(d)}),c.promise},getUser:function(){var b=f.defer();return a.getUser(function(c,d){c?(a._logstatus("err :"+c),b.reject(c)):b.resolve(d)}),b.promise},getScopesForEndpoint:function(b){return a.getScopesForEndpoint(b)},clearCache:function(){a.clearCache()},clearCacheForStoredEntry:function(b){a.clearCacheForStoredEntry(b)},log:function(b,c){a.log(b,c)}}}]}),a.factory("ProtectedResourceInterceptor",["adalAuthenticationService","$q","$rootScope",function(a,b,c){return{request:function(c){if(c){c.headers=c.headers||{};var d=a.getScopesForEndpoint(c.url),e=a.getCachedToken(d),f=!1;if(e)return a.log(d,"Token is avaliable for this url "+c.url),c.headers.Authorization="Bearer "+e,c;if(a.config)for(var g in a.config.endpoints)c.url.indexOf(g)>-1&&(f=!0);if(a.loginInProgress())return a.log(d,"login already start."),b.reject();if(a.config&&f){var h=b.defer();return a.acquireTokenSilent(d).then(function(b){a.log(d,"Token is avaliable"),c.headers.Authorization="Bearer "+b,h.resolve(c)},function(a){h.reject(a)}),h.promise}return c}},responseError:function(d){if(a.log(null,"Getting error in the response"),d&&401===d.status){var e=a.getScopesForEndpoint(d.config.url);a.clearCacheForStoredEntry(e),c.$broadcast("adal:notAuthorized",d,e)}return b.reject(d)}}}])}else console.error("Angular.JS is not included")}();