@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'
|
|
@@ -499,9 +499,9 @@ class ScrollService {
|
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
503
|
-
ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
504
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
502
|
+
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 });
|
|
503
|
+
ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: ScrollService, providedIn: 'root' });
|
|
504
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: ScrollService, decorators: [{
|
|
505
505
|
type: Injectable,
|
|
506
506
|
args: [{
|
|
507
507
|
providedIn: 'root'
|
|
@@ -516,9 +516,9 @@ class VisibilityService {
|
|
|
516
516
|
return this.visibility$;
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
|
-
VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
520
|
-
VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
521
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
519
|
+
VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
520
|
+
VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, providedIn: 'root' });
|
|
521
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: VisibilityService, decorators: [{
|
|
522
522
|
type: Injectable,
|
|
523
523
|
args: [{ providedIn: 'root' }]
|
|
524
524
|
}], ctorParameters: function () { return []; } });
|
|
@@ -534,9 +534,9 @@ class WithCredentialsInterceptor {
|
|
|
534
534
|
return next.handle(cloned);
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
-
WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
538
|
-
WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
539
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
537
|
+
WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
538
|
+
WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor });
|
|
539
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
|
|
540
540
|
type: Injectable
|
|
541
541
|
}] });
|
|
542
542
|
|
|
@@ -585,15 +585,251 @@ class RedirectToLoginInterceptor {
|
|
|
585
585
|
}));
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
589
|
-
RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
590
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
588
|
+
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 });
|
|
589
|
+
RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToLoginInterceptor });
|
|
590
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
|
|
591
591
|
type: Injectable
|
|
592
592
|
}], ctorParameters: function () { return [{ type: i1.Router }, { type: undefined, decorators: [{
|
|
593
593
|
type: Inject,
|
|
594
594
|
args: [DDR_LOGIN_PATH]
|
|
595
595
|
}] }]; } });
|
|
596
596
|
|
|
597
|
+
const DDR_OAUTH2_CONFIG = new InjectionToken('DDR_OAUTH2_CONFIG');
|
|
598
|
+
class OAuth2Config {
|
|
599
|
+
constructor(clientId, redirectUri, authorizeUri, tokenUri) {
|
|
600
|
+
this.clientId = clientId;
|
|
601
|
+
this.redirectUri = redirectUri;
|
|
602
|
+
this.authorizeUri = authorizeUri;
|
|
603
|
+
this.tokenUri = tokenUri;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
class OAuth2Error extends Error {
|
|
608
|
+
constructor(error) {
|
|
609
|
+
super(error);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
OAuth2Error.CODE_NOT_FOUND = 'code_not_found';
|
|
613
|
+
OAuth2Error.ACCESS_DENIED = 'access_denied';
|
|
614
|
+
|
|
615
|
+
class OAuth2Service {
|
|
616
|
+
constructor(route, httpClient, config) {
|
|
617
|
+
this.route = route;
|
|
618
|
+
this.httpClient = httpClient;
|
|
619
|
+
this.config = config;
|
|
620
|
+
this.accessTokenString = null;
|
|
621
|
+
this.accessToken = null;
|
|
622
|
+
this.REFRESH_MARGIN_SECONDS = 60 * 10;
|
|
623
|
+
this.refreshTokenRequest$ = null;
|
|
624
|
+
}
|
|
625
|
+
redirectToLogin() {
|
|
626
|
+
const challenge = this.createChallenge();
|
|
627
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_CHALLENGE, challenge);
|
|
628
|
+
const params = new HttpParams()
|
|
629
|
+
.set('client_id', this.config.clientId)
|
|
630
|
+
.set('response_type', 'code')
|
|
631
|
+
.set('redirect_uri', this.config.redirectUri)
|
|
632
|
+
.set('code_challenge', challenge)
|
|
633
|
+
.set('code_challenge_method', 'plain');
|
|
634
|
+
window.location.href = this.config.authorizeUri + '?' + params.toString();
|
|
635
|
+
}
|
|
636
|
+
handleCode() {
|
|
637
|
+
if (this.route.snapshot.queryParamMap.has('error')) {
|
|
638
|
+
const error = this.route.snapshot.queryParamMap.get('error');
|
|
639
|
+
return throwError(() => new OAuth2Error(error ?? 'Unknown error'));
|
|
640
|
+
}
|
|
641
|
+
if (!this.route.snapshot.queryParamMap.has('code')) {
|
|
642
|
+
return throwError(() => new OAuth2Error(OAuth2Error.CODE_NOT_FOUND));
|
|
643
|
+
}
|
|
644
|
+
const code = TypeUtils.notNull(this.route.snapshot.queryParamMap.get('code'));
|
|
645
|
+
const params = new HttpParams()
|
|
646
|
+
.set('grant_type', 'authorization_code')
|
|
647
|
+
.set('code', code)
|
|
648
|
+
.set('redirect_uri', this.config.redirectUri)
|
|
649
|
+
.set('code_verifier', TypeUtils.notNull(localStorage.getItem(OAuth2Service.STORAGE_KEY_CHALLENGE)))
|
|
650
|
+
.set('client_id', this.config.clientId);
|
|
651
|
+
return this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)));
|
|
652
|
+
}
|
|
653
|
+
createChallenge() {
|
|
654
|
+
return StringUtils.createRandomString(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._~');
|
|
655
|
+
}
|
|
656
|
+
getRefreshToken() {
|
|
657
|
+
return localStorage.getItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
658
|
+
}
|
|
659
|
+
getAccessTokenString() {
|
|
660
|
+
return this.accessTokenString;
|
|
661
|
+
}
|
|
662
|
+
isAccessTokenExpired() {
|
|
663
|
+
return (null == this.accessToken
|
|
664
|
+
|| this.accessToken.exp * 1000 < Date.now());
|
|
665
|
+
}
|
|
666
|
+
isRefreshPossibleAndRequired(req = null) {
|
|
667
|
+
return ((null == req || !req.url.endsWith(this.config.tokenUri))
|
|
668
|
+
&& null != this.getRefreshToken()
|
|
669
|
+
&& (null == this.accessToken
|
|
670
|
+
|| (this.accessToken.exp - this.REFRESH_MARGIN_SECONDS) * 1000 < Date.now()));
|
|
671
|
+
}
|
|
672
|
+
performRefresh() {
|
|
673
|
+
if (null == this.refreshTokenRequest$) {
|
|
674
|
+
console.log('Performing token refesh');
|
|
675
|
+
const params = new HttpParams()
|
|
676
|
+
.set('grant_type', 'refresh_token')
|
|
677
|
+
.set('refresh_token', TypeUtils.notNull(this.getRefreshToken()))
|
|
678
|
+
.set('client_id', this.config.clientId);
|
|
679
|
+
this.refreshTokenRequest$ = this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)), catchError(error => {
|
|
680
|
+
this.accessTokenString = null;
|
|
681
|
+
this.accessToken = null;
|
|
682
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
683
|
+
this.refreshTokenRequest$ = null;
|
|
684
|
+
return throwError(error);
|
|
685
|
+
}), shareReplay(1));
|
|
686
|
+
}
|
|
687
|
+
return this.refreshTokenRequest$;
|
|
688
|
+
}
|
|
689
|
+
processTokenResponse(tokenResponse) {
|
|
690
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_CHALLENGE);
|
|
691
|
+
this.accessTokenString = tokenResponse.access_token;
|
|
692
|
+
this.accessToken = JSON.parse(atob(tokenResponse.access_token.split('.')[1]));
|
|
693
|
+
console.log('Access Token Expiry', new Date(this.accessToken.exp * 1000));
|
|
694
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN, tokenResponse.refresh_token);
|
|
695
|
+
return this.accessToken;
|
|
696
|
+
}
|
|
697
|
+
clear() {
|
|
698
|
+
this.accessToken = null;
|
|
699
|
+
this.accessTokenString = null;
|
|
700
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
701
|
+
localStorage.removeItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
702
|
+
}
|
|
703
|
+
setReturnUrl(url) {
|
|
704
|
+
localStorage.setItem(OAuth2Service.STORAGE_KEY_RETURN_URL, url);
|
|
705
|
+
}
|
|
706
|
+
getReturnUrl() {
|
|
707
|
+
return localStorage.getItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
OAuth2Service.STORAGE_KEY_CHALLENGE = 'ddr_oauth2_challenge';
|
|
711
|
+
OAuth2Service.STORAGE_KEY_REFRESH_TOKEN = 'ddr_oauth2_refresh_token';
|
|
712
|
+
OAuth2Service.STORAGE_KEY_RETURN_URL = 'ddr_oauth2_return_url';
|
|
713
|
+
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 });
|
|
714
|
+
OAuth2Service.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Service });
|
|
715
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Service, decorators: [{
|
|
716
|
+
type: Injectable
|
|
717
|
+
}], ctorParameters: function () { return [{ type: i1.ActivatedRoute }, { type: i2$1.HttpClient }, { type: OAuth2Config, decorators: [{
|
|
718
|
+
type: Inject,
|
|
719
|
+
args: [DDR_OAUTH2_CONFIG]
|
|
720
|
+
}] }]; } });
|
|
721
|
+
|
|
722
|
+
class OAuth2RefreshTokenInterceptor {
|
|
723
|
+
constructor(oAuth2Service) {
|
|
724
|
+
this.oAuth2Service = oAuth2Service;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* @override
|
|
728
|
+
*/
|
|
729
|
+
intercept(req, next) {
|
|
730
|
+
if (this.oAuth2Service.isRefreshPossibleAndRequired(req)) {
|
|
731
|
+
return this.oAuth2Service.performRefresh().pipe(switchMap(() => next.handle(req)));
|
|
732
|
+
}
|
|
733
|
+
return next.handle(req);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
OAuth2RefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
737
|
+
OAuth2RefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor });
|
|
738
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2RefreshTokenInterceptor, decorators: [{
|
|
739
|
+
type: Injectable
|
|
740
|
+
}], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
|
|
741
|
+
|
|
742
|
+
class RedirectToOAuth2LoginInterceptor {
|
|
743
|
+
constructor(oAuth2Service, router, oAuth2Config) {
|
|
744
|
+
this.oAuth2Service = oAuth2Service;
|
|
745
|
+
this.router = router;
|
|
746
|
+
this.oAuth2Config = oAuth2Config;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* @override
|
|
750
|
+
*/
|
|
751
|
+
intercept(req, next) {
|
|
752
|
+
return next.handle(req).pipe(catchError((err) => {
|
|
753
|
+
if (err instanceof HttpErrorResponse) {
|
|
754
|
+
if (err.status === 401) {
|
|
755
|
+
if (!window.location.href.startsWith(this.oAuth2Config.redirectUri)) {
|
|
756
|
+
this.oAuth2Service.setReturnUrl(this.router.routerState.snapshot.url);
|
|
757
|
+
this.oAuth2Service.redirectToLogin();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return throwError(err);
|
|
762
|
+
}));
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
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 });
|
|
766
|
+
RedirectToOAuth2LoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToOAuth2LoginInterceptor });
|
|
767
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, decorators: [{
|
|
768
|
+
type: Injectable
|
|
769
|
+
}], ctorParameters: function () { return [{ type: OAuth2Service }, { type: i1.Router }, { type: OAuth2Config, decorators: [{
|
|
770
|
+
type: Inject,
|
|
771
|
+
args: [DDR_OAUTH2_CONFIG]
|
|
772
|
+
}] }]; } });
|
|
773
|
+
|
|
774
|
+
class OAuth2AccessTokenInterceptor {
|
|
775
|
+
constructor(oAuth2Service) {
|
|
776
|
+
this.oAuth2Service = oAuth2Service;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @override
|
|
780
|
+
*/
|
|
781
|
+
intercept(req, next) {
|
|
782
|
+
const accessTokenString = this.oAuth2Service.getAccessTokenString();
|
|
783
|
+
if (null !== accessTokenString && !this.oAuth2Service.isAccessTokenExpired()) {
|
|
784
|
+
req = req.clone({
|
|
785
|
+
headers: req.headers.set('Authorization', 'Bearer ' + accessTokenString)
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
return next.handle(req);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
OAuth2AccessTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
792
|
+
OAuth2AccessTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor });
|
|
793
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2AccessTokenInterceptor, decorators: [{
|
|
794
|
+
type: Injectable
|
|
795
|
+
}], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
|
|
796
|
+
|
|
797
|
+
class OAuth2Module {
|
|
798
|
+
static forRoot(config) {
|
|
799
|
+
return {
|
|
800
|
+
ngModule: OAuth2Module,
|
|
801
|
+
providers: [
|
|
802
|
+
OAuth2Service,
|
|
803
|
+
{
|
|
804
|
+
provide: DDR_OAUTH2_CONFIG,
|
|
805
|
+
useValue: config
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
provide: HTTP_INTERCEPTORS,
|
|
809
|
+
useClass: OAuth2RefreshTokenInterceptor,
|
|
810
|
+
multi: true
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
provide: HTTP_INTERCEPTORS,
|
|
814
|
+
useClass: RedirectToOAuth2LoginInterceptor,
|
|
815
|
+
multi: true
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
provide: HTTP_INTERCEPTORS,
|
|
819
|
+
useClass: OAuth2AccessTokenInterceptor,
|
|
820
|
+
multi: true
|
|
821
|
+
}
|
|
822
|
+
],
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
OAuth2Module.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
827
|
+
OAuth2Module.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module });
|
|
828
|
+
OAuth2Module.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module });
|
|
829
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: OAuth2Module, decorators: [{
|
|
830
|
+
type: NgModule
|
|
831
|
+
}] });
|
|
832
|
+
|
|
597
833
|
class JwtService {
|
|
598
834
|
constructor(storagePrefix) {
|
|
599
835
|
this.storagePrefix = storagePrefix;
|
|
@@ -661,9 +897,9 @@ class JwtService {
|
|
|
661
897
|
return this.storagePrefix + '.jwt.refresh_token';
|
|
662
898
|
}
|
|
663
899
|
}
|
|
664
|
-
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
665
|
-
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
666
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
900
|
+
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 });
|
|
901
|
+
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
902
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtService, decorators: [{
|
|
667
903
|
type: Injectable,
|
|
668
904
|
args: [{
|
|
669
905
|
providedIn: 'root'
|
|
@@ -690,9 +926,9 @@ class JwtInterceptor {
|
|
|
690
926
|
return next.handle(req);
|
|
691
927
|
}
|
|
692
928
|
}
|
|
693
|
-
JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
694
|
-
JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
695
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
929
|
+
JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
930
|
+
JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor });
|
|
931
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtInterceptor, decorators: [{
|
|
696
932
|
type: Injectable
|
|
697
933
|
}], ctorParameters: function () { return [{ type: JwtService }]; } });
|
|
698
934
|
|
|
@@ -730,9 +966,9 @@ class JwtRefreshTokenInterceptor {
|
|
|
730
966
|
return this.refreshTokenRequest$;
|
|
731
967
|
}
|
|
732
968
|
}
|
|
733
|
-
JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
734
|
-
JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
735
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
969
|
+
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 });
|
|
970
|
+
JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtRefreshTokenInterceptor });
|
|
971
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
|
|
736
972
|
type: Injectable
|
|
737
973
|
}], ctorParameters: function () { return [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
|
|
738
974
|
type: Inject,
|
|
@@ -747,5 +983,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
747
983
|
* Generated bundle index. Do not edit.
|
|
748
984
|
*/
|
|
749
985
|
|
|
750
|
-
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 };
|
|
986
|
+
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 };
|
|
751
987
|
//# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map
|