@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.
- package/dist/authz.provider.d.ts +3 -4
- package/dist/authz.provider.js +27 -43
- package/dist/constants.d.ts +6 -8
- package/dist/constants.js +13 -46
- package/dist/errors.d.ts +3 -5
- package/dist/errors.js +29 -44
- package/dist/index.d.ts +5 -21
- package/dist/index.js +16 -45
- package/dist/jwt/extract-jwt.d.ts +4 -7
- package/dist/jwt/extract-jwt.js +136 -152
- package/dist/jwt/index.d.ts +2 -16
- package/dist/jwt/index.js +7 -30
- package/dist/jwt/jwt-authz-als.middleware.d.ts +6 -16
- package/dist/jwt/jwt-authz-als.middleware.js +40 -60
- package/dist/jwt/jwt-authz.guard.d.ts +8 -21
- package/dist/jwt/jwt-authz.guard.js +126 -148
- package/dist/jwt/jwt-authz.interface.d.ts +16 -25
- package/dist/jwt/jwt-authz.interface.js +66 -114
- package/dist/jwt/jwt-authz.module.d.ts +19 -31
- package/dist/jwt/jwt-authz.module.js +240 -242
- package/dist/jwt/jwt-authz.service.d.ts +6 -17
- package/dist/jwt/jwt-authz.service.js +113 -144
- package/dist/jwt/jwt-authz.strategy.d.ts +5 -17
- package/dist/jwt/jwt-authz.strategy.js +127 -150
- package/dist/session/index.d.ts +1 -12
- package/dist/session/index.js +5 -27
- package/dist/session/session-authz-als.middleware.d.ts +5 -12
- package/dist/session/session-authz-als.middleware.js +95 -109
- package/dist/session/session-authz.guard.d.ts +6 -15
- package/dist/session/session-authz.guard.js +96 -116
- package/dist/session/session-authz.interface.d.ts +5 -12
- package/dist/session/session-authz.interface.js +18 -40
- package/dist/session/session-authz.module.d.ts +18 -26
- package/dist/session/session-authz.module.js +231 -237
- package/dist/session/session-authz.service.d.ts +5 -13
- package/dist/session/session-authz.service.js +66 -83
- package/dist/session/session-authz.strategy.d.ts +4 -12
- package/dist/session/session-authz.strategy.js +65 -78
- package/dist/user.decorator.d.ts +3 -6
- package/dist/user.decorator.js +25 -33
- package/dist/utils/cookie-parsers.d.ts +3 -6
- package/dist/utils/cookie-parsers.js +62 -63
- package/dist/utils/create-authz-decorator-factory.d.ts +3 -9
- package/dist/utils/create-authz-decorator-factory.js +29 -50
- package/dist/utils/create-set-cookie-fn.d.ts +3 -9
- package/dist/utils/create-set-cookie-fn.js +21 -42
- package/dist/utils/generics.d.ts +4 -6
- package/dist/utils/generics.js +31 -54
- package/dist/utils/get-allow-anonymous.d.ts +2 -9
- package/dist/utils/get-allow-anonymous.js +6 -27
- package/dist/utils/get-als-store.d.ts +2 -5
- package/dist/utils/get-als-store.js +10 -32
- package/dist/utils/get-context-authz-meta-params-list.d.ts +2 -9
- package/dist/utils/get-context-authz-meta-params-list.js +15 -33
- package/dist/utils/get-passport-property.d.ts +1 -3
- package/dist/utils/get-passport-property.js +7 -28
- package/dist/utils/index.d.ts +11 -16
- package/dist/utils/index.js +26 -40
- package/dist/utils/merge-dynamic-module-configs.d.ts +2 -5
- package/dist/utils/merge-dynamic-module-configs.js +13 -38
- package/dist/utils/msgpackrs.d.ts +2 -4
- package/dist/utils/msgpackrs.js +9 -32
- package/dist/utils/types.d.ts +23 -26
- package/dist/utils/types.js +2 -15
- package/package.json +4 -4
|
@@ -1,156 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
__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;
|
|
8
7
|
};
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
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);
|
|
16
10
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
-
if (decorator = decorators[i])
|
|
22
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
-
if (kind && result) __defProp(target, key, result);
|
|
24
|
-
return result;
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
25
13
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
JWT_META_KEY,
|
|
43
|
-
JWT_REFRESH_META_KEY
|
|
44
|
-
]) => {
|
|
45
|
-
let JwtAuthzGuard = class extends (0, import_passport.AuthGuard)(JWT_STRATEGY) {
|
|
46
|
-
constructor(reflector, authzProvider, jwtAuthzOptions, als) {
|
|
47
|
-
super();
|
|
48
|
-
this.reflector = reflector;
|
|
49
|
-
this.authzProvider = authzProvider;
|
|
50
|
-
this.jwtAuthzOptions = jwtAuthzOptions;
|
|
51
|
-
this.als = als;
|
|
52
|
-
}
|
|
53
|
-
getAuthenticateOptions() {
|
|
54
|
-
return {
|
|
55
|
-
property: this.jwtAuthzOptions.passportProperty,
|
|
56
|
-
session: false
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* recives err, user, info from JwtStrategy.validate
|
|
62
|
-
*
|
|
63
|
-
* will return request.user=null if allowAnonymous=true
|
|
64
|
-
*
|
|
65
|
-
* @param _err will always be null
|
|
66
|
-
* @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
|
|
67
|
-
* @param info AuthzError or undefined
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
handleRequest(_err, user, info) {
|
|
71
|
-
const store = (0, import_utils.getAlsStore)(this.als);
|
|
72
|
-
if (info) {
|
|
73
|
-
if (store.allowAnonymous && info.name === import_errors.AuthzAnonymousError.name) {
|
|
74
|
-
return user;
|
|
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;
|
|
75
30
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
async canActivate(context) {
|
|
82
|
-
const store = (0, import_utils.getAlsStore)(this.als);
|
|
83
|
-
if ((0, import_utils.isNotFalsy)(store.guardResult)) {
|
|
84
|
-
return store.guardResult;
|
|
85
|
-
}
|
|
86
|
-
const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(
|
|
87
|
-
this.reflector.getAll(JWT_REFRESH_META_KEY, [context.getClass(), context.getHandler()])
|
|
88
|
-
);
|
|
89
|
-
if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
|
|
90
|
-
store.guardResult = true;
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
const paramsList = (0, import_utils.normalizedArray)(
|
|
94
|
-
this.reflector.getAll(JWT_META_KEY, [context.getClass(), context.getHandler()])
|
|
95
|
-
);
|
|
96
|
-
if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
|
|
97
|
-
store.guardResult = true;
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
const contextParamsList = (0, import_utils.getContextAuthzMetaParamsList)(paramsList, {
|
|
101
|
-
defaultOverride: this.jwtAuthzOptions.defaultOverride,
|
|
102
|
-
skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
|
|
103
|
-
});
|
|
104
|
-
const req = context.switchToHttp().getRequest();
|
|
105
|
-
store.allowAnonymous = (0, import_utils.getAllowAnonymous)(contextParamsList, {
|
|
106
|
-
defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
|
|
107
|
-
});
|
|
108
|
-
await super.canActivate(context);
|
|
109
|
-
const user = (0, import_utils.getPassportProperty)(req);
|
|
110
|
-
if (store.allowAnonymous && !user) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
for (const ele of contextParamsList) {
|
|
114
|
-
if (!await this.authzProvider.authorize(user, ele.metaData)) {
|
|
115
|
-
return false;
|
|
31
|
+
getAuthenticateOptions() {
|
|
32
|
+
return {
|
|
33
|
+
property: this.jwtAuthzOptions.passportProperty,
|
|
34
|
+
session: false
|
|
35
|
+
};
|
|
116
36
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
97
|
+
}
|
|
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);
|
|
127
107
|
};
|
|
108
|
+
exports.createJwtAuthzGuard = createJwtAuthzGuard;
|
|
128
109
|
const createJwtRefreshAuthzGuard = ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
};
|
|
120
|
+
}
|
|
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);
|
|
151
133
|
};
|
|
152
|
-
|
|
153
|
-
0 && (module.exports = {
|
|
154
|
-
createJwtAuthzGuard,
|
|
155
|
-
createJwtRefreshAuthzGuard
|
|
156
|
-
});
|
|
134
|
+
exports.createJwtRefreshAuthzGuard = createJwtRefreshAuthzGuard;
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
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,119 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var jwt_authz_interface_exports = {};
|
|
19
|
-
__export(jwt_authz_interface_exports, {
|
|
20
|
-
normalizedJwtAuthzModuleOptions: () => normalizedJwtAuthzModuleOptions
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(jwt_authz_interface_exports);
|
|
23
|
-
var import_constants = require("../constants");
|
|
24
|
-
var import_utils = require("../utils");
|
|
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");
|
|
25
6
|
const normalizedJwtOptions = (jwtOptions) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
jwtFromRequest
|
|
31
|
-
algorithm
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
noTimestamp,
|
|
72
|
-
allowInvalidAsymmetricKeyTypes
|
|
73
|
-
};
|
|
74
|
-
const verify = {
|
|
75
|
-
algorithms,
|
|
76
|
-
audience,
|
|
77
|
-
clockTimestamp,
|
|
78
|
-
clockTolerance,
|
|
79
|
-
complete,
|
|
80
|
-
ignoreExpiration,
|
|
81
|
-
ignoreNotBefore,
|
|
82
|
-
issuer,
|
|
83
|
-
jwtid,
|
|
84
|
-
maxAge,
|
|
85
|
-
nonce,
|
|
86
|
-
subject,
|
|
87
|
-
allowInvalidAsymmetricKeyTypes
|
|
88
|
-
};
|
|
89
|
-
let secretOrPrivateKey = secret;
|
|
90
|
-
let secretOrPublicKey = secret;
|
|
91
|
-
if (privateKey || publicKey) {
|
|
92
|
-
secretOrPrivateKey = privateKey;
|
|
93
|
-
secretOrPublicKey = publicKey;
|
|
94
|
-
if (secret) {
|
|
95
|
-
console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
|
|
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
|
+
}
|
|
96
52
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
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
|
+
};
|
|
105
60
|
};
|
|
106
61
|
const normalizedJwtAuthzModuleOptions = (options) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
};
|
|
115
70
|
};
|
|
116
|
-
|
|
117
|
-
0 && (module.exports = {
|
|
118
|
-
normalizedJwtAuthzModuleOptions
|
|
119
|
-
});
|
|
71
|
+
exports.normalizedJwtAuthzModuleOptions = normalizedJwtAuthzModuleOptions;
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import './extract-jwt.js';
|
|
2
|
-
import * as _nestjs_core from '@nestjs/core';
|
|
3
|
-
import { JwtOptions, JwtAuthzModuleOptions, JwtAuthzOptions } from './jwt-authz.interface.js';
|
|
4
|
-
import { AuthzProviderClass } from '../authz.provider.js';
|
|
5
|
-
import { AbstractConstructor, RoutesOptions, AuthzModuleBaseOptions, AuthzModuleRoutesOptions, AuthzDecoParams, MethodParameters, ApplyDecorators, CookieOptionsWithSecret, DeepReadonly } from '../utils/types.js';
|
|
6
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { AuthzError } from '../errors
|
|
10
|
-
import {
|
|
11
|
-
import '
|
|
12
|
-
import '
|
|
13
|
-
import
|
|
14
|
-
import '@nestjs/common/interfaces';
|
|
15
|
-
import 'express';
|
|
16
|
-
import '../constants.js';
|
|
17
|
-
|
|
18
|
-
declare const ASYNC_OPTIONS_TYPE: _nestjs_common.ConfigurableModuleAsyncOptions<JwtAuthzModuleOptions, "createJwtAuthzModuleOptions"> & Partial<{
|
|
2
|
+
import { DynamicModule, MiddlewareConsumer, type Type } from '@nestjs/common';
|
|
3
|
+
import { AuthzProviderClass } from '../authz.provider';
|
|
4
|
+
import { AuthzError } from '../errors';
|
|
5
|
+
import { type AbstractConstructor, type ApplyDecorators, type AuthzModuleRoutesOptions, type RoutesOptions } from '../utils';
|
|
6
|
+
import { type JwtAlsType } from './jwt-authz-als.middleware';
|
|
7
|
+
import { type JwtAuthzModuleOptions, type JwtAuthzOptions } from './jwt-authz.interface';
|
|
8
|
+
declare const ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<JwtAuthzModuleOptions, "createJwtAuthzModuleOptions"> & Partial<{
|
|
19
9
|
authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
|
|
20
|
-
} & AuthzModuleRoutesOptions
|
|
21
|
-
|
|
22
|
-
jwt
|
|
23
|
-
refresh?: JwtOptions;
|
|
10
|
+
} & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<import("../utils").AuthzModuleBaseOptions> & {
|
|
11
|
+
jwt: import("./jwt-authz.interface").JwtOptions;
|
|
12
|
+
refresh?: import("./jwt-authz.interface").JwtOptions;
|
|
24
13
|
} & Partial<{
|
|
25
14
|
authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
|
|
26
15
|
} & AuthzModuleRoutesOptions>;
|
|
@@ -31,7 +20,7 @@ declare const OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
|
|
|
31
20
|
* @param authzProvider - The implementation class of `AuthzProviderClass`
|
|
32
21
|
* @returns \{AuthzModule, AuthzGuard, AuthzService}
|
|
33
22
|
*/
|
|
34
|
-
declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(authzProvider: AbstractConstructor<T, P, U>) => {
|
|
23
|
+
export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(authzProvider: AbstractConstructor<T, P, U>) => {
|
|
35
24
|
/**
|
|
36
25
|
* A dynamic module used to configure JWT based authentication and authorization features for the application.
|
|
37
26
|
*
|
|
@@ -103,7 +92,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
|
|
|
103
92
|
* ```
|
|
104
93
|
*/
|
|
105
94
|
AuthzGuard: Type<Omit<{
|
|
106
|
-
readonly reflector:
|
|
95
|
+
readonly reflector: import("@nestjs/core").Reflector;
|
|
107
96
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
108
97
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
109
98
|
readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
|
|
@@ -112,11 +101,11 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
|
|
|
112
101
|
session: boolean;
|
|
113
102
|
};
|
|
114
103
|
handleRequest<T_1>(_err: unknown, user: T_1, info?: AuthzError): T_1;
|
|
115
|
-
canActivate(context:
|
|
104
|
+
canActivate(context: import("@nestjs/common").ExecutionContext): Promise<boolean>;
|
|
116
105
|
logIn<TRequest extends {
|
|
117
106
|
logIn: Function;
|
|
118
107
|
} = any>(request: TRequest): Promise<void>;
|
|
119
|
-
getRequest(context:
|
|
108
|
+
getRequest(context: import("@nestjs/common").ExecutionContext): any;
|
|
120
109
|
}, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">> & {
|
|
121
110
|
/**
|
|
122
111
|
* Verifies the user's authorization for specific meta data.
|
|
@@ -135,7 +124,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
|
|
|
135
124
|
* }
|
|
136
125
|
* ```
|
|
137
126
|
*/
|
|
138
|
-
Verify: (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|
|
127
|
+
Verify: (...args: import("../utils").AuthzDecoParams<import("../utils").MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|
|
139
128
|
/**
|
|
140
129
|
* Skips authentication & authorization checks for specific routes.
|
|
141
130
|
*
|
|
@@ -188,7 +177,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
|
|
|
188
177
|
* }
|
|
189
178
|
* ```
|
|
190
179
|
*/
|
|
191
|
-
Apply: (...rest: Parameters<(...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
180
|
+
Apply: (...rest: Parameters<(...args: import("../utils").AuthzDecoParams<import("../utils").MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
192
181
|
};
|
|
193
182
|
/**
|
|
194
183
|
* A custom servcie to provide methods to handle authentication and authorization.
|
|
@@ -207,9 +196,8 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
|
|
|
207
196
|
refresh(user?: U | undefined): Promise<{
|
|
208
197
|
token: string;
|
|
209
198
|
} | undefined>;
|
|
210
|
-
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
211
|
-
getUser(): DeepReadonly<U> | undefined;
|
|
199
|
+
setCookie(name: string, value: string, options?: import("../utils").CookieOptionsWithSecret | undefined): void;
|
|
200
|
+
getUser(): import("../utils").DeepReadonly<U> | undefined;
|
|
212
201
|
}, "als" | "jwtAuthzOptions" | "authzProvider">>;
|
|
213
202
|
};
|
|
214
|
-
|
|
215
|
-
export { createJwtAuthzModule };
|
|
203
|
+
export {};
|