@delon/auth 16.4.3 → 17.0.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.
Files changed (42) hide show
  1. package/esm2022/index.mjs +2 -20
  2. package/esm2022/src/auth.config.mjs +1 -2
  3. package/esm2022/src/index.mjs +7 -0
  4. package/esm2022/src/provide.mjs +42 -0
  5. package/esm2022/src/social/social.service.mjs +6 -6
  6. package/esm2022/src/store/cookie-storage.service.mjs +2 -3
  7. package/esm2022/src/store/index.mjs +6 -0
  8. package/esm2022/src/store/local-storage.service.mjs +2 -3
  9. package/esm2022/src/store/memory.service.mjs +1 -6
  10. package/esm2022/src/store/session-storage.service.mjs +2 -3
  11. package/esm2022/src/token/base.interceptor.mjs +26 -66
  12. package/esm2022/src/token/helper.mjs +8 -5
  13. package/esm2022/src/token/index.mjs +6 -0
  14. package/esm2022/src/token/jwt/index.mjs +5 -0
  15. package/esm2022/src/token/jwt/jwt.guard.mjs +8 -9
  16. package/esm2022/src/token/jwt/jwt.interceptor.mjs +20 -30
  17. package/esm2022/src/token/simple/index.mjs +4 -0
  18. package/esm2022/src/token/simple/simple.guard.mjs +8 -9
  19. package/esm2022/src/token/simple/simple.interceptor.mjs +38 -47
  20. package/esm2022/src/token/token.service.mjs +6 -6
  21. package/fesm2022/auth.mjs +187 -223
  22. package/fesm2022/auth.mjs.map +1 -1
  23. package/index.d.ts +1 -19
  24. package/package.json +2 -2
  25. package/src/index.d.ts +6 -0
  26. package/src/provide.d.ts +24 -0
  27. package/src/store/cookie-storage.service.d.ts +1 -2
  28. package/src/store/index.d.ts +5 -0
  29. package/src/store/local-storage.service.d.ts +1 -2
  30. package/src/store/memory.service.d.ts +0 -5
  31. package/src/store/session-storage.service.d.ts +1 -2
  32. package/src/token/base.interceptor.d.ts +3 -14
  33. package/src/token/helper.d.ts +1 -2
  34. package/src/token/index.d.ts +5 -0
  35. package/src/token/jwt/index.d.ts +4 -0
  36. package/src/token/jwt/jwt.guard.d.ts +1 -3
  37. package/src/token/jwt/jwt.interceptor.d.ts +2 -18
  38. package/src/token/simple/index.d.ts +3 -0
  39. package/src/token/simple/simple.guard.d.ts +1 -3
  40. package/src/token/simple/simple.interceptor.d.ts +2 -18
  41. package/esm2022/src/auth.module.mjs +0 -12
  42. package/src/auth.module.d.ts +0 -6
package/fesm2022/auth.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  import { DOCUMENT } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, Injectable, Inject, Optional, NgModule } from '@angular/core';
4
- import { Subject, BehaviorSubject, share, interval, map, filter, Observable } from 'rxjs';
3
+ import { InjectionToken, inject, Injectable, Inject, makeEnvironmentProviders } from '@angular/core';
4
+ import { Subject, BehaviorSubject, share, map, filter, interval, Observable } from 'rxjs';
5
5
  import * as i1 from '@delon/util/config';
6
6
  import { AlainConfigService } from '@delon/util/config';
7
7
  import * as i1$1 from '@angular/router';
8
8
  import { Router } from '@angular/router';
9
- import { HttpContextToken, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
9
+ import { HttpContextToken, HttpErrorResponse } from '@angular/common/http';
10
+ import { CookieService } from '@delon/util/browser';
10
11
 
11
12
  const AUTH_DEFAULT_CONFIG = {
12
13
  store_key: `_token`,
@@ -17,7 +18,6 @@ const AUTH_DEFAULT_CONFIG = {
17
18
  token_send_place: 'header',
18
19
  login_url: '/login',
19
20
  ignores: [/\/login/, /assets\//, /passport\//],
20
- executeOtherInterceptors: true,
21
21
  refreshTime: 3000,
22
22
  refreshOffset: 6000
23
23
  };
@@ -32,8 +32,7 @@ function DA_STORE_TOKEN_LOCAL_FACTORY() {
32
32
  * `localStorage` storage, **not lost after closing the browser**.
33
33
  *
34
34
  * ```ts
35
- * // global-config.module.ts
36
- * { provide: DA_STORE_TOKEN, useClass: LocalStorageStore }
35
+ * provideAuth(withJWT(), withLocalStorage())
37
36
  * ```
38
37
  */
39
38
  class LocalStorageStore {
@@ -128,15 +127,15 @@ class TokenService {
128
127
  ngOnDestroy() {
129
128
  this.cleanRefresh();
130
129
  }
131
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TokenService, deps: [{ token: i1.AlainConfigService }, { token: DA_STORE_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable }); }
132
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TokenService }); }
130
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: TokenService, deps: [{ token: i1.AlainConfigService }, { token: DA_STORE_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable }); }
131
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: TokenService }); }
133
132
  }
