@nestjs-kitchen/authz 2.0.2 → 2.0.4

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 +1 -3
  2. package/dist/authz.provider.js +29 -48
  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 +35 -60
  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 +138 -158
  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 +44 -81
  15. package/dist/jwt/jwt-authz.guard.d.ts +8 -21
  16. package/dist/jwt/jwt-authz.guard.js +130 -175
  17. package/dist/jwt/jwt-authz.interface.d.ts +16 -25
  18. package/dist/jwt/jwt-authz.interface.js +69 -92
  19. package/dist/jwt/jwt-authz.module.d.ts +19 -31
  20. package/dist/jwt/jwt-authz.module.js +250 -299
  21. package/dist/jwt/jwt-authz.service.d.ts +6 -17
  22. package/dist/jwt/jwt-authz.service.js +116 -162
  23. package/dist/jwt/jwt-authz.strategy.d.ts +5 -17
  24. package/dist/jwt/jwt-authz.strategy.js +132 -192
  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 +98 -130
  29. package/dist/session/session-authz.guard.d.ts +6 -15
  30. package/dist/session/session-authz.guard.js +98 -135
  31. package/dist/session/session-authz.interface.d.ts +5 -12
  32. package/dist/session/session-authz.interface.js +19 -42
  33. package/dist/session/session-authz.module.d.ts +18 -26
  34. package/dist/session/session-authz.module.js +241 -290
  35. package/dist/session/session-authz.service.d.ts +5 -13
  36. package/dist/session/session-authz.service.js +69 -105
  37. package/dist/session/session-authz.strategy.d.ts +4 -12
  38. package/dist/session/session-authz.strategy.js +68 -105
  39. package/dist/user.decorator.d.ts +3 -6
  40. package/dist/user.decorator.js +26 -35
  41. package/dist/utils/cookie-parsers.d.ts +3 -6
  42. package/dist/utils/cookie-parsers.js +66 -74
  43. package/dist/utils/create-authz-decorator-factory.d.ts +3 -9
  44. package/dist/utils/create-authz-decorator-factory.js +32 -54
  45. package/dist/utils/create-set-cookie-fn.d.ts +3 -9
  46. package/dist/utils/create-set-cookie-fn.js +23 -45
  47. package/dist/utils/generics.d.ts +4 -6
  48. package/dist/utils/generics.js +37 -63
  49. package/dist/utils/get-allow-anonymous.d.ts +2 -9
  50. package/dist/utils/get-allow-anonymous.js +7 -29
  51. package/dist/utils/get-als-store.d.ts +2 -5
  52. package/dist/utils/get-als-store.js +11 -34
  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 +16 -35
  55. package/dist/utils/get-passport-property.d.ts +1 -3
  56. package/dist/utils/get-passport-property.js +8 -30
  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 +14 -49
  61. package/dist/utils/msgpackrs.d.ts +2 -4
  62. package/dist/utils/msgpackrs.js +11 -35
  63. package/dist/utils/types.d.ts +23 -26
  64. package/dist/utils/types.js +2 -15
  65. package/package.json +7 -7
