@nestjs-kitchen/authz 2.0.3 → 2.0.5

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 (65) hide show
  1. package/dist/authz.provider.d.ts +3 -4
  2. package/dist/authz.provider.js +27 -43
  3. package/dist/constants.d.ts +6 -8
  4. package/dist/constants.js +13 -46
  5. package/dist/errors.d.ts +3 -5
  6. package/dist/errors.js +29 -44
  7. package/dist/index.d.ts +5 -21
  8. package/dist/index.js +16 -45
  9. package/dist/jwt/extract-jwt.d.ts +4 -7
  10. package/dist/jwt/extract-jwt.js +136 -152
  11. package/dist/jwt/index.d.ts +2 -16
  12. package/dist/jwt/index.js +7 -30
  13. package/dist/jwt/jwt-authz-als.middleware.d.ts +6 -16
  14. package/dist/jwt/jwt-authz-als.middleware.js +40 -60
  15. package/dist/jwt/jwt-authz.guard.d.ts +8 -21
  16. package/dist/jwt/jwt-authz.guard.js +126 -148
  17. package/dist/jwt/jwt-authz.interface.d.ts +16 -25
  18. package/dist/jwt/jwt-authz.interface.js +66 -114
  19. package/dist/jwt/jwt-authz.module.d.ts +19 -31
  20. package/dist/jwt/jwt-authz.module.js +240 -242
  21. package/dist/jwt/jwt-authz.service.d.ts +6 -17
  22. package/dist/jwt/jwt-authz.service.js +113 -144
  23. package/dist/jwt/jwt-authz.strategy.d.ts +5 -17
  24. package/dist/jwt/jwt-authz.strategy.js +127 -150
  25. package/dist/session/index.d.ts +1 -12
  26. package/dist/session/index.js +5 -27
  27. package/dist/session/session-authz-als.middleware.d.ts +5 -12
  28. package/dist/session/session-authz-als.middleware.js +95 -109
  29. package/dist/session/session-authz.guard.d.ts +6 -15
  30. package/dist/session/session-authz.guard.js +96 -116
  31. package/dist/session/session-authz.interface.d.ts +5 -12
  32. package/dist/session/session-authz.interface.js +18 -40
  33. package/dist/session/session-authz.module.d.ts +18 -26
  34. package/dist/session/session-authz.module.js +231 -237
  35. package/dist/session/session-authz.service.d.ts +5 -13
  36. package/dist/session/session-authz.service.js +66 -83
  37. package/dist/session/session-authz.strategy.d.ts +4 -12
  38. package/dist/session/session-authz.strategy.js +65 -78
  39. package/dist/user.decorator.d.ts +3 -6
  40. package/dist/user.decorator.js +25 -33
  41. package/dist/utils/cookie-parsers.d.ts +3 -6
  42. package/dist/utils/cookie-parsers.js +62 -63
  43. package/dist/utils/create-authz-decorator-factory.d.ts +3 -9
  44. package/dist/utils/create-authz-decorator-factory.js +29 -50
  45. package/dist/utils/create-set-cookie-fn.d.ts +3 -9
  46. package/dist/utils/create-set-cookie-fn.js +21 -42
  47. package/dist/utils/generics.d.ts +4 -6
  48. package/dist/utils/generics.js +31 -54
  49. package/dist/utils/get-allow-anonymous.d.ts +2 -9
  50. package/dist/utils/get-allow-anonymous.js +6 -27
  51. package/dist/utils/get-als-store.d.ts +2 -5
  52. package/dist/utils/get-als-store.js +10 -32
  53. package/dist/utils/get-context-authz-meta-params-list.d.ts +2 -9
  54. package/dist/utils/get-context-authz-meta-params-list.js +15 -33
  55. package/dist/utils/get-passport-property.d.ts +1 -3
  56. package/dist/utils/get-passport-property.js +7 -28
  57. package/dist/utils/index.d.ts +11 -16
  58. package/dist/utils/index.js +26 -40
  59. package/dist/utils/merge-dynamic-module-configs.d.ts +2 -5
  60. package/dist/utils/merge-dynamic-module-configs.js +13 -38
  61. package/dist/utils/msgpackrs.d.ts +2 -4
  62. package/dist/utils/msgpackrs.js +9 -32
  63. package/dist/utils/types.d.ts +23 -26
  64. package/dist/utils/types.js +2 -15
  65. package/package.json +4 -4