134
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TokenService, decorators: [{
133
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: TokenService, decorators: [{
135
134
  type: Injectable
136
- }], ctorParameters: function () { return [{ type: i1.AlainConfigService }, { type: undefined, decorators: [{
135
+ }], ctorParameters: () => [{ type: i1.AlainConfigService }, { type: undefined, decorators: [{
137
136
  type: Inject,
138
137
  args: [DA_STORE_TOKEN]
139
- }] }]; } });
138
+ }] }] });
140
139
 
141
140
  /* eslint-disable @typescript-eslint/no-explicit-any */
142
141
  const DA_SERVICE_TOKEN = new InjectionToken('DA_SERVICE_TOKEN', {
@@ -231,26 +230,21 @@ class SocialService {
231
230
  clearInterval(this._winTime);
232
231
  this._winTime = null;
233
232
  }
234
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SocialService, deps: [{ token: DA_SERVICE_TOKEN }, { token: DOCUMENT }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
235
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SocialService }); }
233
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: SocialService, deps: [{ token: DA_SERVICE_TOKEN }, { token: DOCUMENT }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
234
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: SocialService }); }
236
235
  }
237
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SocialService, decorators: [{
236
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: SocialService, decorators: [{
238
237
  type: Injectable
239
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
238
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
240
239
  type: Inject,
241
240
  args: [DA_SERVICE_TOKEN]
242
241
  }] }, { type: undefined, decorators: [{
243
242
  type: Inject,
244
243
  args: [DOCUMENT]
245
- }] }, { type: i1$1.Router }]; } });
244
+ }] }, { type: i1$1.Router }] });
246
245
 
247
246
  /**
248
247
  * 内存存储,关掉浏览器标签后**丢失**。
249
- *
250
- * ```ts
251
- * // global-config.module.ts
252
- * { provide: DA_STORE_TOKEN, useClass: MemoryStore }
253
- * ```
254
248
  */
