UNPKG

ngx-adal-8

Version:
2 lines 4.2 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs/operators"),require("rxjs"),require("@angular/common/http"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-adal-8",["exports","@angular/core","rxjs/operators","rxjs","@angular/common/http","@angular/common"],t):t((e=e||self)["ngx-adal-8"]={},e.ng.core,e.rxjs.operators,e.rxjs,e.ng.common.http,e.ng.common)}(this,function(e,t,o,n,r,i){"use strict";var a=function(){function e(e){this.adalConfig=e,e.redirectUri=window.location.origin+"/"+e.redirectUri,e.postLogoutRedirectUri=window.location.origin+"/"+e.postLogoutRedirectUri,this.context=new AuthenticationContext(e),this.handleCallback()}return Object.defineProperty(e.prototype,"LoggedInUserEmail",{get:function(){return this.isAuthenticated?this.context.getCachedUser().userName:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"LoggedInUserName",{get:function(){return this.isAuthenticated?this.context.getCachedUser().profile.name:""},enumerable:!0,configurable:!0}),e.prototype.login=function(){this.context.login()},e.prototype.logout=function(){this.context.logOut()},e.prototype.GetResourceForEndpoint=function(e){return this.context.getResourceForEndpoint(e)},e.prototype.RenewToken=function(e){var t=this.GetResourceForEndpoint(e);return this.context.clearCacheForResource(t)},e.prototype.acquireToken=function(e){var t,r=this;return n.bindCallback(function(o){var n,i=null;return n=r.GetResourceForEndpoint(e),r.context.acquireToken(n,function(e,a){e?(r.context.error("Error when acquiring token for resource: "+n,e),t=e,o(null)):(o(a),i=a)}),i})().pipe(o.map(function(e){if(!e&&t)throw t;return e}))},e.prototype.getToken=function(e){var t,o=this.context.getResourceForEndpoint(e);return t=o?"adal.access.token.key"+o:"adal.idtoken","localStorage"===this.adalConfig.cacheLocation?localStorage.getItem(t):sessionStorage.getItem(t)},e.prototype.handleCallback=function(){this.context.handleWindowCallback()},Object.defineProperty(e.prototype,"userInfo",{get:function(){return this.context.getCachedUser()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"accessToken",{get:function(){return this.context.getCachedToken(this.adalConfig.clientId)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAuthenticated",{get:function(){return!(!this.userInfo||!this.accessToken)},enumerable:!0,configurable:!0}),e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:undefined,decorators:[{type:t.Inject,args:["adalConfig"]}]}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject("adalConfig"))},token:e,providedIn:"root"}),e}(),c=function(){function e(e){this.adal=e}return e.prototype.intercept=function(e,t){return this.adal.GetResourceForEndpoint(e.url)?(this.adal.isAuthenticated||this.adal.RenewToken(e.url),this.adal.acquireToken(e.url).pipe(o.mergeMap(function(o){var n=e.clone({setHeaders:{Authorization:"Bearer "+o,"content-Type":"application/json; charset=utf-8",Accept:"application/json"}});return t.handle(n)}))):t.handle(e)},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:a}]},e}(),u=function(){function e(e){this.adalSvc=e}return e.prototype.canActivate=function(e,t){return!!this.adalSvc.isAuthenticated||(this.adalSvc.login(),!1)},e.prototype.canActivateChild=function(e,t){return this.canActivate(e,t)},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:a}]},e}(),s=function(){function e(e){if(e)throw new Error("NgxAdalModule is already loaded. Import it in the AppModule only")}return e.forRoot=function(t){return{ngModule:e,providers:[[a,{provide:"adalConfig",useValue:t}]]}},e.decorators=[{type:t.NgModule,args:[{imports:[i.CommonModule],providers:[u,a,{provide:r.HTTP_INTERCEPTORS,useClass:c,multi:!0}]}]}],e.ctorParameters=function(){return[{type:e,decorators:[{type:t.Optional},{type:t.SkipSelf}]}]},e}();e.NgxAdalGuard=u,e.NgxAdalInterceptor=c,e.NgxAdalModule=s,e.NgxAdalService=a,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-adal-8.umd.min.js.map