@dontdrinkandroot/ngx-extensions 0.1.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/{esm2015/dontdrinkandroot-ngx-extensions.js → esm2020/dontdrinkandroot-ngx-extensions.mjs} +0 -0
- package/esm2020/public-api.mjs +27 -0
- package/{esm2015/src/cookie/cookie.service.js → esm2020/src/cookie/cookie.service.mjs} +4 -4
- package/{esm2015/src/ddr-extensions.module.js → esm2020/src/ddr-extensions.module.mjs} +6 -6
- package/{esm2015/src/http/redirect-to-login-interceptor.service.js → esm2020/src/http/redirect-to-login-interceptor.service.mjs} +4 -4
- package/{esm2015/src/http/url-info.js → esm2020/src/http/url-info.mjs} +0 -0
- package/{esm2015/src/http/with-credentials-interceptor.service.js → esm2020/src/http/with-credentials-interceptor.service.mjs} +4 -4
- package/{esm2015/src/image/lazy-image.directive.js → esm2020/src/image/lazy-image.directive.mjs} +4 -4
- package/{esm2015/src/jwt/jwt-interceptor.service.js → esm2020/src/jwt/jwt-interceptor.service.mjs} +4 -4
- package/{esm2015/src/jwt/jwt-refresh-token-interceptor.service.js → esm2020/src/jwt/jwt-refresh-token-interceptor.service.mjs} +4 -4
- package/{esm2015/src/jwt/jwt-token-response.js → esm2020/src/jwt/jwt-token-response.mjs} +0 -0
- package/{esm2015/src/jwt/jwt.service.js → esm2020/src/jwt/jwt.service.mjs} +4 -4
- package/{esm2015/src/methoddecorator/debounce.js → esm2020/src/methoddecorator/debounce.mjs} +0 -0
- package/{esm2015/src/methoddecorator/limit.js → esm2020/src/methoddecorator/limit.mjs} +0 -0
- 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/{esm2015/src/scroll/bottom-hit.directive.js → esm2020/src/scroll/bottom-hit.directive.mjs} +4 -4
- package/{esm2015/src/scroll/scroll.service.js → esm2020/src/scroll/scroll.service.mjs} +4 -4
- package/esm2020/src/util/collection-utils.mjs +27 -0
- package/{esm2015/src/util/number-utils.js → esm2020/src/util/number-utils.mjs} +0 -0
- package/{esm2015/src/util/object-utils.js → esm2020/src/util/object-utils.mjs} +0 -0
- package/{esm2015/src/util/string-utils.js → esm2020/src/util/string-utils.mjs} +0 -0
- package/esm2020/src/util/type-utils.mjs +9 -0
- package/{esm2015/src/visibility/visibility.service.js → esm2020/src/visibility/visibility.service.mjs} +4 -4
- package/fesm2015/dontdrinkandroot-ngx-extensions.mjs +1000 -0
- package/fesm2015/dontdrinkandroot-ngx-extensions.mjs.map +1 -0
- package/{fesm2015/dontdrinkandroot-ngx-extensions.js → fesm2020/dontdrinkandroot-ngx-extensions.mjs} +284 -40
- package/fesm2020/dontdrinkandroot-ngx-extensions.mjs.map +1 -0
- package/{dontdrinkandroot-ngx-extensions.d.ts → index.d.ts} +0 -0
- package/package.json +22 -9
- package/public-api.d.ts +4 -0
- package/src/image/lazy-image.directive.d.ts +1 -1
- 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
- package/src/scroll/bottom-hit.directive.d.ts +1 -1
- package/src/util/type-utils.d.ts +3 -0
- package/bundles/dontdrinkandroot-ngx-extensions.umd.js +0 -1178
- package/bundles/dontdrinkandroot-ngx-extensions.umd.js.map +0 -1
- package/esm2015/public-api.js +0 -23
- package/esm2015/src/util/collection-utils.js +0 -28
- package/fesm2015/dontdrinkandroot-ngx-extensions.js.map +0 -1
package/{fesm2015/dontdrinkandroot-ngx-extensions.js → fesm2020/dontdrinkandroot-ngx-extensions.mjs}
RENAMED
|
@@ -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: "
|
|
175
|
-
LazyImageDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
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: "
|
|
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: "
|
|
244
|
-
BottomHitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
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: "
|
|
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: "
|
|
274
|
-
DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
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: "
|
|
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
|
-
]
|
|
283
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
282
|
+
] });
|
|
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: "
|
|
423
|
-
CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
424
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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'
|
|
@@ -455,11 +455,10 @@ class CollectionUtils {
|
|
|
455
455
|
* Maps an array into a Map by a specified property and aggregates them into an array.
|
|
456
456
|
*/
|
|
457
457
|
static mapArrayByProperty(entries, property) {
|
|
458
|
-
var _a;
|
|
459
458
|
const map = new Map();
|
|
460
459
|
for (const entry of entries) {
|
|
461
460
|
const value = ObjectUtils.getProperty(entry, property);
|
|
462
|
-
const existingEntries =
|
|
461
|
+
const existingEntries = map.get(value) ?? [];
|
|
463
462
|
existingEntries.push(entry);
|
|
464
463
|
map.set(value, existingEntries);
|
|
465
464
|
}
|
|
@@ -467,6 +466,15 @@ class CollectionUtils {
|
|
|
467
466
|
}
|
|
468
467
|
}
|
|
469
468
|
|
|
469
|
+
class TypeUtils {
|
|
470
|
+
static notNull(value, message = 'Value must not be null') {
|
|
471
|
+
if (null == value) {
|
|
472
|
+
throw new Error(message);
|
|
473
|
+
}
|
|
474
|
+
return value;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
470
478
|
class ScrollService {
|
|
471
479
|
constructor(router, viewportScroller) {
|
|
472
480
|
this.router = router;
|
|
@@ -491,9 +499,9 @@ class ScrollService {
|
|
|
491
499
|
}
|
|
492
500
|
}
|
|
493
501
|
}
|
|
494
|
-
ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
495
|
-
ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
496
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
497
505
|
type: Injectable,
|
|
498
506
|
args: [{
|
|
499
507
|
providedIn: 'root'
|
|
@@ -508,9 +516,9 @@ class VisibilityService {
|
|
|
508
516
|
return this.visibility$;
|
|
509
517
|
}
|
|
510
518
|
}
|
|
511
|
-
VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
512
|
-
VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
513
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
514
522
|
type: Injectable,
|
|
515
523
|
args: [{ providedIn: 'root' }]
|
|
516
524
|
}], ctorParameters: function () { return []; } });
|
|
@@ -526,9 +534,9 @@ class WithCredentialsInterceptor {
|
|
|
526
534
|
return next.handle(cloned);
|
|
527
535
|
}
|
|
528
536
|
}
|
|
529
|
-
WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
530
|
-
WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
531
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
532
540
|
type: Injectable
|
|
533
541
|
}] });
|
|
534
542
|
|
|
@@ -577,15 +585,251 @@ class RedirectToLoginInterceptor {
|
|
|
577
585
|
}));
|
|
578
586
|
}
|
|
579
587
|
}
|
|
580
|
-
RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
581
|
-
RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
582
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
583
591
|
type: Injectable
|
|
584
592
|
}], ctorParameters: function () { return [{ type: i1.Router }, { type: undefined, decorators: [{
|
|
585
593
|
type: Inject,
|
|
586
594
|
args: [DDR_LOGIN_PATH]
|
|
587
595
|
}] }]; } });
|
|
588
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
|
+
|
|
589
833
|
class JwtService {
|
|
590
834
|
constructor(storagePrefix) {
|
|
591
835
|
this.storagePrefix = storagePrefix;
|
|
@@ -653,9 +897,9 @@ class JwtService {
|
|
|
653
897
|
return this.storagePrefix + '.jwt.refresh_token';
|
|
654
898
|
}
|
|
655
899
|
}
|
|
656
|
-
JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
657
|
-
JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
658
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
659
903
|
type: Injectable,
|
|
660
904
|
args: [{
|
|
661
905
|
providedIn: 'root'
|
|
@@ -682,9 +926,9 @@ class JwtInterceptor {
|
|
|
682
926
|
return next.handle(req);
|
|
683
927
|
}
|
|
684
928
|
}
|
|
685
|
-
JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
686
|
-
JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
687
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
688
932
|
type: Injectable
|
|
689
933
|
}], ctorParameters: function () { return [{ type: JwtService }]; } });
|
|
690
934
|
|
|
@@ -722,9 +966,9 @@ class JwtRefreshTokenInterceptor {
|
|
|
722
966
|
return this.refreshTokenRequest$;
|
|
723
967
|
}
|
|
724
968
|
}
|
|
725
|
-
JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
726
|
-
JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
727
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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: [{
|
|
728
972
|
type: Injectable
|
|
729
973
|
}], ctorParameters: function () { return [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
|
|
730
974
|
type: Inject,
|
|
@@ -739,5 +983,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
739
983
|
* Generated bundle index. Do not edit.
|
|
740
984
|
*/
|
|
741
985
|
|
|
742
|
-
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, UrlInfo, VisibilityService, WithCredentialsInterceptor };
|
|
743
|
-
//# sourceMappingURL=dontdrinkandroot-ngx-extensions.
|
|
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 };
|
|
987
|
+
//# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map
|