255
249
  class MemoryStore {
256
250
  constructor() {
@@ -272,8 +266,7 @@ class MemoryStore {
272
266
  * `sessionStorage` storage, **lost after closing the browser**.
273
267
  *
274
268
  * ```ts
275
- * // global-config.module.ts
276
- * { provide: DA_STORE_TOKEN, useClass: SessionStorageStore }
269
+ * provideAuth(withJWT(), withSessionStorage())
277
270
  * ```
278
271
  */
279
272
  class SessionStorageStore {
@@ -293,8 +286,7 @@ class SessionStorageStore {
293
286
  * `cookie` storage
294
287
  *
295
288
  * ```ts
296
- * // global-config.module.ts
297
- * { provide: DA_STORE_TOKEN, useClass: CookieStorageStore, deps: [CookieService] }
289
+ * provideAuth(withJWT(), withCookie())
298
290
  * ```
299
291
  */
300
292
  class CookieStorageStore {
@@ -322,115 +314,6 @@ class CookieStorageStore {
322
314
  }
323
315
  }
324
316
 
325
- function CheckSimple(model) {
326
- return model != null && typeof model.token === 'string' && model.token.length > 0;
327
- }
328
- function CheckJwt(model, offset) {
329
- try {
330
- return model != null && !!model.token && !model.isExpired(offset);
331
- }
332
- catch (err) {
333
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
334
- console.warn(`${err.message}, jump to login_url`);
335
- }
336
- return false;
337
- }
338
- }
339
- function ToLogin(options, injector, url) {
340
- const router = injector.get(Router);
341
- injector.get(DA_SERVICE_TOKEN).referrer.url = url || router.url;
342
- if (options.token_invalid_redirect === true) {
343
- setTimeout(() => {
344
- if (/^https?:\/\//g.test(options.login_url)) {
345
- injector.get(DOCUMENT).location.href = options.login_url;
346
- }
347
- else {
348
- router.navigate([options.login_url]);
349
- }
350
- });
351
- }
352
- }
353
-
354
- /**
355
- * Whether to allow anonymous login
356
- *
357
- * 是否允许匿名登录
358
- *
359
- * @example
360
- * this.http.post(`login`, {
361
- * name: 'cipchk', pwd: '123456'
362
- * }, {
363
- * context: new HttpContext().set(ALLOW_ANONYMOUS, true)
364
- * })
365
- */
366
- const ALLOW_ANONYMOUS = new HttpContextToken(() => false);
367
-
368
- /* eslint-disable @typescript-eslint/no-explicit-any */
369
- class HttpAuthInterceptorHandler {
370
- constructor(next, interceptor) {
371
- this.next = next;
372
- this.interceptor = interceptor;
373
- }
374
- handle(req) {
375
- return this.interceptor.intercept(req, this.next);
376
- }
377
- }
378
- class BaseInterceptor {
379
- constructor(injector) {
380
- this.injector = injector;
381
- }
382
- intercept(req, next) {
383
- if (req.context.get(ALLOW_ANONYMOUS))
384
- return next.handle(req);
385
- const options = mergeConfig(this.injector.get(AlainConfigService));
386
- if (Array.isArray(options.ignores)) {
387
- for (const item of options.ignores) {
388
- if (item.test(req.url))
389
- return next.handle(req);
390
- }
391
- }
392
- if (this.isAuth(options)) {
393
- req = this.setReq(req, options);
394
- }
395
- else {
396
- ToLogin(options, this.injector);
397
- // Interrupt Http request, so need to generate a new Observable
398
- const err$ = new Observable((observer) => {
399
- let statusText = '';
400
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
401
- statusText = `来自 @delon/auth 的拦截,所请求URL未授权,若是登录API可加入 [url?_allow_anonymous=true] 来表示忽略校验,更多方法请参考: https://ng-alain.com/auth/getting-started#AlainAuthConfig\nThe interception from @delon/auth, the requested URL is not authorized. If the login API can add [url?_allow_anonymous=true] to ignore the check, please refer to: https://ng-alain.com/auth/getting-started#AlainAuthConfig`;
402
- }
403
- const res = new HttpErrorResponse({
404
- url: req.url,
405
- headers: req.headers,
406
- status: 401,
407
- statusText
408
- });
409
- observer.error(res);
410
- });
411
- if (options.executeOtherInterceptors) {
412
- const interceptors = this.injector.get(HTTP_INTERCEPTORS, []);
413
- const lastInterceptors = interceptors.slice(interceptors.indexOf(this) + 1);
414
- if (lastInterceptors.length > 0) {
415
- const chain = lastInterceptors.reduceRight((_next, _interceptor) => new HttpAuthInterceptorHandler(_next, _interceptor), {
416
- handle: (_) => err$
417
- });
418
- return chain.handle(req);
419
- }
420
- }
421
- return err$;
422
- }
423
- return next.handle(req);
424
- }
425
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseInterceptor, deps: [{ token: i0.Injector, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
426
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseInterceptor }); }
427
- }
428
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseInterceptor, decorators: [{
429
- type: Injectable
430
- }], ctorParameters: function () { return [{ type: i0.Injector, decorators: [{
431
- type: Optional
432
- }] }]; } });
433
-
434
317
  function urlBase64Decode(str) {
435
318
  let output = str.replace(/-/g, '+').replace(/_/g, '/');
436
319
  switch (output.length % 4) {
@@ -519,57 +402,59 @@ class JWTTokenModel {
519
402
  }
520
403
  }
521
404
 
522
- /**
523
- * JWT 拦截器
524
- *
525
- * ```
526
- * // app.module.ts
527
- * { provide: HTTP_INTERCEPTORS, useClass: JWTInterceptor, multi: true}
528
- * ```
529
- */
530
- class JWTInterceptor extends BaseInterceptor {
531
- isAuth(options) {
532
- this.model = this.injector.get(DA_SERVICE_TOKEN).get(JWTTokenModel);
533
- return CheckJwt(this.model, options.token_exp_offset);
405
+ function CheckSimple(model) {
406
+ return model != null && typeof model.token === 'string' && model.token.length > 0;
407
+ }
408
+ function CheckJwt(model, offset) {
409
+ try {
410
+ return model != null && !!model.token && !model.isExpired(offset);
534
411
  }
535
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
536
- setReq(req, _options) {
537
- return req.clone({
538
- setHeaders: {
539
- Authorization: `Bearer ${this.model.token}`
412
+ catch (err) {
413
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
414
+ console.warn(`${err.message}, jump to login_url`);
415
+ }
416
+ return false;
417
+ }
418
+ }
419
+ function ToLogin(options, url) {
420
+ const router = inject(Router);
421
+ const token = inject(DA_SERVICE_TOKEN);
422
+ const doc = inject(DOCUMENT);
423
+ token.referrer.url = url || router.url;
424
+ if (options.token_invalid_redirect === true) {
425
+ setTimeout(() => {
426
+ if (/^https?:\/\//g.test(options.login_url)) {
427
+ doc.location.href = options.login_url;
428
+ }
429
+ else {
430
+ router.navigate([options.login_url]);
540
431
  }
541
432
  });
542
433
  }
543
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: JWTInterceptor, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
544
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: JWTInterceptor }); }
545
434
  }
546
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: JWTInterceptor, decorators: [{
547
- type: Injectable
548
- }] });
549
435
 
550
436
  class AuthJWTGuardService {
551
- constructor(srv, injector) {
437
+ constructor(srv) {
552
438
  this.srv = srv;
553
- this.injector = injector;
554
439
  }
555
440
  process(url) {
556
441
  const cog = this.srv.options;
557
442
  const res = CheckJwt(this.srv.get(JWTTokenModel), cog.token_exp_offset);
558
443
  if (!res) {
559
- ToLogin(cog, this.injector, url);
444
+ ToLogin(cog, url);
560
445
  }
561
446
  return res;
562
447
  }
563
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthJWTGuardService, deps: [{ token: DA_SERVICE_TOKEN }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
564
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthJWTGuardService, providedIn: 'root' }); }
448
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthJWTGuardService, deps: [{ token: DA_SERVICE_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable }); }
449
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthJWTGuardService, providedIn: 'root' }); }
565
450
  }
