@dontdrinkandroot/ngx-extensions 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/public-api.mjs +4 -1
- package/esm2020/src/cookie/cookie.service.mjs +3 -3
- package/esm2020/src/ddr-extensions.module.mjs +4 -4
- package/esm2020/src/http/redirect-to-login-interceptor.service.mjs +3 -3
- package/esm2020/src/http/with-credentials-interceptor.service.mjs +3 -3
- package/esm2020/src/image/lazy-image.directive.mjs +3 -3
- package/esm2020/src/jwt/jwt-interceptor.service.mjs +3 -3
- package/esm2020/src/jwt/jwt-refresh-token-interceptor.service.mjs +3 -3
- package/esm2020/src/jwt/jwt.service.mjs +3 -3
- package/esm2020/src/oauth/json-web-token.mjs +2 -0
- package/esm2020/src/oauth/oauth2-access-token-interceptor.service.mjs +26 -0
- package/esm2020/src/oauth/oauth2-config.mjs +11 -0
- package/esm2020/src/oauth/oauth2-error.mjs +8 -0
- package/esm2020/src/oauth/oauth2-refresh-token-interceptor.service.mjs +24 -0
- package/esm2020/src/oauth/oauth2.module.mjs +44 -0
- package/esm2020/src/oauth/oauth2.service.mjs +119 -0
- package/esm2020/src/oauth/redirect-to-oauth2-login-interceptor.service.mjs +41 -0
- package/esm2020/src/oauth/token-response.mjs +2 -0
- package/esm2020/src/scroll/bottom-hit.directive.mjs +3 -3
- package/esm2020/src/scroll/scroll.service.mjs +3 -3
- package/esm2020/src/visibility/visibility.service.mjs +3 -3
- package/fesm2015/dontdrinkandroot-ngx-extensions.mjs +276 -36
- package/fesm2015/dontdrinkandroot-ngx-extensions.mjs.map +1 -1
- package/fesm2020/dontdrinkandroot-ngx-extensions.mjs +272 -36
- package/fesm2020/dontdrinkandroot-ngx-extensions.mjs.map +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +3 -0
- package/src/oauth/json-web-token.d.ts +30 -0
- package/src/oauth/oauth2-access-token-interceptor.service.d.ts +14 -0
- package/src/oauth/oauth2-config.d.ts +9 -0
- package/src/oauth/oauth2-error.d.ts +5 -0
- package/src/oauth/oauth2-refresh-token-interceptor.service.d.ts +14 -0
- package/src/oauth/oauth2.module.d.ts +9 -0
- package/src/oauth/oauth2.service.d.ts +33 -0
- package/src/oauth/redirect-to-oauth2-login-interceptor.service.d.ts +18 -0
- package/src/oauth/token-response.d.ts +6 -0
|
@@ -8,7 +8,7 @@ import { NavigationStart } from '@angular/router';
|
|
|
8
8
|
import { merge, fromEvent, throwError } from 'rxjs';
|
|
9
9
|
import { debounceTime, startWith, map, distinctUntilChanged, shareReplay, catchError, switchMap } from 'rxjs/operators';
|
|
10
10
|
import * as i2$1 from '@angular/common/http';
|
|
11
|
-
import { HttpErrorResponse } from '@angular/common/http';
|
|
11
|
+
import { HttpErrorResponse, HttpParams, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
12
12
|
|
|
13
13
|
class NumberUtils {
|
|
14
14
|
static getNextPowerOfTwo(value) {
|
|
@@ -171,15 +171,15 @@ class LazyImageDirective {
|
|
|
171
171
|
return window.getComputedStyle(element).display === 'none';
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
LazyImageDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
175
|
-
LazyImageDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.
|
|
174
|
+
LazyImageDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: LazyImageDirective, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
175
|
+
LazyImageDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.3", type: LazyImageDirective, selector: "[ddrLazyImage]", inputs: { src: ["ddrLazyImage", "src"], objectFit: "objectFit", offset: "offset" }, host: { listeners: { "window:resize": "windowResized($event)", "window:scroll": "windowScroll($event)" }, properties: { "src": "this.hostSrc", "style.width.px": "this.hostStyleWidthPx", "style.height.px": "this.hostStyleHeightPx", "style.object-fit": "this.hostStyleObjectFit" } }, usesOnChanges: true, ngImport: i0 });
|
|
176
176
|
__decorate([
|
|
177
177
|
Debounce()
|
|
178
178
|
], LazyImageDirective.prototype, "windowResized", null);
|
|
179
179
|
__decorate([
|
|
180
180
|
Limit()
|
|
181
181
|
], LazyImageDirective.prototype, "windowScroll", null);
|
|
182
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
182
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: LazyImageDirective, decorators: [{
|
|
183
183
|
type: Directive,
|
|
184
184
|
args: [{ selector: '[ddrLazyImage]' }]
|
|
185
185
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { src: [{
|
|
@@ -240,15 +240,15 @@ class BottomHitDirective {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
BottomHitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
244
|
-
BottomHitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.
|
|
243
|
+
BottomHitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: BottomHitDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
244
|
+
BottomHitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.3", type: BottomHitDirective, selector: "[ddrBottomHit]", outputs: { onWindowBottomHit: "onWindowBottomHit", onElementBottomHit: "onElementBottomHit" }, host: { listeners: { "scroll": "scrolled($event)", "window:scroll": "windowScrolled($event)" } }, ngImport: i0 });
|
|
245
245
|
__decorate([
|
|
246
246
|
Limit()
|
|
247
247
|
], BottomHitDirective.prototype, "scrolled", null);
|
|
248
248
|
__decorate([
|
|
249
249
|
Limit()
|
|
250
250
|
], BottomHitDirective.prototype, "windowScrolled", null);
|
|
251
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
251
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: BottomHitDirective, decorators: [{
|
|
252
252
|
type: Directive,
|
|
253
253
|
args: [{
|
|
254
254
|
selector: '[ddrBottomHit]'
|
|
@@ -270,17 +270,17 @@ const DDR_JWT_REFRESH_TOKEN_URL = new InjectionToken('DDR_JWT_REFRESH_TOKEN_URL'
|
|
|
270
270
|
const DDR_LOGIN_PATH = new InjectionToken('DDR_LOGIN_PATH');
|
|
271
271
|
class DdrExtensionsModule {
|
|
272
272
|
}
|
|
273
|
-
DdrExtensionsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
274
|
-
DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.
|
|
273
|
+
DdrExtensionsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: DdrExtensionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
274
|
+
DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.3", ngImport: i0, type: DdrExtensionsModule, declarations: [LazyImageDirective,
|
|
275
275
|
BottomHitDirective], exports: [LazyImageDirective,
|
|
276
276
|
BottomHitDirective] });
|
|
277
|
-
DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.
|
|
277
|
+
DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: DdrExtensionsModule, providers: [
|
|
278
278
|
{
|
|
279
279
|
provide: DDR_LOGIN_PATH,
|
|
280
280
|
useValue: '/login'
|
|
281
281
|
}
|
|
282
282
|
] });
|
|
283
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
283
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: DdrExtensionsModule, decorators: [{
|
|
284
284
|
type: NgModule,
|
|
285
285
|
args: [{
|
|
286
286
|
declarations: [
|
|
@@ -419,9 +419,9 @@ class CookieService {
|
|
|
419
419
|
return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
CookieService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
423
|
-
CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
424
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
422
|
+
CookieService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: CookieService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
423
|
+
CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: CookieService, providedIn: 'root' });
|
|
424
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: CookieService, decorators: [{
|
|
425
425
|
type: Injectable,
|
|
426
426
|
args: [{
|
|
427
427
|
providedIn: 'root'
|
|
@@ -502,9 +502,9 @@ class ScrollService {
|
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
506
|
-
ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
507
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
505
|
+
ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: ScrollService, deps: [{ token: i1.Router }, { token: i2.ViewportScroller }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
506
|
+
ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: ScrollService, providedIn: 'root' });
|
|
507
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: ScrollService, decorators: [{
|
|
508
508
|
type: Injectable,
|
|
509
509
|
args: [{
|
|
510
510
|
providedIn: 'root'
|
|
@@ -519,9 +519,9 @@ class VisibilityService {
|
|
|
519
519
|
return this.visibility$;
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
-
VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
523
|
-
VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
524
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
522
|
+
VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
523
|
+
VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, providedIn: 'root' });
|
|
524
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, decorators: [{
|
|
525
525
|
type: Injectable,
|
|
526
526
|
args: [{ providedIn: 'root' }]
|
|
527
527
|
}], ctorParameters: function () { return []; } });
|
|
@@ -537,9 +537,9 @@ class WithCredentialsInterceptor {
|
|
|
537
537
|
return next.handle(cloned);
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
541
|
-
WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
542
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
540
|
+
WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
541
|
+
WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor });
|
|
542
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
|
|
543
543
|
type: Injectable
|
|
544
544
|
}] });
|
|
545
545
|
|
|
@@ -588,9 +588,9 @@ class RedirectToLoginInterceptor {
|
|
|
588
588
|
}));
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
|
-
RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
592
|
-
RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
593
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
591
|
+
RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToLoginInterceptor, deps: [{ token: i1.Router }, { token: DDR_LOGIN_PATH }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
592
|
+
RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToLoginInterceptor });
|
|
593
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
|
|
594
594
|
type: Injectable
|
|
595
595
|
}], ctorParameters: function () {
|
|
596
596
|
return [{ type: i1.Router }, { type: undefined, decorators: [{
|
|
@@ -599,6 +599,246 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
599
599
|
}] }];
|
|
600
600
|
} });
|
|
601
601
|
|
|
602
|
+
const DDR_OAUTH2_CONFIG = new InjectionToken('DDR_OAUTH2_CONFIG');
|
|
603
|
+
class OAuth2Config {
|
|
604
|
+
constructor(clientId, redirectUri, authorizeUri, tokenUri) {
|
|
605
|
+
this.clientId = clientId;
|
|
606
|
+
this.redirectUri = redirectUri;
|
|
607
|
+
this.authorizeUri = authorizeUri;
|
|
608
|
+
this.tokenUri = tokenUri;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
class OAuth2Error extends Error {
|
|
613
|
+
constructor(error) {
|
|
614
|
+
super(error);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
OAuth2Error.CODE_NOT_FOUND = 'code_not_found';
|
|
618
|
+
OAuth2Error.ACCESS_DENIED = 'access_denied';
|
|
619
|
+
|
|
620
|
+
class OAuth2Service {
|
|
621
|
+
constructor(route, httpClient, config) {
|
|
622
|
+
this.route = route;
|
|
623
|
+
this.httpClient = httpClient;
|
|
624
|
+
this.config = config;
|
|
625
|
+
this.accessTokenString = null;
|
|
626
|
+
this.accessToken = null;
|
|
627
|
+
this.REFRESH_MARGIN_SECONDS = 60 * 10;
|
|
628
|
+
this.refreshTokenRequest$ = null;
|
|
629
|
+
}
|
|
630
|
+
redirectToLogin() {
|
|
631
|
+
const challenge = this.createChallenge();
|
|
632
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_CHALLENGE, challenge);
|
|
633
|
+
const params = new HttpParams()
|
|
634
|
+
.set('client_id', this.config.clientId)
|
|
635
|
+
.set('response_type', 'code')
|
|
636
|
+
.set('redirect_uri', this.config.redirectUri)
|
|
637
|
+
.set('code_challenge', challenge)
|
|
638
|
+
.set('code_challenge_method', 'plain');
|
|
639
|
+
window.location.href = this.config.authorizeUri + '?' + params.toString();
|
|
640
|
+
}
|
|
641
|
+
handleCode() {
|
|
642
|
+
if (this.route.snapshot.queryParamMap.has('error')) {
|
|
643
|
+
const error = this.route.snapshot.queryParamMap.get('error');
|
|
644
|
+
return throwError(() => new OAuth2Error(error !== null && error !== void 0 ? error : 'Unknown error'));
|
|
645
|
+
}
|
|
646
|
+
if (!this.route.snapshot.queryParamMap.has('code')) {
|
|
647
|
+
return throwError(() => new OAuth2Error(OAuth2Error.CODE_NOT_FOUND));
|
|
648
|
+
}
|
|
649
|
+
const code = TypeUtils.notNull(this.route.snapshot.queryParamMap.get('code'));
|
|
650
|
+
const params = new HttpParams()
|
|
651
|
+
.set('grant_type', 'authorization_code')
|
|
652
|
+
.set('code', code)
|
|
653
|
+
.set('redirect_uri', this.config.redirectUri)
|
|
654
|
+
.set('code_verifier', TypeUtils.notNull(localStorage.getItem(OAuth2Service.STORAGE_KEY_CHALLENGE)))
|
|
655
|
+
.set('client_id', this.config.clientId);
|
|
656
|
+
return this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)));
|
|
657
|
+
}
|
|
658
|
+
createChallenge() {
|
|
659
|
+
return StringUtils.createRandomString(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._~');
|
|
660
|
+
}
|
|
661
|
+
getRefreshToken() {
|
|
662
|
+
return localStorage.getItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
663
|
+
}
|
|
664
|
+
getAccessTokenString() {
|
|
665
|
+
return this.accessTokenString;
|
|
666
|
+
}
|
|
667
|
+
isAccessTokenExpired() {
|
|
668
|
+
return (null == this.accessToken
|
|
669
|
+
|| this.accessToken.exp * 1000 < Date.now());
|
|
670
|
+
}
|
|
671
|
+
isRefreshPossibleAndRequired(req = null) {
|
|
672
|
+
return ((null == req || !req.url.endsWith(this.config.tokenUri))
|
|
673
|
+
&& null != this.getRefreshToken()
|
|
674
|
+
&& (null == this.accessToken
|
|
675
|
+
|| (this.accessToken.exp - this.REFRESH_MARGIN_SECONDS) * 1000 < Date.now()));
|
|
676
|
+
}
|
|
677
|
+
performRefresh() {
|
|
678
|
+
if (null == this.refreshTokenRequest$) {
|
|
679
|
+
console.log('Performing token refesh');
|
|
680
|
+
const params = new HttpParams()
|
|
681
|
+
.set('grant_type', 'refresh_token')
|
|
682
|
+
.set('refresh_token', TypeUtils.notNull(this.getRefreshToken()))
|
|
683
|
+
.set('client_id', this.config.clientId);
|
|
684
|
+
this.refreshTokenRequest$ = this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)), catchError(error => {
|
|
685
|
+
this.accessTokenString = null;
|
|
686
|
+
this.accessToken = null;
|
|
687
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
688
|
+
this.refreshTokenRequest$ = null;
|
|
689
|
+
return throwError(error);
|
|
690
|
+
}), shareReplay(1));
|
|
691
|
+
}
|
|
692
|
+
return this.refreshTokenRequest$;
|
|
693
|
+
}
|
|
694
|
+
processTokenResponse(tokenResponse) {
|
|
695
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_CHALLENGE);
|
|
696
|
+
this.accessTokenString = tokenResponse.access_token;
|
|
697
|
+
this.accessToken = JSON.parse(atob(tokenResponse.access_token.split('.')[1]));
|
|
698
|
+
console.log('Access Token Expiry', new Date(this.accessToken.exp * 1000));
|
|
699
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN, tokenResponse.refresh_token);
|
|
700
|
+
return this.accessToken;
|
|
701
|
+
}
|
|
702
|
+
clear() {
|
|
703
|
+
this.accessToken = null;
|
|
704
|
+
this.accessTokenString = null;
|
|
705
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
706
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
707
|
+
}
|
|
708
|
+
setReturnUrl(url) {
|
|
709
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_RETURN_URL, url);
|
|
710
|
+
}
|
|
711
|
+
getReturnUrl() {
|
|
712
|
+
return localStorage.getItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
OAuth2Service.STORAGE_KEY_CHALLENGE = 'ddr_oauth2_challenge';
|
|
716
|
+
OAuth2Service.STORAGE_KEY_REFRESH_TOKEN = 'ddr_oauth2_refresh_token';
|
|
717
|
+
OAuth2Service.STORAGE_KEY_RETURN_URL = 'ddr_oauth2_return_url';
|
|
718
|
+
OAuth2Service.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Service, deps: [{ token: i1.ActivatedRoute }, { token: i2$1.HttpClient }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
719
|
+
OAuth2Service.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Service });
|
|
720
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Service, decorators: [{
|
|
721
|
+
type: Injectable
|
|
722
|
+
}], ctorParameters: function () {
|
|
723
|
+
return [{ type: i1.ActivatedRoute }, { type: i2$1.HttpClient }, { type: OAuth2Config, decorators: [{
|
|
724
|
+
type: Inject,
|
|
725
|
+
args: [DDR_OAUTH2_CONFIG]
|
|
726
|
+
}] }];
|
|
727
|
+
} });
|
|
728
|
+
|
|
729
|
+
class OAuth2RefreshTokenInterceptor {
|
|
730
|
+
constructor(oAuth2Service) {
|
|
731
|
+
this.oAuth2Service = oAuth2Service;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* @override
|
|
735
|
+
*/
|
|
736
|
+
intercept(req, next) {
|
|
737
|
+
if (this.oAuth2Service.isRefreshPossibleAndRequired(req)) {
|
|
738
|
+
return this.oAuth2Service.performRefresh().pipe(switchMap(() => next.handle(req)));
|
|
739
|
+
}
|
|
740
|
+
return next.handle(req);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
OAuth2RefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
744
|
+
OAuth2RefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor });
|
|
745
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor, decorators: [{
|
|
746
|
+
type: Injectable
|
|
747
|
+
}], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
|
|
748
|
+
|
|
749
|
+
class RedirectToOAuth2LoginInterceptor {
|
|
750
|
+
constructor(oAuth2Service, router, oAuth2Config) {
|
|
751
|
+
this.oAuth2Service = oAuth2Service;
|
|
752
|
+
this.router = router;
|
|
753
|
+
this.oAuth2Config = oAuth2Config;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* @override
|
|
757
|
+
*/
|
|
758
|
+
intercept(req, next) {
|
|
759
|
+
return next.handle(req).pipe(catchError((err) => {
|
|
760
|
+
if (err instanceof HttpErrorResponse) {
|
|
761
|
+
if (err.status === 401) {
|
|
762
|
+
if (!window.location.href.startsWith(this.oAuth2Config.redirectUri)) {
|
|
763
|
+
this.oAuth2Service.setReturnUrl(this.router.routerState.snapshot.url);
|
|
764
|
+
this.oAuth2Service.redirectToLogin();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
return throwError(err);
|
|
769
|
+
}));
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
RedirectToOAuth2LoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, deps: [{ token: OAuth2Service }, { token: i1.Router }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
773
|
+
RedirectToOAuth2LoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToOAuth2LoginInterceptor });
|
|
774
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, decorators: [{
|
|
775
|
+
type: Injectable
|
|
776
|
+
}], ctorParameters: function () {
|
|
777
|
+
return [{ type: OAuth2Service }, { type: i1.Router }, { type: OAuth2Config, decorators: [{
|
|
778
|
+
type: Inject,
|
|
779
|
+
args: [DDR_OAUTH2_CONFIG]
|
|
780
|
+
}] }];
|
|
781
|
+
} });
|
|
782
|
+
|
|
783
|
+
class OAuth2AccessTokenInterceptor {
|
|
784
|
+
constructor(oAuth2Service) {
|
|
785
|
+
this.oAuth2Service = oAuth2Service;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* @override
|
|
789
|
+
*/
|
|
790
|
+
intercept(req, next) {
|
|
791
|
+
const accessTokenString = this.oAuth2Service.getAccessTokenString();
|
|
792
|
+
if (null !== accessTokenString && !this.oAuth2Service.isAccessTokenExpired()) {
|
|
793
|
+
req = req.clone({
|
|
794
|
+
headers: req.headers.set('Authorization', 'Bearer ' + accessTokenString)
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
return next.handle(req);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
OAuth2AccessTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
801
|
+
OAuth2AccessTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor });
|
|
802
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor, decorators: [{
|
|
803
|
+
type: Injectable
|
|
804
|
+
}], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
|
|
805
|
+
|
|
806
|
+
class OAuth2Module {
|
|
807
|
+
static forRoot(config) {
|
|
808
|
+
return {
|
|
809
|
+
ngModule: OAuth2Module,
|
|
810
|
+
providers: [
|
|
811
|
+
OAuth2Service,
|
|
812
|
+
{
|
|
813
|
+
provide: DDR_OAUTH2_CONFIG,
|
|
814
|
+
useValue: config
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
provide: HTTP_INTERCEPTORS,
|
|
818
|
+
useClass: OAuth2RefreshTokenInterceptor,
|
|
819
|
+
multi: true
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
provide: HTTP_INTERCEPTORS,
|
|
823
|
+
useClass: RedirectToOAuth2LoginInterceptor,
|
|
824
|
+
multi: true
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
provide: HTTP_INTERCEPTORS,
|
|
828
|
+
useClass: OAuth2AccessTokenInterceptor,
|
|
829
|
+
multi: true
|
|
830
|
+
}
|
|
831
|
+
],
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
OAuth2Module.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
836
|
+
OAuth2Module.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module });
|
|
837
|
+
OAuth2Module.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module });
|
|
838
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module, decorators: [{
|
|
839
|
+
type: NgModule
|
|
840
|
+
}] });
|
|
841
|
+
|
|
602
842
|
class JwtService {
|
|
603
843
|
constructor(storagePrefix) {
|
|
604
844
|
this.storagePrefix = storagePrefix;
|
|
@@ -666,9 +906,9 @@ class JwtService {
|
|
|
666
906
|
return this.storagePrefix + '.jwt.refresh_token';
|
|
667
907
|
}
|
|
668
908
|
}
|
|
669
|
-
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
670
|
-
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
671
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
909
|
+
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtService, deps: [{ token: DDR_STORAGE_PREFIX }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
910
|
+
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
911
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtService, decorators: [{
|
|
672
912
|
type: Injectable,
|
|
673
913
|
args: [{
|
|
674
914
|
providedIn: 'root'
|
|
@@ -697,9 +937,9 @@ class JwtInterceptor {
|
|
|
697
937
|
return next.handle(req);
|
|
698
938
|
}
|
|
699
939
|
}
|
|
700
|
-
JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
701
|
-
JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
702
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
940
|
+
JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
941
|
+
JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor });
|
|
942
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor, decorators: [{
|
|
703
943
|
type: Injectable
|
|
704
944
|
}], ctorParameters: function () { return [{ type: JwtService }]; } });
|
|
705
945
|
|
|
@@ -737,9 +977,9 @@ class JwtRefreshTokenInterceptor {
|
|
|
737
977
|
return this.refreshTokenRequest$;
|
|
738
978
|
}
|
|
739
979
|
}
|
|
740
|
-
JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
741
|
-
JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
742
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
980
|
+
JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtRefreshTokenInterceptor, deps: [{ token: JwtService }, { token: i2$1.HttpClient }, { token: DDR_JWT_REFRESH_TOKEN_URL }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
981
|
+
JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtRefreshTokenInterceptor });
|
|
982
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
|
|
743
983
|
type: Injectable
|
|
744
984
|
}], ctorParameters: function () {
|
|
745
985
|
return [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
|
|
@@ -756,5 +996,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
756
996
|
* Generated bundle index. Do not edit.
|
|
757
997
|
*/
|
|
758
998
|
|
|
759
|
-
export { BottomHitDirective, CollectionUtils, CookieService, DDR_JWT_REFRESH_TOKEN_URL, DDR_LOGIN_PATH, DDR_STORAGE_PREFIX, DdrExtensionsModule, Debounce, JwtInterceptor, JwtRefreshTokenInterceptor, JwtService, LazyImageDirective, Limit, NumberUtils, ObjectUtils, RedirectToLoginInterceptor, ScrollService, StringUtils, TypeUtils, UrlInfo, VisibilityService, WithCredentialsInterceptor };
|
|
999
|
+
export { BottomHitDirective, CollectionUtils, CookieService, DDR_JWT_REFRESH_TOKEN_URL, DDR_LOGIN_PATH, DDR_STORAGE_PREFIX, DdrExtensionsModule, Debounce, JwtInterceptor, JwtRefreshTokenInterceptor, JwtService, LazyImageDirective, Limit, NumberUtils, OAuth2Error, OAuth2Module, OAuth2Service, ObjectUtils, RedirectToLoginInterceptor, ScrollService, StringUtils, TypeUtils, UrlInfo, VisibilityService, WithCredentialsInterceptor };
|
|
760
1000
|
//# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map
|