@@ -1,179 +1,134 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- var jwt_authz_guard_exports = {};
22
- __export(jwt_authz_guard_exports, {
23
- createJwtAuthzGuard: () => createJwtAuthzGuard,
24
- createJwtRefreshAuthzGuard: () => createJwtRefreshAuthzGuard
25
- });
26
- module.exports = __toCommonJS(jwt_authz_guard_exports);
27
- var import_common = require("@nestjs/common");
28
- var import_core = require("@nestjs/core");
29
- var import_passport = require("@nestjs/passport");
30
- var import_authz = require("../authz.provider");
31
- var import_errors = require("../errors");
32
- var import_utils = require("../utils");
33
- function _ts_decorate(decorators, target, key, desc) {
34
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
- 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;
37
- return c > 3 && r && Object.defineProperty(target, key, r), r;
38
- }
39
- __name(_ts_decorate, "_ts_decorate");
40
- function _ts_metadata(k, v) {
41
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
42
- }
43
- __name(_ts_metadata, "_ts_metadata");
44
- function _ts_param(paramIndex, decorator) {
45
- return function(target, key) {
46
- decorator(target, key, paramIndex);
47
- };
48
- }
49
- __name(_ts_param, "_ts_param");
50
- const createJwtAuthzGuard = /* @__PURE__ */ __name(([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]) => {
51
- var _a;
52
- let JwtAuthzGuard = (_a = class extends (0, import_passport.AuthGuard)(JWT_STRATEGY) {
53
- constructor(reflector, authzProvider, jwtAuthzOptions, als) {
54
- super();
55
- __publicField(this, "reflector");
56
- __publicField(this, "authzProvider");
57
- __publicField(this, "jwtAuthzOptions");
58
- __publicField(this, "als");
59
- this.reflector = reflector, this.authzProvider = authzProvider, this.jwtAuthzOptions = jwtAuthzOptions, this.als = als;
60
- }
61
- getAuthenticateOptions() {
62
- return {
63
- property: this.jwtAuthzOptions.passportProperty,
64
- session: false
65
- };
66
- }
67
- /**
68
- *
69
- * recives err, user, info from JwtStrategy.validate
70
- *
71
- * will return request.user=null if allowAnonymous=true
72
- *
73
- * @param _err will always be null
74
- * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
75
- * @param info AuthzError or undefined
76
- * @returns
77
- */
78
- handleRequest(_err, user, info) {
79
- const store = (0, import_utils.getAlsStore)(this.als);
80
- if (info) {
81
- if (store.allowAnonymous && info.name === import_errors.AuthzAnonymousError.name) {
82
- return user;
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createJwtRefreshAuthzGuard = exports.createJwtAuthzGuard = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const passport_1 = require("@nestjs/passport");
19
+ const authz_provider_1 = require("../authz.provider");
20
+ const errors_1 = require("../errors");
21
+ const utils_1 = require("../utils");
22
+ const createJwtAuthzGuard = ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]) => {
23
+ let JwtAuthzGuard = class JwtAuthzGuard extends (0, passport_1.AuthGuard)(JWT_STRATEGY) {
24
+ constructor(reflector, authzProvider, jwtAuthzOptions, als) {
25
+ super();
26
+ this.reflector = reflector;
27
+ this.authzProvider = authzProvider;
28
+ this.jwtAuthzOptions = jwtAuthzOptions;
29
+ this.als = als;
30
+ }
31
+ getAuthenticateOptions() {
32
+ return {
33
+ property: this.jwtAuthzOptions.passportProperty,
34
+ session: false
35
+ };
36
+ }
37
+ /**
38
+ *
39
+ * recives err, user, info from JwtStrategy.validate
40
+ *
41
+ * will return request.user=null if allowAnonymous=true
42
+ *
43
+ * @param _err will always be null
44
+ * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
45
+ * @param info AuthzError or undefined
46
+ * @returns
47
+ */
48
+ handleRequest(_err, user, info) {
49
+ const store = (0, utils_1.getAlsStore)(this.als);
50
+ if (info) {
51
+ if (store.allowAnonymous && info.name === errors_1.AuthzAnonymousError.name) {
52
+ // user is null.
53
+ return user;
54
+ }
55
+ store.guardResult = false;
56
+ throw info;
57
+ }
58
+ return user;
59
+ }
60
+ async canActivate(context) {
61
+ const store = (0, utils_1.getAlsStore)(this.als);
62
+ if ((0, utils_1.isNotFalsy)(store.guardResult)) {
63
+ return store.guardResult;
64
+ }
65
+ const jwtRefreshMetaCollection = (0, utils_1.normalizedArray)(this.reflector.getAll(JWT_REFRESH_META_KEY, [context.getClass(), context.getHandler()]));
66
+ // authz decorator will be ignore when use refresh decorator together.
67
+ if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
68
+ store.guardResult = true;
69
+ return true;
70
+ }
71
+ const paramsList = (0, utils_1.normalizedArray)(this.reflector.getAll(JWT_META_KEY, [context.getClass(), context.getHandler()]));
72
+ // bypass if last meta is public
73
+ if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
74
+ store.guardResult = true;
75
+ return true;
76
+ }
77
+ const contextParamsList = (0, utils_1.getContextAuthzMetaParamsList)(paramsList, {
78
+ defaultOverride: this.jwtAuthzOptions.defaultOverride,
79
+ skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
80
+ });
81
+ const req = context.switchToHttp().getRequest();
82
+ store.allowAnonymous = (0, utils_1.getAllowAnonymous)(contextParamsList, {
83
+ defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
84
+ });
85
+ await super.canActivate(context);
86
+ // will be null if allowAnonymous=true.
87
+ const user = (0, utils_1.getPassportProperty)(req);
88
+ if (store.allowAnonymous && !user) {
89
+ return true;
90
+ }
91
+ for (const ele of contextParamsList) {
92
+ if (!(await this.authzProvider.authorize(user, ele.metaData))) {
93
+ return false;
94
+ }
95
+ }
96
+ return true;
83
97
  }
84
- store.guardResult = false;
85
- throw info;
86
- }
87
- return user;
88
- }
89
- async canActivate(context) {
90
- const store = (0, import_utils.getAlsStore)(this.als);
91
- if ((0, import_utils.isNotFalsy)(store.guardResult)) {
92
- return store.guardResult;
93
- }
94
- const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_REFRESH_META_KEY, [
95
- context.getClass(),
96
- context.getHandler()
97
- ]));
98
- if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
99
- store.guardResult = true;
100
- return true;
101
- }
102
- const paramsList = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_META_KEY, [
103
- context.getClass(),
104
- context.getHandler()
105
- ]));
106
- if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
107
- store.guardResult = true;
108
- return true;
109
- }
110
- const contextParamsList = (0, import_utils.getContextAuthzMetaParamsList)(paramsList, {
111
- defaultOverride: this.jwtAuthzOptions.defaultOverride,
112
- skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
113
- });
114
- const req = context.switchToHttp().getRequest();
115
- store.allowAnonymous = (0, import_utils.getAllowAnonymous)(contextParamsList, {
116
- defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
117
- });
118
- await super.canActivate(context);
119
- const user = (0, import_utils.getPassportProperty)(req);
120
- if (store.allowAnonymous && !user) {
121
- return true;
122
- }
123
- for (const ele of contextParamsList) {
124
- if (!await this.authzProvider.authorize(user, ele.metaData)) {
125
- return false;
98
+ };
99
+ JwtAuthzGuard = __decorate([
100
+ __param(1, (0, common_1.Inject)(AUTHZ_PROVIDER)),
101
+ __param(2, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
102
+ __param(3, (0, common_1.Inject)(ALS_PROVIDER)),
103
+ __metadata("design:paramtypes", [core_1.Reflector,
104
+ authz_provider_1.AuthzProviderClass, Object, Function])
105
+ ], JwtAuthzGuard);
106
+ return (0, common_1.mixin)(JwtAuthzGuard);
107
+ };
108
+ exports.createJwtAuthzGuard = createJwtAuthzGuard;
109
+ const createJwtRefreshAuthzGuard = ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
110
+ let JwtRefreshAuthzGuard = class JwtRefreshAuthzGuard extends (0, passport_1.AuthGuard)(JWT_REFRESH_STRATEGY) {
111
+ constructor(jwtAuthzOptions) {
112
+ super();
113
+ this.jwtAuthzOptions = jwtAuthzOptions;
114
+ }
115
+ getAuthenticateOptions() {
116
+ return {
117
+ property: this.jwtAuthzOptions.passportProperty,
118
+ session: false
119
+ };
126
120
  }
127
- }
128
- return true;
129
- }
130
- }, __name(_a, "JwtAuthzGuard"), _a);
131
- JwtAuthzGuard = _ts_decorate([
132
- _ts_param(1, (0, import_common.Inject)(AUTHZ_PROVIDER)),
133
- _ts_param(2, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
134
- _ts_param(3, (0, import_common.Inject)(ALS_PROVIDER)),
135
- _ts_metadata("design:type", Function),
136
- _ts_metadata("design:paramtypes", [
137
- typeof import_core.Reflector === "undefined" ? Object : import_core.Reflector,
138
- typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
139
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions,
140
- typeof AsyncLocalStorage === "undefined" ? Object : AsyncLocalStorage
141
- ])
142
- ], JwtAuthzGuard);
143
- return (0, import_common.mixin)(JwtAuthzGuard);
144
- }, "createJwtAuthzGuard");
145
- const createJwtRefreshAuthzGuard = /* @__PURE__ */ __name(([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
146
- var _a;
147
- let JwtRefreshAuthzGuard = (_a = class extends (0, import_passport.AuthGuard)(JWT_REFRESH_STRATEGY) {
148
- constructor(jwtAuthzOptions) {
149
- super();
150
- __publicField(this, "jwtAuthzOptions");
151
- this.jwtAuthzOptions = jwtAuthzOptions;
152
- }
153
- getAuthenticateOptions() {
154
- return {
155
- property: this.jwtAuthzOptions.passportProperty,
156
- session: false
157
- };
158
- }
159
- handleRequest(_err, user, info) {
160
- if (info) {
161
- throw info;
162
- }
163
- return user;
164
- }
165
- }, __name(_a, "JwtRefreshAuthzGuard"), _a);
166
- JwtRefreshAuthzGuard = _ts_decorate([
167
- _ts_param(0, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
168
- _ts_metadata("design:type", Function),
169
- _ts_metadata("design:paramtypes", [
170
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions
171
- ])
172
- ], JwtRefreshAuthzGuard);
173
- return (0, import_common.mixin)(JwtRefreshAuthzGuard);
174
- }, "createJwtRefreshAuthzGuard");
175
- // Annotate the CommonJS export names for ESM import in node:
176
- 0 && (module.exports = {
177
- createJwtAuthzGuard,
178
- createJwtRefreshAuthzGuard
179
- });
121
+ handleRequest(_err, user, info) {
122
+ if (info) {
123
+ throw info;
124
+ }
125
+ return user;
126
+ }
127
+ };
128
+ JwtRefreshAuthzGuard = __decorate([
129
+ __param(0, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
130
+ __metadata("design:paramtypes", [Object])
131
+ ], JwtRefreshAuthzGuard);
132
+ return (0, common_1.mixin)(JwtRefreshAuthzGuard);
133
+ };
134
+ exports.createJwtRefreshAuthzGuard = createJwtRefreshAuthzGuard;
@@ -1,14 +1,7 @@
1
- import * as crypto from 'crypto';
2
- import { VerifyOptions, SignOptions, Secret, PrivateKey, PublicKey } from 'jsonwebtoken';
3
- import { AuthzModuleBaseOptions } from '../utils/types.js';
4
- import { JwtFromRequestFunction } from './extract-jwt.js';
5
- import '@nestjs/common';
6
- import '@nestjs/common/interfaces';
7
- import 'express';
8
- import '../authz.provider.js';
9
- import 'cookie';
10
-
11
- type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & SignOptions & {
1
+ import { type PrivateKey, type PublicKey, type Secret, type SignOptions, type VerifyOptions } from 'jsonwebtoken';
2
+ import { type AuthzModuleBaseOptions } from '../utils';
3
+ import type { JwtFromRequestFunction } from './extract-jwt';
4
+ export type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & SignOptions & {
12
5
  /**
13
6
  * Function that accepts a request as the only parameter and returns either the JWT as a string or null.
14
7
  *
@@ -28,7 +21,7 @@ type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & Si
28
21
  */
29
22
  publicKey?: PublicKey;
30
23
  };
31
- type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
24
+ export type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
32
25
  /**
33
26
  * JWT sign & verify options.
34
27
  *
@@ -44,41 +37,39 @@ type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
44
37
  */
45
38
  refresh?: JwtOptions;
46
39
  };
47
- declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOptions) => {
40
+ export declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOptions) => {
48
41
  defaultOverride: boolean;
49
42
  passportProperty: string;
50
43
  skipFalsyMetadata: boolean;
51
44
  defaultAllowAnonymous: boolean;
52
45
  jwt: {
53
- secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
46
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
54
47
  key: string | Buffer;
55
48
  passphrase: string;
56
- } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
57
- secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
49
+ } | import("crypto").PrivateKeyInput | import("crypto").JsonWebKeyInput | null;
50
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
58
51
  key: string | Buffer;