566
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthJWTGuardService, decorators: [{
451
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthJWTGuardService, decorators: [{
567
452
  type: Injectable,
568
453
  args: [{ providedIn: 'root' }]
569
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
454
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
570
455
  type: Inject,
571
456
  args: [DA_SERVICE_TOKEN]
572
- }] }, { type: i0.Injector }]; } });
457
+ }] }] });
573
458
  /**
574
459
  * JWT 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
575
460
  *
@@ -607,77 +492,88 @@ const authJWTCanActivateChild = (_, state) => inject(AuthJWTGuardService).proces
607
492
  */
608
493
  const authJWTCanMatch = route => inject(AuthJWTGuardService).process(route.path);
609
494
 
610
- class SimpleTokenModel {
611
- }
612
-
613
495
  /**
614
- * Simple 拦截器
496
+ * Whether to allow anonymous login
615
497
  *
616
- * ```
617
- * // app.module.ts
618
- * { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true}
619
- * ```
498
+ * 是否允许匿名登录
499
+ *
500
+ * @example
501
+ * this.http.post(`login`, {
502
+ * name: 'cipchk', pwd: '123456'
503
+ * }, {
504
+ * context: new HttpContext().set(ALLOW_ANONYMOUS, true)
505
+ * })
620
506
  */
621
- class SimpleInterceptor extends BaseInterceptor {
622
- isAuth(_options) {
623
- this.model = this.injector.get(DA_SERVICE_TOKEN).get();
624
- return CheckSimple(this.model);
625
- }
626
- setReq(req, options) {
627
- const { token_send_template, token_send_key } = options;
628
- const token = token_send_template.replace(/\$\{([\w]+)\}/g, (_, g) => this.model[g]);
629
- switch (options.token_send_place) {
630
- case 'header':
631
- const obj = {};
632
- obj[token_send_key] = token;
633
- req = req.clone({
634
- setHeaders: obj
635
- });
636
- break;
637
- case 'body':
638
- const body = req.body || {};
639
- body[token_send_key] = token;
640
- req = req.clone({
641
- body
642
- });
643
- break;
644
- case 'url':
645
- req = req.clone({
646
- params: req.params.append(token_send_key, token)
647
- });
648
- break;
507
+ const ALLOW_ANONYMOUS = new HttpContextToken(() => false);
508
+
509
+ /* eslint-disable @typescript-eslint/no-explicit-any */
510
+ function isAnonymous(req, options) {
511
+ if (req.context.get(ALLOW_ANONYMOUS))
512
+ return true;
513
+ if (Array.isArray(options.ignores)) {
514
+ for (const item of options.ignores) {
515
+ if (item.test(req.url))
516
+ return true;
649
517
  }
650
- return req;
651
518
  }
652
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SimpleInterceptor, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
653
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SimpleInterceptor }); }
519
+ return false;
520
+ }
521
+ function throwErr(req, options) {
522
+ ToLogin(options);
523
+ // Interrupt Http request, so need to generate a new Observable
524
+ return new Observable((observer) => {
525
+ let statusText = '';
526
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
527
+ statusText = `来自 @delon/auth 的拦截,所请求URL未授权,若是登录API可加入 new HttpContext().set(ALLOW_ANONYMOUS, true) 来表示忽略校验,更多方法请参考: https://ng-alain.com/auth/getting-started#AlainAuthConfig\nThe interception from @delon/auth, the requested URL is not authorized. If the login API can add new HttpContext().set(ALLOW_ANONYMOUS, true) to ignore the check, please refer to: https://ng-alain.com/auth/getting-started#AlainAuthConfig`;
528
+ }
529
+ const res = new HttpErrorResponse({
530
+ url: req.url,
531
+ headers: req.headers,
532
+ status: 401,
533
+ statusText
534
+ });
535
+ observer.error(res);
536
+ });
654
537
  }
