@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.
- package/dist/authz.provider.d.ts +1 -3
- package/dist/authz.provider.js +29 -48
- package/dist/constants.d.ts +6 -8
- package/dist/constants.js +13 -46
- package/dist/errors.d.ts +3 -5
- package/dist/errors.js +35 -60
- 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 +138 -158
- 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 +44 -81
- package/dist/jwt/jwt-authz.guard.d.ts +8 -21
- package/dist/jwt/jwt-authz.guard.js +130 -175
- package/dist/jwt/jwt-authz.interface.d.ts +16 -25
- package/dist/jwt/jwt-authz.interface.js +69 -92
- package/dist/jwt/jwt-authz.module.d.ts +19 -31
- package/dist/jwt/jwt-authz.module.js +250 -299
- package/dist/jwt/jwt-authz.service.d.ts +6 -17
- package/dist/jwt/jwt-authz.service.js +116 -162
- package/dist/jwt/jwt-authz.strategy.d.ts +5 -17
- package/dist/jwt/jwt-authz.strategy.js +132 -192
- 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 +98 -130
- package/dist/session/session-authz.guard.d.ts +6 -15
- package/dist/session/session-authz.guard.js +98 -135
- package/dist/session/session-authz.interface.d.ts +5 -12
- package/dist/session/session-authz.interface.js +19 -42
- package/dist/session/session-authz.module.d.ts +18 -26
- package/dist/session/session-authz.module.js +241 -290
- package/dist/session/session-authz.service.d.ts +5 -13
- package/dist/session/session-authz.service.js +69 -105
- package/dist/session/session-authz.strategy.d.ts +4 -12
- package/dist/session/session-authz.strategy.js +68 -105
- package/dist/user.decorator.d.ts +3 -6
- package/dist/user.decorator.js +26 -35
- package/dist/utils/cookie-parsers.d.ts +3 -6
- package/dist/utils/cookie-parsers.js +66 -74
- package/dist/utils/create-authz-decorator-factory.d.ts +3 -9
- package/dist/utils/create-authz-decorator-factory.js +32 -54
- package/dist/utils/create-set-cookie-fn.d.ts +3 -9
- package/dist/utils/create-set-cookie-fn.js +23 -45
- package/dist/utils/generics.d.ts +4 -6
- package/dist/utils/generics.js +37 -63
- package/dist/utils/get-allow-anonymous.d.ts +2 -9
- package/dist/utils/get-allow-anonymous.js +7 -29
- package/dist/utils/get-als-store.d.ts +2 -5
- package/dist/utils/get-als-store.js +11 -34
- package/dist/utils/get-context-authz-meta-params-list.d.ts +2 -9
- package/dist/utils/get-context-authz-meta-params-list.js +16 -35
- package/dist/utils/get-passport-property.d.ts +1 -3
- package/dist/utils/get-passport-property.js +8 -30
- 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 +14 -49
- package/dist/utils/msgpackrs.d.ts +2 -4
- package/dist/utils/msgpackrs.js +11 -35
- package/dist/utils/types.d.ts +23 -26
- package/dist/utils/types.js +2 -15
- package/package.json +7 -7
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
-
import { AuthzProviderClass } from '../authz.provider.js';
|
|
3
|
-
import { CookieOptionsWithSecret, DeepReadonly } from '../utils/types.js';
|
|
4
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
8
|
-
import
|
|
9
|
-
import 'express-session';
|
|
10
|
-
|
|
11
|
-
declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, ALS_PROVIDER]: [any, any]) => _nestjs_common.Type<Omit<{
|
|
2
|
+
import { AuthzProviderClass } from '../authz.provider';
|
|
3
|
+
import { type DeepReadonly } from '../utils';
|
|
4
|
+
import type { SessionAlsType } from './session-authz-als.middleware';
|
|
5
|
+
export declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, ALS_PROVIDER]: [any, any]) => import("@nestjs/common").Type<Omit<{
|
|
12
6
|
readonly authzProvider: AuthzProviderClass<P, U>;
|
|
13
7
|
readonly als: AsyncLocalStorage<SessionAlsType<P, U>>;
|
|
14
8
|
/**
|
|
@@ -24,11 +18,9 @@ declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVI
|
|
|
24
18
|
/**
|
|
25
19
|
* Sets a secure HTTP cookie with the given name, value, and optional cookie options.
|
|
26
20
|
*/
|
|
27
|
-
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
21
|
+
setCookie(name: string, value: string, options?: import("../utils").CookieOptionsWithSecret | undefined): void;
|
|
28
22
|
/**
|
|
29
23
|
* Retrieves the current user associated with the request, if available.
|
|
30
24
|
*/
|
|
31
25
|
getUser(): DeepReadonly<U> | undefined;
|
|
32
26
|
}, "als" | "authzProvider">>;
|
|
33
|
-
|
|
34
|
-
export { createSessionAuthzService };
|
|
@@ -1,107 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
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
|
|
12
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
setCookie(...rest) {
|
|
81
|
-
const store = (0, import_utils.getAlsStore)(this.als);
|
|
82
|
-
store.setCookie(...rest);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Retrieves the current user associated with the request, if available.
|
|
86
|
-
*/
|
|
87
|
-
getUser() {
|
|
88
|
-
const store = (0, import_utils.getAlsStore)(this.als);
|
|
89
|
-
const user = store.user;
|
|
90
|
-
return user;
|
|
91
|
-
}
|
|
92
|
-
}, __name(_a, "SessionAuthzService"), _a);
|
|
93
|
-
SessionAuthzService = _ts_decorate([
|
|
94
|
-
_ts_param(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
|
|
95
|
-
_ts_param(1, (0, import_common.Inject)(ALS_PROVIDER)),
|
|
96
|
-
_ts_metadata("design:type", Function),
|
|
97
|
-
_ts_metadata("design:paramtypes", [
|
|
98
|
-
typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
|
|
99
|
-
typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage
|
|
100
|
-
])
|
|
101
|
-
], SessionAuthzService);
|
|
102
|
-
return (0, import_common.mixin)(SessionAuthzService);
|
|
103
|
-
}, "createSessionAuthzService");
|
|
104
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
-
0 && (module.exports = {
|
|
106
|
-
createSessionAuthzService
|
|
107
|
-
});
|
|
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.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");
|
|
21
|
+
const createSessionAuthzService = ([AUTHZ_PROVIDER, ALS_PROVIDER]) => {
|
|
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);
|
|
70
|
+
};
|
|
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,107 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
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
|
|
12
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
null,
|
|
80
|
-
error instanceof Error ? new import_errors.AuthzVerificationError(`${error.name}: ${error.message}`, error) : new import_errors.AuthzVerificationError(`${error}`)
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
store.user = user;
|
|
84
|
-
if (!user) {
|
|
85
|
-
return [
|
|
86
|
-
null,
|
|
87
|
-
new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find user.")
|
|
88
|
-
];
|
|
89
|
-
}
|
|
90
|
-
return user;
|
|
91
|
-
}
|
|
92
|
-
}, __name(_a, "SessionAuthzStrategy"), _a);
|
|
93
|
-
SessionAuthzStrategy = _ts_decorate([
|
|
94
|
-
_ts_param(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
|
|
95
|
-
_ts_param(1, (0, import_common.Inject)(ALS_PROVIDER)),
|
|
96
|
-
_ts_metadata("design:type", Function),
|
|
97
|
-
_ts_metadata("design:paramtypes", [
|
|
98
|
-
typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
|
|
99
|
-
typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage
|
|
100
|
-
])
|
|
101
|
-
], SessionAuthzStrategy);
|
|
102
|
-
return (0, import_common.mixin)(SessionAuthzStrategy);
|
|
103
|
-
}, "createSessionAuthzStrategy");
|
|
104
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
-
0 && (module.exports = {
|
|
106
|
-
createSessionAuthzStrategy
|
|
107
|
-
});
|
|
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.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");
|
|
24
|
+
const createSessionAuthzStrategy = ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
|
|
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);
|
|
69
|
+
};
|
|
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,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
6
|
+
const userDecoratorFactory = (_data, ctx) => {
|
|
7
|
+
const request = ctx.switchToHttp().getRequest();
|
|
8
|
+
return (0, utils_1.getPassportProperty)(request);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const request = ctx.switchToHttp().getRequest();
|
|
29
|
-
return (0, import_utils.getPassportProperty)(request);
|
|
30
|
-
}, "userDecoratorFactory");
|
|
31
|
-
const User = (0, import_common.createParamDecorator)(userDecoratorFactory);
|
|
32
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
User,
|
|
35
|
-
userDecoratorFactory
|
|
36
|
-
});
|
|
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 };
|