59
52
  passphrase: string;
60
- } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
53
+ } | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput | null;
61
54
  jwtFromRequest: JwtFromRequestFunction<any>[];
62
55
  sign: SignOptions;
63
56
  verify: VerifyOptions;
64
57
  };
65
58
  refresh: {
66
- secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
59
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
67
60
  key: string | Buffer;
68
61
  passphrase: string;
69
- } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
70
- secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
62
+ } | import("crypto").PrivateKeyInput | import("crypto").JsonWebKeyInput | null;
63
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
71
64
  key: string | Buffer;
72
65
  passphrase: string;
73
- } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
66
+ } | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput | null;
74
67
  jwtFromRequest: JwtFromRequestFunction<any>[];
75
68
  sign: SignOptions;
76
69
  verify: VerifyOptions;
77
70
  } | undefined;
78
71
  };
79
- type JwtAuthzOptions = ReturnType<typeof normalizedJwtAuthzModuleOptions>;
80
- interface RefreshPayload {
72
+ export type JwtAuthzOptions = ReturnType<typeof normalizedJwtAuthzModuleOptions>;
73
+ export interface RefreshPayload {
81
74
  data: string;
82
75
  }
83
-
84
- export { type JwtAuthzModuleOptions, type JwtAuthzOptions, type JwtOptions, type RefreshPayload, normalizedJwtAuthzModuleOptions };
@@ -1,94 +1,71 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizedJwtAuthzModuleOptions = void 0;
4
+ const constants_1 = require("../constants");
5
+ const utils_1 = require("../utils");
6
+ const normalizedJwtOptions = (jwtOptions) => {
7
+ if (!jwtOptions) {
8
+ return undefined;
9
+ }
10
+ const { jwtFromRequest, algorithm, audience, clockTimestamp, clockTolerance, complete, ignoreExpiration, ignoreNotBefore, issuer, jwtid, maxAge, nonce, privateKey, publicKey, secret, subject, allowInsecureKeySizes, encoding, expiresIn, header, keyid, mutatePayload, noTimestamp, notBefore, allowInvalidAsymmetricKeyTypes } = jwtOptions;
11
+ const formattedJwtFromRequest = (0, utils_1.normalizedArray)(jwtFromRequest);
12
+ const algorithms = (0, utils_1.normalizedArray)(algorithm);
13
+ const sign = {
14
+ algorithm: algorithms?.[0],
15
+ audience,
16
+ issuer,
17
+ jwtid,
18
+ subject,
19
+ allowInsecureKeySizes,
20
+ encoding,
21
+ expiresIn,
22
+ header,
23
+ keyid,
24
+ mutatePayload,
25
+ notBefore,
26
+ noTimestamp,
27
+ allowInvalidAsymmetricKeyTypes
28
+ };
29
+ const verify = {
30
+ algorithms,
31
+ audience,
32
+ clockTimestamp,
33
+ clockTolerance,
34
+ complete,
35
+ ignoreExpiration,
36
+ ignoreNotBefore,
37
+ issuer,
38
+ jwtid,
39
+ maxAge,
40
+ nonce,
41
+ subject,
42
+ allowInvalidAsymmetricKeyTypes
43
+ };
44
+ let secretOrPrivateKey = secret;
45
+ let secretOrPublicKey = secret;
46
+ if (privateKey || publicKey) {
47
+ secretOrPrivateKey = privateKey;
48
+ secretOrPublicKey = publicKey;
49
+ if (secret) {
50
+ console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
51
+ }
52
+ }
53
+ return {
54
+ secretOrPrivateKey: secretOrPrivateKey ?? null,
55
+ secretOrPublicKey: secretOrPublicKey ?? null,
56
+ jwtFromRequest: formattedJwtFromRequest ?? [],
57
+ sign: (0, utils_1.normalizedObject)(sign) ?? {},
58
+ verify: (0, utils_1.normalizedObject)(verify) ?? {}
59
+ };
9
60
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
61
+ const normalizedJwtAuthzModuleOptions = (options) => {
62
+ return {
63
+ defaultOverride: options?.defaultOverride || false,
64
+ passportProperty: options?.passportProperty || constants_1.DEFAULT_PASSPORT_PROPERTY_VALUE,
65
+ skipFalsyMetadata: options?.skipFalsyMetadata || false,
66
+ defaultAllowAnonymous: options.defaultAllowAnonymous || false,
67
+ jwt: normalizedJwtOptions(options?.jwt),
68
+ refresh: normalizedJwtOptions(options?.refresh)
69
+ };
17
70
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var jwt_authz_interface_exports = {};
20
- __export(jwt_authz_interface_exports, {
21
- normalizedJwtAuthzModuleOptions: () => normalizedJwtAuthzModuleOptions
22
- });
23
- module.exports = __toCommonJS(jwt_authz_interface_exports);
24
- var import_constants = require("../constants");
25
- var import_utils = require("../utils");
26
- const normalizedJwtOptions = /* @__PURE__ */ __name((jwtOptions) => {
27
- if (!jwtOptions) {
28
- return void 0;
29
- }
30
- const { jwtFromRequest, algorithm, audience, clockTimestamp, clockTolerance, complete, ignoreExpiration, ignoreNotBefore, issuer, jwtid, maxAge, nonce, privateKey, publicKey, secret, subject, allowInsecureKeySizes, encoding, expiresIn, header, keyid, mutatePayload, noTimestamp, notBefore, allowInvalidAsymmetricKeyTypes } = jwtOptions;
31
- const formattedJwtFromRequest = (0, import_utils.normalizedArray)(jwtFromRequest);
32
- const algorithms = (0, import_utils.normalizedArray)(algorithm);
33
- const sign = {
34
- algorithm: algorithms?.[0],
35
- audience,
36
- issuer,
37
- jwtid,
38
- subject,
39
- allowInsecureKeySizes,
40
- encoding,
41
- expiresIn,
42
- header,
43
- keyid,
44
- mutatePayload,
45
- notBefore,
46
- noTimestamp,
47
- allowInvalidAsymmetricKeyTypes
48
- };
49
- const verify = {
50
- algorithms,
51
- audience,
52
- clockTimestamp,
53
- clockTolerance,
54
- complete,
55
- ignoreExpiration,
56
- ignoreNotBefore,
57
- issuer,
58
- jwtid,
59
- maxAge,
60
- nonce,
61
- subject,
62
- allowInvalidAsymmetricKeyTypes
63
- };
64
- let secretOrPrivateKey = secret;
65
- let secretOrPublicKey = secret;
66
- if (privateKey || publicKey) {
67
- secretOrPrivateKey = privateKey;
68
- secretOrPublicKey = publicKey;
69
- if (secret) {
70
- console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
71
- }
72
- }
73
- return {
74
- secretOrPrivateKey: secretOrPrivateKey ?? null,
75
- secretOrPublicKey: secretOrPublicKey ?? null,
76
- jwtFromRequest: formattedJwtFromRequest ?? [],
77
- sign: (0, import_utils.normalizedObject)(sign) ?? {},
78
- verify: (0, import_utils.normalizedObject)(verify) ?? {}
79
- };
80
- }, "normalizedJwtOptions");
81
- const normalizedJwtAuthzModuleOptions = /* @__PURE__ */ __name((options) => {
82
- return {
83
- defaultOverride: options?.defaultOverride || false,
84
- passportProperty: options?.passportProperty || import_constants.DEFAULT_PASSPORT_PROPERTY_VALUE,
85
- skipFalsyMetadata: options?.skipFalsyMetadata || false,
86
- defaultAllowAnonymous: options.defaultAllowAnonymous || false,
87
- jwt: normalizedJwtOptions(options?.jwt),
88
- refresh: normalizedJwtOptions(options?.refresh)
89
- };
90
- }, "normalizedJwtAuthzModuleOptions");
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- normalizedJwtAuthzModuleOptions
94
- });
71
+ exports.normalizedJwtAuthzModuleOptions = normalizedJwtAuthzModuleOptions;