655
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SimpleInterceptor, decorators: [{
656
- type: Injectable
657
- }] });
538
+
539
+ function newReq$1(req, model) {
540
+ return req.clone({
541
+ setHeaders: {
542
+ Authorization: `Bearer ${model.token}`
543
+ }
544
+ });
545
+ }
546
+ const authJWTInterceptor = (req, next) => {
547
+ const options = mergeConfig(inject(AlainConfigService));
548
+ if (isAnonymous(req, options))
549
+ return next(req);
550
+ const model = inject(DA_SERVICE_TOKEN).get(JWTTokenModel);
551
+ if (CheckJwt(model, options.token_exp_offset))
552
+ return next(newReq$1(req, model));
553
+ return throwErr(req, options);
554
+ };
658
555
 
659
556
  class AuthSimpleGuardService {
660
- constructor(srv, injector) {
557
+ constructor(srv) {
661
558
  this.srv = srv;
662
- this.injector = injector;
663
559
  }
664
560
  process(url) {
665
561
  const res = CheckSimple(this.srv.get());
666
562
  if (!res) {
667
- ToLogin(this.srv.options, this.injector, url);
563
+ ToLogin(this.srv.options, url);
668
564
  }
669
565
  return res;
670
566
  }
671
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthSimpleGuardService, deps: [{ token: DA_SERVICE_TOKEN }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
672
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthSimpleGuardService, providedIn: 'root' }); }
567
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthSimpleGuardService, deps: [{ token: DA_SERVICE_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable }); }
568
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthSimpleGuardService, providedIn: 'root' }); }
673
569
  }
674
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AuthSimpleGuardService, decorators: [{
570
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: AuthSimpleGuardService, decorators: [{
675
571
  type: Injectable,
676
572
  args: [{ providedIn: 'root' }]
677
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
573
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
678
574
  type: Inject,
679
575
  args: [DA_SERVICE_TOKEN]
680
- }] }, { type: i0.Injector }]; } });
576
+ }] }] });
681
577
  /**
682
578
  * Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
683
579
  *
@@ -715,19 +611,87 @@ const authSimpleCanActivateChild = (_, state) => inject(AuthSimpleGuardService).
715
611
  */
716
612
  const authSimpleCanMatch = route => inject(AuthSimpleGuardService).process(route.path);
717
613
 
