@nestjs-kitchen/authz 2.0.3 → 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.
- package/dist/authz.provider.d.ts +1 -3
- 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,88 +1,71 @@
|
|
|
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
|
-
var import_errors = require("../errors");
|
|
34
|
-
var import_utils = require("../utils");
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createSessionAuthzService = void 0;
|
|
16
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const authz_provider_1 = require("../authz.provider");
|
|
19
|
+
const errors_1 = require("../errors");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
35
21
|
const createSessionAuthzService = ([AUTHZ_PROVIDER, ALS_PROVIDER]) => {
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
22
|
+
let SessionAuthzService = class SessionAuthzService {
|
|
23
|
+
constructor(authzProvider, als) {
|
|
24
|
+
this.authzProvider = authzProvider;
|
|
25
|
+
this.als = als;
|
|
26
|
+
if (typeof this.authzProvider.createPayload !== 'function') {
|
|
27
|
+
throw new errors_1.AuthzError(`InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a session id with a payload generated by AuthzProviderClass.createPayload().
|
|
32
|
+
*
|
|
33
|
+
* @param user - User entity
|
|
34
|
+
*/
|
|
35
|
+
async logIn(user) {
|
|
36
|
+
const store = (0, utils_1.getAlsStore)(this.als);
|
|
37
|
+
const payload = await this.authzProvider.createPayload(user);
|
|
38
|
+
return store.logIn(payload);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Clears current user session.
|
|
42
|
+
*/
|
|
43
|
+
async logOut() {
|
|
44
|
+
const store = (0, utils_1.getAlsStore)(this.als);
|
|
45
|
+
return store.logOut();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets a secure HTTP cookie with the given name, value, and optional cookie options.
|
|
49
|
+
*/
|
|
50
|
+
setCookie(...rest) {
|
|
51
|
+
const store = (0, utils_1.getAlsStore)(this.als);
|
|
52
|
+
store.setCookie(...rest);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the current user associated with the request, if available.
|
|
56
|
+
*/
|
|
57
|
+
getUser() {
|
|
58
|
+
const store = (0, utils_1.getAlsStore)(this.als);
|
|
59
|
+
const user = store.user;
|
|
60
|
+
return user;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
SessionAuthzService = __decorate([
|
|
64
|
+
__param(0, (0, common_1.Inject)(AUTHZ_PROVIDER)),
|
|
65
|
+
__param(1, (0, common_1.Inject)(ALS_PROVIDER)),
|
|
66
|
+
__metadata("design:paramtypes", [authz_provider_1.AuthzProviderClass,
|
|
67
|
+
node_async_hooks_1.AsyncLocalStorage])
|
|
68
|
+
], SessionAuthzService);
|
|
69
|
+
return (0, common_1.mixin)(SessionAuthzService);
|
|
84
70
|
};
|
|
85
|
-
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
createSessionAuthzService
|
|
88
|
-
});
|
|
71
|
+
exports.createSessionAuthzService = createSessionAuthzService;
|
|
@@ -1,18 +1,10 @@
|
|
|
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
|
|
5
|
-
import { SessionAlsType } from './session-authz-als.middleware
|
|
6
|
-
import
|
|
7
|
-
import '@nestjs/common/interfaces';
|
|
8
|
-
import './session-authz.interface.js';
|
|
9
|
-
import 'express-session';
|
|
10
|
-
|
|
11
|
-
declare const createSessionAuthzStrategy: ([SESSION_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 { SessionAlsType } from './session-authz-als.middleware';
|
|
5
|
+
export declare const createSessionAuthzStrategy: ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => import("@nestjs/common").Type<Omit<{
|
|
12
6
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
13
7
|
readonly als: AsyncLocalStorage<SessionAlsType<unknown, unknown>>;
|
|
14
8
|
validate(req: Request): Promise<{}>;
|
|
15
9
|
authenticate(req: Request, options?: any): any;
|
|
16
10
|
}, "als" | "authzProvider">>;
|
|
17
|
-
|
|
18
|
-
export { createSessionAuthzStrategy };
|
|
@@ -1,83 +1,70 @@
|
|
|
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
|
-
var import_errors = require("../errors");
|
|
37
|
-
var import_utils = require("../utils");
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createSessionAuthzStrategy = void 0;
|
|
16
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const passport_1 = require("@nestjs/passport");
|
|
19
|
+
const passport_custom_1 = require("passport-custom");
|
|
20
|
+
const authz_provider_1 = require("../authz.provider");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const utils_1 = require("../utils");
|
|
38
24
|
const createSessionAuthzStrategy = ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
25
|
+
let SessionAuthzStrategy = class SessionAuthzStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, SESSION_STRATEGY) {
|
|
26
|
+
constructor(authzProvider, als) {
|
|
27
|
+
super();
|
|
28
|
+
this.authzProvider = authzProvider;
|
|
29
|
+
this.als = als;
|
|
30
|
+
if (typeof this.authzProvider.authenticate !== 'function') {
|
|
31
|
+
throw new errors_1.AuthzError(`InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async validate(req) {
|
|
35
|
+
const store = (0, utils_1.getAlsStore)(this.als);
|
|
36
|
+
const authOptions = store.authOptions;
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
req[constants_1.PASSPORT_PROPERTY] = authOptions.passportProperty;
|
|
39
|
+
const payload = req?.session?.[constants_1.SESSION_PASSPORT_KEY]?.user;
|
|
40
|
+
if (!payload) {
|
|
41
|
+
return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find session.')];
|
|
42
|
+
}
|
|
43
|
+
let user = undefined;
|
|
44
|
+
try {
|
|
45
|
+
user = await this.authzProvider.authenticate(payload);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return [
|
|
49
|
+
null,
|
|
50
|
+
error instanceof Error
|
|
51
|
+
? new errors_1.AuthzVerificationError(`${error.name}: ${error.message}`, error)
|
|
52
|
+
: new errors_1.AuthzVerificationError(`${error}`)
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
store.user = user;
|
|
56
|
+
if (!user) {
|
|
57
|
+
return [null, new errors_1.AuthzAnonymousError('AnonymousError: Cannnot find user.')];
|
|
58
|
+
}
|
|
59
|
+
return user;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
SessionAuthzStrategy = __decorate([
|
|
63
|
+
__param(0, (0, common_1.Inject)(AUTHZ_PROVIDER)),
|
|
64
|
+
__param(1, (0, common_1.Inject)(ALS_PROVIDER)),
|
|
65
|
+
__metadata("design:paramtypes", [authz_provider_1.AuthzProviderClass,
|
|
66
|
+
node_async_hooks_1.AsyncLocalStorage])
|
|
67
|
+
], SessionAuthzStrategy);
|
|
68
|
+
return (0, common_1.mixin)(SessionAuthzStrategy);
|
|
79
69
|
};
|
|
80
|
-
|
|
81
|
-
0 && (module.exports = {
|
|
82
|
-
createSessionAuthzStrategy
|
|
83
|
-
});
|
|
70
|
+
exports.createSessionAuthzStrategy = createSessionAuthzStrategy;
|
package/dist/user.decorator.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
-
|
|
3
|
-
declare const userDecoratorFactory: (_data: unknown, ctx: ExecutionContext) => unknown;
|
|
1
|
+
import { type ExecutionContext } from '@nestjs/common';
|
|
2
|
+
export declare const userDecoratorFactory: (_data: unknown, ctx: ExecutionContext) => unknown;
|
|
4
3
|
/**
|
|
5
4
|
* Retrieves the current user associated with the request, if available.
|
|
6
5
|
*
|
|
@@ -17,6 +16,4 @@ declare const userDecoratorFactory: (_data: unknown, ctx: ExecutionContext) => u
|
|
|
17
16
|
* }
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
20
|
-
declare const User: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
21
|
-
|
|
22
|
-
export { User, userDecoratorFactory };
|
|
19
|
+
export declare const User: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
package/dist/user.decorator.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
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 user_decorator_exports = {};
|
|
19
|
-
__export(user_decorator_exports, {
|
|
20
|
-
User: () => User,
|
|
21
|
-
userDecoratorFactory: () => userDecoratorFactory
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(user_decorator_exports);
|
|
24
|
-
var import_common = require("@nestjs/common");
|
|
25
|
-
var import_utils = require("./utils");
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = exports.userDecoratorFactory = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
26
6
|
const userDecoratorFactory = (_data, ctx) => {
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
const request = ctx.switchToHttp().getRequest();
|
|
8
|
+
return (0, utils_1.getPassportProperty)(request);
|
|
29
9
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
exports.userDecoratorFactory = userDecoratorFactory;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current user associated with the request, if available.
|
|
13
|
+
*
|
|
14
|
+
* ### Usage
|
|
15
|
+
*
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @UseGuards(AuthzGuard)
|
|
18
|
+
* @Controller(// ...)
|
|
19
|
+
* export class BusinessController {
|
|
20
|
+
* @Get()
|
|
21
|
+
* async method(@User() user: User) {
|
|
22
|
+
* // ...
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
exports.User = (0, common_1.createParamDecorator)(exports.userDecoratorFactory);
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Request } from 'express';
|
|
2
|
-
|
|
3
|
-
declare const normalCookieParser: (req: Request, _secrets?: string[], decode?: (str: string) => string | undefined) => {
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
export declare const normalCookieParser: (req: Request, _secrets?: string[], decode?: (str: string) => string | undefined) => {
|
|
4
3
|
cookies: Record<string, any>;
|
|
5
4
|
signedCookies: Record<string, any>;
|
|
6
5
|
};
|
|
7
|
-
declare const customCookieParser: (req: Request, secrets?: string[], decode?: (str: string) => string | undefined) => {
|
|
6
|
+
export declare const customCookieParser: (req: Request, secrets?: string[], decode?: (str: string) => string | undefined) => {
|
|
8
7
|
cookies: Record<string, any>;
|
|
9
8
|
signedCookies: Record<string, any>;
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
export { customCookieParser, normalCookieParser };
|
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
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 cookie_parsers_exports = {};
|
|
29
|
-
__export(cookie_parsers_exports, {
|
|
30
|
-
customCookieParser: () => customCookieParser,
|
|
31
|
-
normalCookieParser: () => normalCookieParser
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
32
17
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.customCookieParser = exports.normalCookieParser = void 0;
|
|
40
|
+
const cookie = __importStar(require("cookie"));
|
|
41
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
36
42
|
const normalCookieParser = (req, _secrets = [], decode) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
let cookies = req.cookies || {};
|
|
44
|
+
let signedCookies = req.signedCookies || {};
|
|
45
|
+
if (!req.cookies && req.headers.cookie) {
|
|
46
|
+
const parsedCookies = cookie.parse(req.headers.cookie, { decode });
|
|
47
|
+
if (req.secret) {
|
|
48
|
+
signedCookies = cookie_parser_1.default.JSONCookies(cookie_parser_1.default.signedCookies(parsedCookies, [req.secret]));
|
|
49
|
+
}
|
|
50
|
+
cookies = cookie_parser_1.default.JSONCookies(parsedCookies);
|
|
45
51
|
}
|
|
46
|
-
cookies
|
|
47
|
-
}
|
|
48
|
-
return { cookies, signedCookies };
|
|
52
|
+
return { cookies, signedCookies };
|
|
49
53
|
};
|
|
54
|
+
exports.normalCookieParser = normalCookieParser;
|
|
50
55
|
const customCookieParser = (req, secrets = [], decode) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
let cookies = {};
|
|
57
|
+
let signedCookies = {};
|
|
58
|
+
if (req.headers.cookie) {
|
|
59
|
+
const parsedCookies = cookie.parse(req.headers.cookie, {
|
|
60
|
+
decode
|
|
61
|
+
});
|
|
62
|
+
if (secrets.length) {
|
|
63
|
+
signedCookies = cookie_parser_1.default.JSONCookies(cookie_parser_1.default.signedCookies(parsedCookies, secrets));
|
|
64
|
+
}
|
|
65
|
+
cookies = cookie_parser_1.default.JSONCookies(parsedCookies);
|
|
61
66
|
}
|
|
62
|
-
cookies
|
|
63
|
-
}
|
|
64
|
-
return { cookies, signedCookies };
|
|
67
|
+
return { cookies, signedCookies };
|
|
65
68
|
};
|
|
66
|
-
|
|
67
|
-
0 && (module.exports = {
|
|
68
|
-
customCookieParser,
|
|
69
|
-
normalCookieParser
|
|
70
|
-
});
|
|
69
|
+
exports.customCookieParser = customCookieParser;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { AuthzProviderClass } from '../authz.provider
|
|
2
|
-
import { AuthzDecoParams, MethodParameters
|
|
3
|
-
|
|
4
|
-
import '@nestjs/common/interfaces';
|
|
5
|
-
import 'express';
|
|
6
|
-
|
|
7
|
-
declare const createAuthzDecoratorFactory: <T extends AuthzProviderClass<unknown, unknown>>(metaKey: string | Symbol) => (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|
|
8
|
-
|
|
9
|
-
export { createAuthzDecoratorFactory };
|
|
1
|
+
import { AuthzProviderClass } from '../authz.provider';
|
|
2
|
+
import type { ApplyDecorators, AuthzDecoParams, MethodParameters } from './types';
|
|
3
|
+
export declare const createAuthzDecoratorFactory: <T extends AuthzProviderClass<unknown, unknown>>(metaKey: string | Symbol) => (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|