@nestjs-kitchen/authz 2.0.6 → 3.0.0
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/README.md +16 -0
- package/dist/jwt/jwt-authz-als.middleware.d.ts +2 -1
- package/dist/jwt/jwt-authz.guard.d.ts +5 -4
- package/dist/jwt/jwt-authz.interface.d.ts +9 -8
- package/dist/jwt/jwt-authz.module.d.ts +15 -14
- package/dist/jwt/jwt-authz.service.d.ts +4 -3
- package/dist/jwt/jwt-authz.strategy.d.ts +3 -2
- package/dist/session/session-authz-als.middleware.d.ts +2 -1
- package/dist/session/session-authz.guard.d.ts +2 -2
- package/dist/session/session-authz.interface.d.ts +1 -9
- package/dist/session/session-authz.interface.js +2 -7
- package/dist/session/session-authz.module.d.ts +13 -14
- package/dist/session/session-authz.module.js +1 -7
- package/dist/session/session-authz.service.d.ts +4 -3
- package/dist/session/session-authz.strategy.d.ts +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,6 +31,22 @@ Once completed NestJS project setup, install this package and its dependencies:
|
|
|
31
31
|
$ npm install --save @nestjs/passport passport @nestjs-kitchen/authz
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## Beark change
|
|
35
|
+
|
|
36
|
+
- From `@nestjs-kitchen/authz` **v3**, [`express-session`](https://www.npmjs.com/package/express-session) had been removed from dependency. Please setup session manually:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import * as session from 'express-session';
|
|
40
|
+
// somewhere in your initialization file
|
|
41
|
+
app.use(
|
|
42
|
+
session({
|
|
43
|
+
secret: 'my-secret',
|
|
44
|
+
resave: false,
|
|
45
|
+
saveUninitialized: false,
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
34
50
|
## Usage
|
|
35
51
|
|
|
36
52
|
1. Create file `authz.provider.ts`:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import type { NextFunction, Request, Response } from 'express';
|
|
3
4
|
import { JwtValidationType } from '../constants';
|
|
4
5
|
import { type CookieOptionsWithSecret } from '../utils';
|
|
@@ -11,7 +12,7 @@ export interface JwtAlsType<U> {
|
|
|
11
12
|
authOptions: JwtAuthzOptions;
|
|
12
13
|
setCookie: (name: string, value: string, options?: CookieOptionsWithSecret) => void;
|
|
13
14
|
}
|
|
14
|
-
export declare const createJwtAuthzAlsMiddleware: ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]: [any, any]) =>
|
|
15
|
+
export declare const createJwtAuthzAlsMiddleware: ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]: [any, any]) => Type<Omit<{
|
|
15
16
|
readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
|
|
16
17
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
17
18
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { ExecutionContext, type Type } from '@nestjs/common';
|
|
3
3
|
import { Reflector } from '@nestjs/core';
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
4
5
|
import { AuthzProviderClass } from '../authz.provider';
|
|
5
6
|
import { type AuthzError } from '../errors';
|
|
6
7
|
import type { JwtAlsType } from './jwt-authz-als.middleware';
|
|
7
8
|
import type { JwtAuthzOptions } from './jwt-authz.interface';
|
|
8
|
-
export declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]: [string, any, any, any, any, any]) =>
|
|
9
|
+
export declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]: [string, any, any, any, any, any]) => Type<Omit<{
|
|
9
10
|
readonly reflector: Reflector;
|
|
10
11
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
11
12
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
@@ -32,14 +33,14 @@ export declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AU
|
|
|
32
33
|
} = any>(request: TRequest): Promise<void>;
|
|
33
34
|
getRequest(context: ExecutionContext): any;
|
|
34
35
|
}, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">>;
|
|
35
|
-
export declare const createJwtRefreshAuthzGuard: ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]: [string, any]) =>
|
|
36
|
+
export declare const createJwtRefreshAuthzGuard: ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]: [string, any]) => Type<Omit<{
|
|
36
37
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
37
38
|
getAuthenticateOptions(): {
|
|
38
39
|
property: string;
|
|
39
40
|
session: boolean;
|
|
40
41
|
};
|
|
41
42
|
handleRequest<T>(_err: unknown, user: T, info?: AuthzError): T;
|
|
42
|
-
canActivate(context: ExecutionContext): boolean | Promise<boolean> |
|
|
43
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
43
44
|
logIn<TRequest extends {
|
|
44
45
|
logIn: Function;
|
|
45
46
|
} = any>(request: TRequest): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JsonWebKeyInput, KeyObject, PrivateKeyInput, PublicKeyInput } from 'node:crypto';
|
|
1
2
|
import { type PrivateKey, type PublicKey, type Secret, type SignOptions, type VerifyOptions } from 'jsonwebtoken';
|
|
2
3
|
import { type AuthzModuleBaseOptions } from '../utils';
|
|
3
4
|
import type { JwtFromRequestFunction } from './extract-jwt';
|
|
@@ -43,27 +44,27 @@ export declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOp
|
|
|
43
44
|
skipFalsyMetadata: boolean;
|
|
44
45
|
defaultAllowAnonymous: boolean;
|
|
45
46
|
jwt: {
|
|
46
|
-
secretOrPrivateKey: string | Buffer<ArrayBufferLike> |
|
|
47
|
+
secretOrPrivateKey: string | Buffer<ArrayBufferLike> | KeyObject | {
|
|
47
48
|
key: string | Buffer;
|
|
48
49
|
passphrase: string;
|
|
49
|
-
} |
|
|
50
|
-
secretOrPublicKey: string | Buffer<ArrayBufferLike> |
|
|
50
|
+
} | PrivateKeyInput | JsonWebKeyInput | null;
|
|
51
|
+
secretOrPublicKey: string | Buffer<ArrayBufferLike> | KeyObject | {
|
|
51
52
|
key: string | Buffer;
|
|
52
53
|
passphrase: string;
|
|
53
|
-
} |
|
|
54
|
+
} | JsonWebKeyInput | PublicKeyInput | null;
|
|
54
55
|
jwtFromRequest: JwtFromRequestFunction<any>[];
|
|
55
56
|
sign: SignOptions;
|
|
56
57
|
verify: VerifyOptions;
|
|
57
58
|
};
|
|
58
59
|
refresh: {
|
|
59
|
-
secretOrPrivateKey: string | Buffer<ArrayBufferLike> |
|
|
60
|
+
secretOrPrivateKey: string | Buffer<ArrayBufferLike> | KeyObject | {
|
|
60
61
|
key: string | Buffer;
|
|
61
62
|
passphrase: string;
|
|
62
|
-
} |
|
|
63
|
-
secretOrPublicKey: string | Buffer<ArrayBufferLike> |
|
|
63
|
+
} | PrivateKeyInput | JsonWebKeyInput | null;
|
|
64
|
+
secretOrPublicKey: string | Buffer<ArrayBufferLike> | KeyObject | {
|
|
64
65
|
key: string | Buffer;
|
|
65
66
|
passphrase: string;
|
|
66
|
-
} |
|
|
67
|
+
} | JsonWebKeyInput | PublicKeyInput | null;
|
|
67
68
|
jwtFromRequest: JwtFromRequestFunction<any>[];
|
|
68
69
|
sign: SignOptions;
|
|
69
70
|
verify: VerifyOptions;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { DynamicModule, MiddlewareConsumer, type Type } from '@nestjs/common';
|
|
2
|
+
import { type ConfigurableModuleAsyncOptions, DynamicModule, type ExecutionContext, MiddlewareConsumer, type Type } from '@nestjs/common';
|
|
3
|
+
import type { Reflector } from '@nestjs/core';
|
|
3
4
|
import { AuthzProviderClass } from '../authz.provider';
|
|
4
5
|
import { AuthzError } from '../errors';
|
|
5
|
-
import { type AbstractConstructor, type ApplyDecorators, type AuthzModuleRoutesOptions, type RoutesOptions } from '../utils';
|
|
6
|
+
import { type AbstractConstructor, type ApplyDecorators, type AuthzDecoParams, type AuthzModuleBaseOptions, type AuthzModuleRoutesOptions, type CookieOptionsWithSecret, type DeepReadonly, type MethodParameters, type RoutesOptions } from '../utils';
|
|
6
7
|
import { type JwtAlsType } from './jwt-authz-als.middleware';
|
|
7
|
-
import { type JwtAuthzModuleOptions, type JwtAuthzOptions } from './jwt-authz.interface';
|
|
8
|
-
declare const ASYNC_OPTIONS_TYPE:
|
|
8
|
+
import { type JwtAuthzModuleOptions, type JwtAuthzOptions, type JwtOptions } from './jwt-authz.interface';
|
|
9
|
+
declare const ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<JwtAuthzModuleOptions, "createJwtAuthzModuleOptions"> & Partial<{
|
|
9
10
|
authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
|
|
10
|
-
} & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<
|
|
11
|
-
jwt:
|
|
12
|
-
refresh?:
|
|
11
|
+
} & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
|
|
12
|
+
jwt: JwtOptions;
|
|
13
|
+
refresh?: JwtOptions;
|
|
13
14
|
} & Partial<{
|
|
14
15
|
authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
|
|
15
16
|
} & AuthzModuleRoutesOptions>;
|
|
@@ -92,7 +93,7 @@ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P
|
|
|
92
93
|
* ```
|
|
93
94
|
*/
|
|
94
95
|
AuthzGuard: Type<Omit<{
|
|
95
|
-
readonly reflector:
|
|
96
|
+
readonly reflector: Reflector;
|
|
96
97
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
97
98
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
98
99
|
readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
|
|
@@ -101,11 +102,11 @@ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P
|
|
|
101
102
|
session: boolean;
|
|
102
103
|
};
|
|
103
104
|
handleRequest<T_1>(_err: unknown, user: T_1, info?: AuthzError): T_1;
|
|
104
|
-
canActivate(context:
|
|
105
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
105
106
|
logIn<TRequest extends {
|
|
106
107
|
logIn: Function;
|
|
107
108
|
} = any>(request: TRequest): Promise<void>;
|
|
108
|
-
getRequest(context:
|
|
109
|
+
getRequest(context: ExecutionContext): any;
|
|
109
110
|
}, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">> & {
|
|
110
111
|
/**
|
|
111
112
|
* Verifies the user's authorization for specific meta data.
|
|
@@ -124,7 +125,7 @@ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P
|
|
|
124
125
|
* }
|
|
125
126
|
* ```
|
|
126
127
|
*/
|
|
127
|
-
Verify: (...args:
|
|
128
|
+
Verify: (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|
|
128
129
|
/**
|
|
129
130
|
* Skips authentication & authorization checks for specific routes.
|
|
130
131
|
*
|
|
@@ -177,7 +178,7 @@ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P
|
|
|
177
178
|
* }
|
|
178
179
|
* ```
|
|
179
180
|
*/
|
|
180
|
-
Apply: (...rest: Parameters<(...args:
|
|
181
|
+
Apply: (...rest: Parameters<(...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
181
182
|
};
|
|
182
183
|
/**
|
|
183
184
|
* A custom servcie to provide methods to handle authentication and authorization.
|
|
@@ -196,8 +197,8 @@ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P
|
|
|
196
197
|
refresh(user?: U | undefined): Promise<{
|
|
197
198
|
token: string;
|
|
198
199
|
} | undefined>;
|
|
199
|
-
setCookie(name: string, value: string, options?:
|
|
200
|
-
getUser():
|
|
200
|
+
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
201
|
+
getUser(): DeepReadonly<U> | undefined;
|
|
201
202
|
}, "als" | "jwtAuthzOptions" | "authzProvider">>;
|
|
202
203
|
};
|
|
203
204
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import { AuthzProviderClass } from '../authz.provider';
|
|
3
|
-
import { type DeepReadonly } from '../utils';
|
|
4
|
+
import { type CookieOptionsWithSecret, type DeepReadonly } from '../utils';
|
|
4
5
|
import type { JwtAlsType } from './jwt-authz-als.middleware';
|
|
5
6
|
import type { JwtAuthzOptions } from './jwt-authz.interface';
|
|
6
|
-
export declare const createJwtAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]: [any, any, any]) =>
|
|
7
|
+
export declare const createJwtAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]: [any, any, any]) => Type<Omit<{
|
|
7
8
|
readonly authzProvider: AuthzProviderClass<P, U>;
|
|
8
9
|
readonly jwtAuthzOptions: JwtAuthzOptions;
|
|
9
10
|
readonly als: AsyncLocalStorage<JwtAlsType<U>>;
|
|
@@ -35,7 +36,7 @@ export declare const createJwtAuthzService: <P = unknown, U = unknown>([AUTHZ_PR
|
|
|
35
36
|
/**
|
|
36
37
|
* Sets a secure HTTP cookie with the given name, value, and optional cookie options.
|
|
37
38
|
*/
|
|
38
|
-
setCookie(name: string, value: string, options?:
|
|
39
|
+
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
39
40
|
/**
|
|
40
41
|
* Retrieves the current user associated with the request, if available.
|
|
41
42
|
*/
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import type { Request } from 'express';
|
|
3
4
|
import { AuthzProviderClass } from '../authz.provider';
|
|
4
5
|
import type { JwtAlsType } from './jwt-authz-als.middleware';
|
|
5
|
-
export declare const createJwtStrategy: ([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) =>
|
|
6
|
+
export declare const createJwtStrategy: ([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => Type<Omit<{
|
|
6
7
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
7
8
|
readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
|
|
8
9
|
validate(req: Request): Promise<{}>;
|
|
9
10
|
authenticate(req: Request, options?: any): any;
|
|
10
11
|
}, "als" | "authzProvider">>;
|
|
11
|
-
export declare const createRefreshStrategy: ([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) =>
|
|
12
|
+
export declare const createRefreshStrategy: ([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => Type<Omit<{
|
|
12
13
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
13
14
|
readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
|
|
14
15
|
validate(req: Request): Promise<{}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import type { NextFunction, Request, Response } from 'express';
|
|
3
4
|
import { type CookieOptionsWithSecret } from '../utils';
|
|
4
5
|
import type { SessionAuthzOptions } from './session-authz.interface';
|
|
@@ -11,7 +12,7 @@ export interface SessionAlsType<P, U> {
|
|
|
11
12
|
logOut: () => Promise<void>;
|
|
12
13
|
setCookie: (name: string, value: string, options?: CookieOptionsWithSecret) => void;
|
|
13
14
|
}
|
|
14
|
-
export declare const createSessionAuthzAlsMiddleware: ([ALS_PROVIDER, SESSION_AUTHZ_OPTIONS]: [any, any]) =>
|
|
15
|
+
export declare const createSessionAuthzAlsMiddleware: ([ALS_PROVIDER, SESSION_AUTHZ_OPTIONS]: [any, any]) => Type<Omit<{
|
|
15
16
|
readonly als: AsyncLocalStorage<SessionAlsType<unknown, unknown>>;
|
|
16
17
|
readonly sessionAuthzOptions: SessionAuthzOptions;
|
|
17
18
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ExecutionContext } from '@nestjs/common';
|
|
1
|
+
import { ExecutionContext, type Type } from '@nestjs/common';
|
|
2
2
|
import { Reflector } from '@nestjs/core';
|
|
3
3
|
import type { AsyncLocalStorage } from 'async_hooks';
|
|
4
4
|
import { AuthzProviderClass } from '../authz.provider';
|
|
5
5
|
import { type AuthzError } from '../errors';
|
|
6
6
|
import type { SessionAlsType } from './session-authz-als.middleware';
|
|
7
7
|
import type { SessionAuthzOptions } from './session-authz.interface';
|
|
8
|
-
export declare const createSessionAuthzGuard: ([SESSION_STRATEGY, AUTHZ_PROVIDER, SESSION_AUTHZ_OPTIONS, ALS_PROVIDER, SESSION_META_KEY]: [string, any, any, any, any]) =>
|
|
8
|
+
export declare const createSessionAuthzGuard: ([SESSION_STRATEGY, AUTHZ_PROVIDER, SESSION_AUTHZ_OPTIONS, ALS_PROVIDER, SESSION_META_KEY]: [string, any, any, any, any]) => Type<Omit<{
|
|
9
9
|
readonly reflector: Reflector;
|
|
10
10
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
11
11
|
readonly sessionAuthzOptions: SessionAuthzOptions;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import session from 'express-session';
|
|
2
1
|
import type { AuthzModuleBaseOptions } from '../utils';
|
|
3
|
-
export type SessionOptions = Parameters<typeof session>[0];
|
|
4
2
|
export type SessionAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
|
|
5
|
-
|
|
6
|
-
* Session options.
|
|
7
|
-
*
|
|
8
|
-
* Same as `express-session` [session options](https://www.npmjs.com/package/express-session#options).
|
|
9
|
-
*/
|
|
10
|
-
session: SessionOptions & {
|
|
3
|
+
session?: {
|
|
11
4
|
/**
|
|
12
5
|
* Option to keep session information after regenerating.
|
|
13
6
|
*
|
|
@@ -22,6 +15,5 @@ export declare const normalizedSessionAuthzModuleOptions: (options?: Partial<Ses
|
|
|
22
15
|
skipFalsyMetadata: boolean;
|
|
23
16
|
defaultAllowAnonymous: boolean;
|
|
24
17
|
keepSessionInfo: boolean | undefined;
|
|
25
|
-
session: SessionOptions;
|
|
26
18
|
};
|
|
27
19
|
export type SessionAuthzOptions = ReturnType<typeof normalizedSessionAuthzModuleOptions>;
|
|
@@ -3,18 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.normalizedSessionAuthzModuleOptions = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const normalizedSessionAuthzModuleOptions = (options = {}) => {
|
|
6
|
-
const { keepSessionInfo
|
|
6
|
+
const { keepSessionInfo } = options.session ?? {};
|
|
7
7
|
return {
|
|
8
8
|
defaultOverride: options.defaultOverride || false,
|
|
9
9
|
passportProperty: options.passportProperty || constants_1.DEFAULT_PASSPORT_PROPERTY_VALUE,
|
|
10
10
|
skipFalsyMetadata: options.skipFalsyMetadata || false,
|
|
11
11
|
defaultAllowAnonymous: options.defaultAllowAnonymous || false,
|
|
12
|
-
keepSessionInfo
|
|
13
|
-
session: {
|
|
14
|
-
resave: false,
|
|
15
|
-
saveUninitialized: false,
|
|
16
|
-
...sessionOpts
|
|
17
|
-
}
|
|
12
|
+
keepSessionInfo
|
|
18
13
|
};
|
|
19
14
|
};
|
|
20
15
|
exports.normalizedSessionAuthzModuleOptions = normalizedSessionAuthzModuleOptions;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { DynamicModule, MiddlewareConsumer, type Type } from '@nestjs/common';
|
|
2
|
+
import { type ConfigurableModuleAsyncOptions, DynamicModule, type ExecutionContext, MiddlewareConsumer, type Type } from '@nestjs/common';
|
|
3
|
+
import type { Reflector } from '@nestjs/core';
|
|
3
4
|
import { AuthzProviderClass } from '../authz.provider';
|
|
4
5
|
import { AuthzError } from '../errors';
|
|
5
|
-
import { type AbstractConstructor, type AuthzModuleRoutesOptions, type RoutesOptions } from '../utils';
|
|
6
|
+
import { type AbstractConstructor, type ApplyDecorators, type AuthzDecoParams, type AuthzModuleBaseOptions, type AuthzModuleRoutesOptions, type CookieOptionsWithSecret, type DeepReadonly, type MethodParameters, type RoutesOptions } from '../utils';
|
|
6
7
|
import { type SessionAlsType } from './session-authz-als.middleware';
|
|
7
8
|
import { type SessionAuthzModuleOptions, type SessionAuthzOptions } from './session-authz.interface';
|
|
8
|
-
declare const ASYNC_OPTIONS_TYPE:
|
|
9
|
+
declare const ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<SessionAuthzModuleOptions, "createSessionAuthzModuleOptions"> & Partial<{
|
|
9
10
|
authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
|
|
10
|
-
} & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<
|
|
11
|
-
session
|
|
11
|
+
} & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
|
|
12
|
+
session?: {
|
|
12
13
|
keepSessionInfo?: boolean;
|
|
13
14
|
};
|
|
14
15
|
} & Partial<{
|
|
@@ -60,13 +61,11 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
60
61
|
/**
|
|
61
62
|
* Configures authz module.
|
|
62
63
|
*
|
|
63
|
-
* Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
|
|
64
64
|
*/
|
|
65
65
|
register(options: Omit<typeof OPTIONS_TYPE, "authzProvider">): DynamicModule;
|
|
66
66
|
/**
|
|
67
67
|
* Configures authz module asynchronously.
|
|
68
68
|
*
|
|
69
|
-
* Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
|
|
70
69
|
*/
|
|
71
70
|
registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
72
71
|
};
|
|
@@ -90,7 +89,7 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
90
89
|
* ```
|
|
91
90
|
*/
|
|
92
91
|
AuthzGuard: Type<Omit<{
|
|
93
|
-
readonly reflector:
|
|
92
|
+
readonly reflector: Reflector;
|
|
94
93
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
95
94
|
readonly sessionAuthzOptions: SessionAuthzOptions;
|
|
96
95
|
readonly als: AsyncLocalStorage<SessionAlsType<unknown, unknown>>;
|
|
@@ -99,11 +98,11 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
99
98
|
session: boolean;
|
|
100
99
|
};
|
|
101
100
|
handleRequest<T_1>(_err: unknown, user: T_1, info?: AuthzError): T_1;
|
|
102
|
-
canActivate(context:
|
|
101
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
103
102
|
logIn<TRequest extends {
|
|
104
103
|
logIn: Function;
|
|
105
104
|
} = any>(request: TRequest): Promise<void>;
|
|
106
|
-
getRequest(context:
|
|
105
|
+
getRequest(context: ExecutionContext): any;
|
|
107
106
|
}, "als" | "reflector" | "authzProvider" | "sessionAuthzOptions">> & {
|
|
108
107
|
/**
|
|
109
108
|
* Verifies the user's authorization for specific meta data.
|
|
@@ -122,7 +121,7 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
122
121
|
* }
|
|
123
122
|
* ```
|
|
124
123
|
*/
|
|
125
|
-
Verify: (...args:
|
|
124
|
+
Verify: (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
|
|
126
125
|
/**
|
|
127
126
|
* Skips authentication & authorization checks for specific routes.
|
|
128
127
|
*
|
|
@@ -157,7 +156,7 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
157
156
|
* }
|
|
158
157
|
* ```
|
|
159
158
|
*/
|
|
160
|
-
Apply: (...rest: Parameters<(...args:
|
|
159
|
+
Apply: (...rest: Parameters<(...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
161
160
|
};
|
|
162
161
|
/**
|
|
163
162
|
* A custom servcie to provide methods to handle authentication and authorization.
|
|
@@ -167,8 +166,8 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
|
|
|
167
166
|
readonly als: AsyncLocalStorage<SessionAlsType<P, U>>;
|
|
168
167
|
logIn(user: U): Promise<void>;
|
|
169
168
|
logOut(): Promise<void>;
|
|
170
|
-
setCookie(name: string, value: string, options?:
|
|
171
|
-
getUser():
|
|
169
|
+
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
170
|
+
getUser(): DeepReadonly<U> | undefined;
|
|
172
171
|
}, "als" | "authzProvider">>;
|
|
173
172
|
};
|
|
174
173
|
export {};
|
|
@@ -11,14 +11,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.cereateSessionAuthzModule = void 0;
|
|
19
16
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
20
17
|
const common_1 = require("@nestjs/common");
|
|
21
|
-
const express_session_1 = __importDefault(require("express-session"));
|
|
22
18
|
const uid_1 = require("uid");
|
|
23
19
|
const constants_1 = require("../constants");
|
|
24
20
|
const errors_1 = require("../errors");
|
|
@@ -141,7 +137,6 @@ const cereateSessionAuthzModule = (authzProvider) => {
|
|
|
141
137
|
/**
|
|
142
138
|
* Configures authz module.
|
|
143
139
|
*
|
|
144
|
-
* Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
|
|
145
140
|
*/
|
|
146
141
|
static register(options) {
|
|
147
142
|
const sessionAuthzOptions = (0, session_authz_interface_1.normalizedSessionAuthzModuleOptions)(options);
|
|
@@ -157,7 +152,6 @@ const cereateSessionAuthzModule = (authzProvider) => {
|
|
|
157
152
|
/**
|
|
158
153
|
* Configures authz module asynchronously.
|
|
159
154
|
*
|
|
160
|
-
* Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
|
|
161
155
|
*/
|
|
162
156
|
static registerAsync(options) {
|
|
163
157
|
return (0, utils_1.mergeDynamicModuleConfigs)(super.registerAsync({ ...options, authzProvider }), getCommonConfigs(), {
|
|
@@ -179,7 +173,7 @@ const cereateSessionAuthzModule = (authzProvider) => {
|
|
|
179
173
|
}
|
|
180
174
|
configure(consumer) {
|
|
181
175
|
consumer
|
|
182
|
-
.apply(
|
|
176
|
+
.apply(SessionAuthzAlsMiddleware)
|
|
183
177
|
.exclude(...this.routesOpt.excludes)
|
|
184
178
|
// nestjs v11 will be compatible with splat wildcard.
|
|
185
179
|
.forRoutes(...(this.routesOpt.global ? ['*'] : this.routesOpt.routes));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import { AuthzProviderClass } from '../authz.provider';
|
|
3
|
-
import { type DeepReadonly } from '../utils';
|
|
4
|
+
import { type CookieOptionsWithSecret, type DeepReadonly } from '../utils';
|
|
4
5
|
import type { SessionAlsType } from './session-authz-als.middleware';
|
|
5
|
-
export declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, ALS_PROVIDER]: [any, any]) =>
|
|
6
|
+
export declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTHZ_PROVIDER, ALS_PROVIDER]: [any, any]) => Type<Omit<{
|
|
6
7
|
readonly authzProvider: AuthzProviderClass<P, U>;
|
|
7
8
|
readonly als: AsyncLocalStorage<SessionAlsType<P, U>>;
|
|
8
9
|
/**
|
|
@@ -18,7 +19,7 @@ export declare const createSessionAuthzService: <P = unknown, U = unknown>([AUTH
|
|
|
18
19
|
/**
|
|
19
20
|
* Sets a secure HTTP cookie with the given name, value, and optional cookie options.
|
|
20
21
|
*/
|
|
21
|
-
setCookie(name: string, value: string, options?:
|
|
22
|
+
setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
|
|
22
23
|
/**
|
|
23
24
|
* Retrieves the current user associated with the request, if available.
|
|
24
25
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { type Type } from '@nestjs/common';
|
|
2
3
|
import type { Request } from 'express';
|
|
3
4
|
import { AuthzProviderClass } from '../authz.provider';
|
|
4
5
|
import type { SessionAlsType } from './session-authz-als.middleware';
|
|
5
|
-
export declare const createSessionAuthzStrategy: ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) =>
|
|
6
|
+
export declare const createSessionAuthzStrategy: ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]: [string, any, any]) => Type<Omit<{
|
|
6
7
|
readonly authzProvider: AuthzProviderClass<unknown, unknown>;
|
|
7
8
|
readonly als: AsyncLocalStorage<SessionAlsType<unknown, unknown>>;
|
|
8
9
|
validate(req: Request): Promise<{}>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@nestjs-kitchen/authz",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "Simplest authentication & authorization module in NextJS",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "3.0.0",
|
|
6
6
|
"homepage": "https://github.com/yikenman/nestjs-kitchen",
|
|
7
7
|
"repository": "https://github.com/yikenman/nestjs-kitchen",
|
|
8
8
|
"author": "yikenman",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"cookie": "^1.0.2",
|
|
22
22
|
"cookie-parser": "^1.4.7",
|
|
23
|
-
"express-session": "^1.18.1",
|
|
24
23
|
"jsonwebtoken": "^9.0.2",
|
|
25
24
|
"msgpackr": "^1.11.2",
|
|
26
25
|
"passport-custom": "^1.1.1",
|
|
@@ -36,6 +35,7 @@
|
|
|
36
35
|
"@types/node": "^22.13.9",
|
|
37
36
|
"@types/passport": "^1.0.17",
|
|
38
37
|
"@types/supertest": "^6.0.2",
|
|
38
|
+
"express-session": "^1.18.1",
|
|
39
39
|
"jest": "^29.7.0",
|
|
40
40
|
"rimraf": "^6.0.1",
|
|
41
41
|
"supertest": "^7.1.0",
|