718
- class DelonAuthModule {
719
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DelonAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
720
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: DelonAuthModule }); }
721
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DelonAuthModule }); }
614
+ function newReq(req, model, options) {
615
+ const { token_send_template, token_send_key } = options;
616
+ const token = token_send_template.replace(/\$\{([\w]+)\}/g, (_, g) => model[g]);
617
+ switch (options.token_send_place) {
618
+ case 'header':
619
+ const obj = {};
620
+ obj[token_send_key] = token;
621
+ req = req.clone({
622
+ setHeaders: obj
623
+ });
624
+ break;
625
+ case 'body':
626
+ const body = req.body || {};
627
+ body[token_send_key] = token;
628
+ req = req.clone({
629
+ body
630
+ });
631
+ break;
632
+ case 'url':
633
+ req = req.clone({
634
+ params: req.params.append(token_send_key, token)
635
+ });
636
+ break;
637
+ }
638
+ return req;
639
+ }
640
+ const authSimpleInterceptor = (req, next) => {
641
+ const options = mergeConfig(inject(AlainConfigService));
642
+ if (isAnonymous(req, options))
643
+ return next(req);
644
+ const model = inject(DA_SERVICE_TOKEN).get();
645
+ if (CheckSimple(model))
646
+ return next(newReq(req, model, options));
647
+ return throwErr(req, options);
648
+ };
649
+
650
+ class SimpleTokenModel {
651
+ }
652
+
653
+ var AuthFeatureKind;
654
+ (function (AuthFeatureKind) {
655
+ AuthFeatureKind[AuthFeatureKind["Store"] = 0] = "Store";
656
+ })(AuthFeatureKind || (AuthFeatureKind = {}));
657
+ function makeAuthFeature(kind, providers) {
658
+ return {
659
+ ɵkind: kind,
660
+ ɵproviders: providers
661
+ };
662
+ }
663
+ /**
664
+ * Configures authentication process service to be available for injection.
665
+ *
666
+ * @see {@link withCookie}
667
+ * @see {@link withLocalStorage}
668
+ * @see {@link withSessionStorage}
669
+ */
670
+ function provideAuth(store) {
671
+ return makeEnvironmentProviders([(store ?? withLocalStorage()).ɵproviders]);
672
+ }
673
+ /** `cookie` storage */
674
+ function withCookie() {
675
+ return makeAuthFeature(AuthFeatureKind.Store, [
676
+ { provide: DA_STORE_TOKEN, useClass: CookieStorageStore, deps: [CookieService] }
677
+ ]);
678
+ }
679
+ /** `localStorage` storage, **not lost after closing the browser**. */
680
+ function withLocalStorage() {
681
+ return makeAuthFeature(AuthFeatureKind.Store, [{ provide: DA_STORE_TOKEN, useClass: LocalStorageStore }]);
682
+ }
683
+ /** `sessionStorage` storage, **lost after closing the browser**. */
684
+ function withSessionStorage() {
685
+ return makeAuthFeature(AuthFeatureKind.Store, [{ provide: DA_STORE_TOKEN, useClass: SessionStorageStore }]);
686
+ }
687
+ /** Memory storage, **lost after closing the browser tab**. */
688
+ function withMemoryStorage() {
689
+ return makeAuthFeature(AuthFeatureKind.Store, [{ provide: DA_STORE_TOKEN, useClass: MemoryStore }]);
722
690
  }
723
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DelonAuthModule, decorators: [{
724
- type: NgModule,
725
- args: [{}]
726
- }] });
727
691
 
728
692
  /**
729
693
  * Generated bundle index. Do not edit.
730
694
  */
731
695
 
732
- export { ALLOW_ANONYMOUS, AUTH_DEFAULT_CONFIG, AuthJWTGuardService, AuthSimpleGuardService, BaseInterceptor, CookieStorageStore, DA_SERVICE_TOKEN, DA_SERVICE_TOKEN_FACTORY, DA_STORE_TOKEN, DA_STORE_TOKEN_LOCAL_FACTORY, DelonAuthModule, JWTInterceptor, JWTTokenModel, LocalStorageStore, MemoryStore, SessionStorageStore, SimpleInterceptor, SimpleTokenModel, SocialService, TokenService, authJWTCanActivate, authJWTCanActivateChild, authJWTCanMatch, authSimpleCanActivate, authSimpleCanActivateChild, authSimpleCanMatch, mergeConfig, urlBase64Decode };
696
+ export { ALLOW_ANONYMOUS, AUTH_DEFAULT_CONFIG, AuthFeatureKind, AuthJWTGuardService, AuthSimpleGuardService, CookieStorageStore, DA_SERVICE_TOKEN, DA_SERVICE_TOKEN_FACTORY, DA_STORE_TOKEN, DA_STORE_TOKEN_LOCAL_FACTORY, JWTTokenModel, LocalStorageStore, MemoryStore, SessionStorageStore, SimpleTokenModel, SocialService, TokenService, authJWTCanActivate, authJWTCanActivateChild, authJWTCanMatch, authJWTInterceptor, authSimpleCanActivate, authSimpleCanActivateChild, authSimpleCanMatch, authSimpleInterceptor, isAnonymous, mergeConfig, provideAuth, throwErr, urlBase64Decode, withCookie, withLocalStorage, withMemoryStorage, withSessionStorage };
733
697
  //# sourceMappingURL=auth.mjs.map