@@ -1,150 +1,119 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10
7
  };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
10
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var __decorateClass = (decorators, target, key, kind) => {
29
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
- if (decorator = decorators[i])
32
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
- if (kind && result) __defProp(target, key, result);
34
- return result;
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
35
13
  };
36
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
37
- var jwt_authz_service_exports = {};
38
- __export(jwt_authz_service_exports, {
39
- createJwtAuthzService: () => createJwtAuthzService
40
- });
41
- module.exports = __toCommonJS(jwt_authz_service_exports);
42
- var import_common = require("@nestjs/common");
43
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
44
- var import_constants = require("../constants");
45
- var import_errors = require("../errors");
46
- var import_utils = require("../utils");
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createJwtAuthzService = void 0;
19
+ const node_async_hooks_1 = require("node:async_hooks");
20
+ const common_1 = require("@nestjs/common");
21
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
22
+ const authz_provider_1 = require("../authz.provider");
23
+ const constants_1 = require("../constants");
24
+ const errors_1 = require("../errors");
25
+ const utils_1 = require("../utils");
47
26
  const createJwtAuthzService = ([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]) => {
48
- let JwtAuthzService = class {
49
- constructor(authzProvider, jwtAuthzOptions, als) {
50
- this.authzProvider = authzProvider;
51
- this.jwtAuthzOptions = jwtAuthzOptions;
52
- this.als = als;
53
- if (typeof this.authzProvider.createPayload !== "function") {
54
- throw new import_errors.AuthzError(
55
- `InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`
56
- );
57
- }
58
- if (!jwtAuthzOptions.jwt?.sign) {
59
- throw new import_errors.AuthzError(`InternalError: Missing JWT sign options.`);
60
- }
61
- if (this.jwtAuthzOptions.refresh && !this.jwtAuthzOptions.refresh.sign) {
62
- throw new import_errors.AuthzError(`InternalError: Missing Refresh sign options.`);
63
- }
64
- }
65
- /**
66
- * Creates a JWT token with a payload generated by AuthzProviderClass.createPayload(). Optionally, includes a refresh token if configured.
67
- *
68
- * @param user - User entity
69
- * @returns
70
- * - `token` : The generated JWT access token.
71
- * - `refresh` (optional): The generated refresh token, if enabled.
72
- */
73
- async logIn(user) {
74
- const payload = await this.authzProvider.createPayload(user);
75
- const token = import_jsonwebtoken.default.sign(payload, this.jwtAuthzOptions.jwt.secretOrPrivateKey, this.jwtAuthzOptions.jwt.sign);
76
- if (this.jwtAuthzOptions.refresh) {
77
- const refresh = import_jsonwebtoken.default.sign(
78
- {
79
- data: (0, import_utils.encodeMsgpackrString)(payload)
80
- },
81
- this.jwtAuthzOptions.refresh.secretOrPrivateKey,
82
- this.jwtAuthzOptions.refresh.sign
83
- );
84
- return {
85
- token,
86
- refresh
87
- };
88
- }
89
- return {
90
- token
91
- };
92
- }
93
- /**
94
- * Refreshes the JWT token for the provided user. If no user is provided, it attempts to retrieve the
95
- * current user and generate a new token.
96
- *
97
- * @param [user] - User entity
98
- * @returns
99
- */
100
- async refresh(user) {
101
- if (!this.jwtAuthzOptions.refresh) {
102
- console.warn(`'refresh' method can only be called when configured in module options.`);
103
- return void 0;
104
- }
105
- let userParams = user;
106
- if (!user) {
107
- const store = (0, import_utils.getAlsStore)(this.als);
108
- if (store.jwtVerifiedBy !== import_constants.JwtValidationType.REFRESH) {
109
- throw new import_errors.AuthzError(
110
- `InvocationError: Calling 'refresh' method without user parameter can only be called under @Refresh().`
111
- );
27
+ let JwtAuthzService = class JwtAuthzService {
28
+ constructor(authzProvider, jwtAuthzOptions, als) {
29
+ this.authzProvider = authzProvider;
30
+ this.jwtAuthzOptions = jwtAuthzOptions;
31
+ this.als = als;
32
+ if (typeof this.authzProvider.createPayload !== 'function') {
33
+ throw new errors_1.AuthzError(`InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`);
34
+ }
35
+ if (!jwtAuthzOptions.jwt?.sign) {
36
+ throw new errors_1.AuthzError(`InternalError: Missing JWT sign options.`);
37
+ }
38
+ if (this.jwtAuthzOptions.refresh && !this.jwtAuthzOptions.refresh.sign) {
39
+ throw new errors_1.AuthzError(`InternalError: Missing Refresh sign options.`);
40
+ }
41
+ }
42
+ /**
43
+ * Creates a JWT token with a payload generated by AuthzProviderClass.createPayload(). Optionally, includes a refresh token if configured.
44
+ *
45
+ * @param user - User entity
46
+ * @returns
47
+ * - `token` : The generated JWT access token.
48
+ * - `refresh` (optional): The generated refresh token, if enabled.
49
+ */
50
+ async logIn(user) {
51
+ const payload = (await this.authzProvider.createPayload(user));
52
+ const token = jsonwebtoken_1.default.sign(payload, this.jwtAuthzOptions.jwt.secretOrPrivateKey, this.jwtAuthzOptions.jwt.sign);
53
+ if (this.jwtAuthzOptions.refresh) {
54
+ const refresh = jsonwebtoken_1.default.sign({
55
+ data: (0, utils_1.encodeMsgpackrString)(payload)
56
+ }, this.jwtAuthzOptions.refresh.secretOrPrivateKey, this.jwtAuthzOptions.refresh.sign);
57
+ return {
58
+ token,
59
+ refresh
60
+ };
61
+ }
62
+ return {
63
+ token
64
+ };
65
+ }
66
+ /**
67
+ * Refreshes the JWT token for the provided user. If no user is provided, it attempts to retrieve the
68
+ * current user and generate a new token.
69
+ *
70
+ * @param [user] - User entity
71
+ * @returns
72
+ */
73
+ async refresh(user) {
74
+ if (!this.jwtAuthzOptions.refresh) {
75
+ console.warn(`'refresh' method can only be called when configured in module options.`);
76
+ return undefined;
77
+ }
78
+ let userParams = user;
79
+ if (!user) {
80
+ const store = (0, utils_1.getAlsStore)(this.als);
81
+ if (store.jwtVerifiedBy !== constants_1.JwtValidationType.REFRESH) {
82
+ throw new errors_1.AuthzError(`InvocationError: Calling 'refresh' method without user parameter can only be called under @Refresh().`);
83
+ }
84
+ userParams = store.user;
85
+ }
86
+ if (!userParams) {
87
+ throw new errors_1.AuthzError(`ParameterError: User data is undefined.`);
88
+ }
89
+ const payload = (await this.authzProvider.createPayload(userParams));
90
+ const token = jsonwebtoken_1.default.sign(payload, this.jwtAuthzOptions.jwt.secretOrPrivateKey, this.jwtAuthzOptions.jwt.sign);
91
+ return {
92
+ token
93
+ };
94
+ }
95
+ /**
96
+ * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
97
+ */
98
+ setCookie(...rest) {
99
+ const store = (0, utils_1.getAlsStore)(this.als);
100
+ store.setCookie(...rest);
101
+ }
102
+ /**
103
+ * Retrieves the current user associated with the request, if available.
104
+ */
105
+ getUser() {
106
+ const store = (0, utils_1.getAlsStore)(this.als);
107
+ const user = store.user;
108
+ return user;
112
109
  }
113
- userParams = store.user;
114
- }
115
- if (!userParams) {
116
- throw new import_errors.AuthzError(`ParameterError: User data is undefined.`);
117
- }
118
- const payload = await this.authzProvider.createPayload(userParams);
119
- const token = import_jsonwebtoken.default.sign(payload, this.jwtAuthzOptions.jwt.secretOrPrivateKey, this.jwtAuthzOptions.jwt.sign);
120
- return {
121
- token
122
- };
123
- }
124
- /**
125
- * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
126
- */
127
- setCookie(...rest) {
128
- const store = (0, import_utils.getAlsStore)(this.als);
129
- store.setCookie(...rest);
130
- }
131
- /**
132
- * Retrieves the current user associated with the request, if available.
133
- */
134
- getUser() {
135
- const store = (0, import_utils.getAlsStore)(this.als);
136
- const user = store.user;
137
- return user;
138
- }
139
- };
140
- JwtAuthzService = __decorateClass([
141
- __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
142
- __decorateParam(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
143
- __decorateParam(2, (0, import_common.Inject)(ALS_PROVIDER))
144
- ], JwtAuthzService);
145
- return (0, import_common.mixin)(JwtAuthzService);
110
+ };
111
+ JwtAuthzService = __decorate([
112
+ __param(0, (0, common_1.Inject)(AUTHZ_PROVIDER)),
113
+ __param(1, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
114
+ __param(2, (0, common_1.Inject)(ALS_PROVIDER)),
115
+ __metadata("design:paramtypes", [authz_provider_1.AuthzProviderClass, Object, node_async_hooks_1.AsyncLocalStorage])
116
+ ], JwtAuthzService);
117
+ return (0, common_1.mixin)(JwtAuthzService);
146
118
  };
147
- // Annotate the CommonJS export names for ESM import in node:
148
- 0 && (module.exports = {
149
- createJwtAuthzService
150
- });
119
+ exports.createJwtAuthzService = createJwtAuthzService;
@@ -1,28 +1,16 @@
1
- import * as _nestjs_common from '@nestjs/common';
2
1
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { Request } from 'express';
4
- import { AuthzProviderClass } from '../authz.provider.js';
5
- import { JwtAlsType } from './jwt-authz-als.middleware.js';
6
- import '../constants.js';
7
- import '../utils/types.js';
8
- import '@nestjs/common/interfaces';
9
- import './jwt-authz.interface.js';
10
- import 'crypto';
11
- import 'jsonwebtoken';
12
- import './extract-jwt.js';
13
- import 'cookie';
14
-
15
- declare const createJwtStrategy: ([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => _nestjs_common.Type<Omit<{
2
+ import type { Request } from 'express';
3
+ import { AuthzProviderClass } from '../authz.provider';
4
+ import type { JwtAlsType } from './jwt-authz-als.middleware';
5
+ export declare const createJwtStrategy: ([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => import("@nestjs/common").Type<Omit<{
16
6
  readonly authzProvider: AuthzProviderClass<unknown, unknown>;
17
7
  readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
18
8
  validate(req: Request): Promise<{}>;
19
9
  authenticate(req: Request, options?: any): any;
20
10
  }, "als" | "authzProvider">>;
21
- declare const createRefreshStrategy: ([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => _nestjs_common.Type<Omit<{
11
+ export declare const createRefreshStrategy: ([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => import("@nestjs/common").Type<Omit<{
22
12
  readonly authzProvider: AuthzProviderClass<unknown, unknown>;
23
13
  readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
24
14
  validate(req: Request): Promise<{}>;
25
15
  authenticate(req: Request, options?: any): any;
26
16
  }, "als" | "authzProvider">>;
27
-
28
- export { createJwtStrategy, createRefreshStrategy };
@@ -1,157 +1,134 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10
7
  };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
10
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var __decorateClass = (decorators, target, key, kind) => {
29
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
- if (decorator = decorators[i])
32
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
- if (kind && result) __defProp(target, key, result);
34
- return result;
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
35
13
  };
36
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
37
- var jwt_authz_strategy_exports = {};
38
- __export(jwt_authz_strategy_exports, {
39
- createJwtStrategy: () => createJwtStrategy,
40
- createRefreshStrategy: () => createRefreshStrategy
41
- });
42
- module.exports = __toCommonJS(jwt_authz_strategy_exports);
43
- var import_common = require("@nestjs/common");
44
- var import_passport = require("@nestjs/passport");
45
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
46
- var import_passport_custom = require("passport-custom");
47
- var import_constants = require("../constants");
48
- var import_errors = require("../errors");
49
- var import_utils = require("../utils");
50
- var import_extract_jwt = require("./extract-jwt");
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createRefreshStrategy = exports.createJwtStrategy = void 0;
19
+ const node_async_hooks_1 = require("node:async_hooks");
20
+ const common_1 = require("@nestjs/common");
21
+ const passport_1 = require("@nestjs/passport");
22
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
23
+ const passport_custom_1 = require("passport-custom");
24
+ const authz_provider_1 = require("../authz.provider");
25
+ const constants_1 = require("../constants");
26
+ const errors_1 = require("../errors");
27
+ const utils_1 = require("../utils");
28
+ const extract_jwt_1 = require("./extract-jwt");
51
29
  const createJwtStrategy = ([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
52
- let JwtStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_custom.Strategy, JWT_STRATEGY) {
53
- constructor(authzProvider, als) {
54
- super();
55
- this.authzProvider = authzProvider;
56
- this.als = als;
57
- if (typeof this.authzProvider.authenticate !== "function") {
58
- throw new import_errors.AuthzError(
59
- `InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`
60
- );
61
- }
62
- }
63
- async validate(req) {
64
- const store = (0, import_utils.getAlsStore)(this.als);
65
- const authOptions = store.authOptions;
66
- if (!authOptions.jwt.verify) {
67
- return [null, new import_errors.AuthzError(`InternalError: Refresh verify options must be implemented.`)];
68
- }
69
- const extractor = import_extract_jwt.ExtractJwt.fromExtractors(authOptions.jwt.jwtFromRequest);
70
- req[import_constants.PASSPORT_PROPERTY] = authOptions.passportProperty;
71
- const token = extractor(req);
72
- if (!token) {
73
- return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find token.")];
74
- }
75
- let user = void 0;
76
- try {
77
- const payload = import_jsonwebtoken.default.verify(token, authOptions.jwt.secretOrPublicKey, authOptions.jwt.verify);
78
- user = await this.authzProvider.authenticate(payload);
79
- } catch (error) {
80
- return [
81
- null,
82
- error instanceof Error ? new import_errors.AuthzVerificationError(`${error.name}: ${error.message}`, error) : new import_errors.AuthzVerificationError(`${error}`)
83
- ];
84
- }
85
- store.user = user;
86
- store.jwtVerifiedBy = import_constants.JwtValidationType.JWT;
87
- if (!user) {
88
- return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find user.")];
89
- }
90
- return user;
91
- }
92
- };
93
- JwtStrategy = __decorateClass([
94
- __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
95
- __decorateParam(1, (0, import_common.Inject)(ALS_PROVIDER))
96
- ], JwtStrategy);
97
- return (0, import_common.mixin)(JwtStrategy);
30
+ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, JWT_STRATEGY) {
31
+ constructor(authzProvider, als) {
32
+ super();
33
+ this.authzProvider = authzProvider;
34
+ this.als = als;
35
+ if (typeof this.authzProvider.authenticate !== 'function') {
36
+ throw new errors_1.AuthzError(`InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`);
37
+ }
38
+ }
39
+ async validate(req) {
40
+ const store = (0, utils_1.getAlsStore)(this.als);
41
+ const authOptions = store.authOptions;
42
+ if (!authOptions.jwt.verify) {
43
+ return [null, new errors_1.AuthzError(`InternalError: Refresh verify options must be implemented.`)];
44
+ }
45
+ const extractor = extract_jwt_1.ExtractJwt.fromExtractors(authOptions.jwt.jwtFromRequest);
46
+ req[constants_1.PASSPORT_PROPERTY] = authOptions.passportProperty;
47
+ const token = extractor(req);
48
+ if (!token) {
49
+ return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find token.')];
50
+ }
51
+ let user = undefined;
52
+ try {
53
+ const payload = jsonwebtoken_1.default.verify(token, authOptions.jwt.secretOrPublicKey, authOptions.jwt.verify);
54
+ user = await this.authzProvider.authenticate(payload, req);
55
+ }
56
+ catch (error) {
57
+ return [
58
+ null,
59
+ error instanceof Error
60
+ ? new errors_1.AuthzVerificationError(`${error.name}: ${error.message}`, error)
61
+ : new errors_1.AuthzVerificationError(`${error}`)
62
+ ];
63
+ }
64
+ store.user = user;
65
+ store.jwtVerifiedBy = constants_1.JwtValidationType.JWT;
66
+ if (!user) {
67
+ return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find user.')];
68
+ }
69
+ return user;
70
+ }
71
+ };
72
+ JwtStrategy = __decorate([
73
+ __param(0, (0, common_1.Inject)(AUTHZ_PROVIDER)),
74
+ __param(1, (0, common_1.Inject)(ALS_PROVIDER)),
75
+ __metadata("design:paramtypes", [authz_provider_1.AuthzProviderClass,
76
+ node_async_hooks_1.AsyncLocalStorage])
77
+ ], JwtStrategy);
78
+ return (0, common_1.mixin)(JwtStrategy);
98
79
  };
80
+ exports.createJwtStrategy = createJwtStrategy;
99
81
  const createRefreshStrategy = ([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
100
- let RefreshStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_custom.Strategy, JWT_REFRESH_STRATEGY) {
101
- constructor(authzProvider, als) {
102
- super();
103
- this.authzProvider = authzProvider;
104
- this.als = als;
105
- if (typeof this.authzProvider.authenticate !== "function") {
106
- throw new import_errors.AuthzError(
107
- `InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`
108
- );
109
- }
110
- }
111
- async validate(req) {
112
- const store = (0, import_utils.getAlsStore)(this.als);
113
- const authOptions = store.authOptions;
114
- if (!authOptions.refresh.verify) {
115
- return [null, new import_errors.AuthzError(`InternalError: Refresh verify options must be implemented.`)];
116
- }
117
- const extractor = import_extract_jwt.ExtractJwt.fromExtractors(authOptions.refresh.jwtFromRequest);
118
- req[import_constants.PASSPORT_PROPERTY] = authOptions.passportProperty;
119
- const token = extractor(req);
120
- if (!token) {
121
- return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find token.")];
122
- }
123
- let user = void 0;
124
- try {
125
- const payload = import_jsonwebtoken.default.verify(
126
- token,
127
- authOptions.refresh.secretOrPublicKey,
128
- authOptions.refresh.verify
129
- );
130
- const decodePayload = (0, import_utils.decodeMsgpackrString)(payload.data);
131
- user = await this.authzProvider.authenticate(decodePayload);
132
- } catch (error) {
133
- return [
134
- null,
135
- error instanceof Error ? new import_errors.AuthzVerificationError(`${error.name}: ${error.message}`, error) : new import_errors.AuthzVerificationError(`${error}`)
136
- ];
137
- }
138
- store.user = user;
139
- store.jwtVerifiedBy = import_constants.JwtValidationType.REFRESH;
140
- if (!user) {
141
- return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find user.")];
142
- }
143
- return user;
144
- }
145
- };
146
- RefreshStrategy = __decorateClass([
147
- (0, import_common.Injectable)(),
148
- __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
149
- __decorateParam(1, (0, import_common.Inject)(ALS_PROVIDER))
150
- ], RefreshStrategy);
151
- return (0, import_common.mixin)(RefreshStrategy);
82
+ let RefreshStrategy = class RefreshStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, JWT_REFRESH_STRATEGY) {
83
+ constructor(authzProvider, als) {
84
+ super();
85
+ this.authzProvider = authzProvider;
86
+ this.als = als;
87
+ if (typeof this.authzProvider.authenticate !== 'function') {
88
+ throw new errors_1.AuthzError(`InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`);
89
+ }
90
+ }
91
+ async validate(req) {
92
+ const store = (0, utils_1.getAlsStore)(this.als);
93
+ const authOptions = store.authOptions;
94
+ if (!authOptions.refresh.verify) {
95
+ return [null, new errors_1.AuthzError(`InternalError: Refresh verify options must be implemented.`)];
96
+ }
97
+ const extractor = extract_jwt_1.ExtractJwt.fromExtractors(authOptions.refresh.jwtFromRequest);
98
+ req[constants_1.PASSPORT_PROPERTY] = authOptions.passportProperty;
99
+ const token = extractor(req);
100
+ if (!token) {
101
+ return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find token.')];
102
+ }
103
+ let user = undefined;
104
+ try {
105
+ const payload = jsonwebtoken_1.default.verify(token, authOptions.refresh.secretOrPublicKey, authOptions.refresh.verify);
106
+ const decodePayload = (0, utils_1.decodeMsgpackrString)(payload.data);
107
+ user = await this.authzProvider.authenticate(decodePayload, req);
108
+ }
109
+ catch (error) {
110
+ return [
111
+ null,
112
+ error instanceof Error
113
+ ? new errors_1.AuthzVerificationError(`${error.name}: ${error.message}`, error)
114
+ : new errors_1.AuthzVerificationError(`${error}`)
115
+ ];
116
+ }
117
+ store.user = user;
118
+ store.jwtVerifiedBy = constants_1.JwtValidationType.REFRESH;
119
+ if (!user) {
120
+ return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find user.')];
121
+ }
122
+ return user;
123
+ }
124
+ };
125
+ RefreshStrategy = __decorate([
126
+ (0, common_1.Injectable)(),
127
+ __param(0, (0, common_1.Inject)(AUTHZ_PROVIDER)),
128
+ __param(1, (0, common_1.Inject)(ALS_PROVIDER)),
129
+ __metadata("design:paramtypes", [authz_provider_1.AuthzProviderClass,
130
+ node_async_hooks_1.AsyncLocalStorage])
131
+ ], RefreshStrategy);
132
+ return (0, common_1.mixin)(RefreshStrategy);
152
133
  };
153
- // Annotate the CommonJS export names for ESM import in node:
154
- 0 && (module.exports = {
155
- createJwtStrategy,
156
- createRefreshStrategy
157
- });
134
+ exports.createRefreshStrategy = createRefreshStrategy;
@@ -1,12 +1 @@
1
- export { cereateSessionAuthzModule } from './session-authz.module.js';
2
- import '@nestjs/core';
3
- import './session-authz.interface.js';
4
- import 'express-session';
5
- import '../utils/types.js';
6
- import '@nestjs/common';
7
- import '@nestjs/common/interfaces';
8
- import 'express';
9
- import '../authz.provider.js';
10
- import 'node:async_hooks';
11
- import '../errors.js';
12
- import './session-authz-als.middleware.js';
1
+ export { cereateSessionAuthzModule } from './session-authz.module';