@nathapp/nestjs-auth 2.1.5 → 3.0.0-rc.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/CLAUDE.md +29 -0
- package/dist/auth-provider.js.map +1 -1
- package/dist/auth.module.d.ts +17 -0
- package/dist/auth.module.js +109 -0
- package/dist/auth.module.js.map +1 -0
- package/dist/authentication/auth.module.d.ts +49 -0
- package/dist/authentication/auth.module.js +252 -0
- package/dist/authentication/auth.module.js.map +1 -0
- package/dist/authentication/index.d.ts +8 -0
- package/dist/authentication/index.js +25 -0
- package/dist/authentication/index.js.map +1 -0
- package/dist/authorization/authorization.module.d.ts +32 -0
- package/dist/authorization/authorization.module.js +145 -0
- package/dist/authorization/authorization.module.js.map +1 -0
- package/dist/authorization/index.d.ts +5 -0
- package/dist/authorization/index.js +22 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/casl/casl-ability-factory.js.map +1 -1
- package/dist/constant/jwt-constant.js.map +1 -1
- package/dist/constant/module-constant.js.map +1 -1
- package/dist/decorator/is-public.decorator.js.map +1 -1
- package/dist/decorator/permission.decorator.js.map +1 -1
- package/dist/decorator/principal.decorator.js.map +1 -1
- package/dist/decorator/refresh-token.decorator.js.map +1 -1
- package/dist/guard/jwt-auth.guard.js +1 -8
- package/dist/guard/jwt-auth.guard.js.map +1 -1
- package/dist/guard/jwt-refresh.guard.d.ts +1 -0
- package/dist/guard/jwt-refresh.guard.js +8 -2
- package/dist/guard/jwt-refresh.guard.js.map +1 -1
- package/dist/guard/permission-auth.guard.js +1 -1
- package/dist/guard/permission-auth.guard.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/module/jwt-module.js.map +1 -1
- package/dist/permission/permission.provider.js +25 -3
- package/dist/permission/permission.provider.js.map +1 -1
- package/dist/strategy/base-jwt-strategy-provider.d.ts +19 -0
- package/dist/strategy/base-jwt-strategy-provider.js +54 -0
- package/dist/strategy/base-jwt-strategy-provider.js.map +1 -0
- package/dist/strategy/index.d.ts +4 -3
- package/dist/strategy/index.js +3 -1
- package/dist/strategy/index.js.map +1 -1
- package/dist/strategy/jwt-refresh-strategy-provider.d.ts +4 -17
- package/dist/strategy/jwt-refresh-strategy-provider.js +5 -38
- package/dist/strategy/jwt-refresh-strategy-provider.js.map +1 -1
- package/dist/strategy/jwt-refresh-strategy.js.map +1 -1
- package/dist/strategy/jwt-strategy-provider.d.ts +4 -18
- package/dist/strategy/jwt-strategy-provider.js +5 -38
- package/dist/strategy/jwt-strategy-provider.js.map +1 -1
- package/dist/strategy/jwt-strategy.js.map +1 -1
- package/dist/strategy/strategy-provider.d.ts +2 -10
- package/dist/strategy/strategy-provider.js.map +1 -1
- package/dist/strategy/type-interface.d.ts +11 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +6 -6
- package/dist/utils/utils.js.map +1 -1
- package/docs/20260214-fix-plan-auth-module-split.md +148 -0
- package/docs/20260214-fix-plan-auth-security.md +130 -0
- package/docs/20260214-review-auth-enterprise.md +186 -0
- package/docs/20260214-review-auth.md +300 -0
- package/docs/20260215-review-auth-post-fix.md +519 -0
- package/package.json +3 -3
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultJwtRefreshStrategyProvider = exports.JwtRefreshStrategyProvider = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class JwtRefreshStrategyProvider {
|
|
4
|
+
const base_jwt_strategy_provider_1 = require("./base-jwt-strategy-provider");
|
|
5
|
+
class JwtRefreshStrategyProvider extends base_jwt_strategy_provider_1.BaseJwtStrategyProvider {
|
|
7
6
|
constructor(jwtOptions) {
|
|
8
|
-
|
|
7
|
+
super(jwtOptions, {
|
|
9
8
|
bindIp: false,
|
|
10
9
|
allowDuplicateLogin: false,
|
|
11
10
|
checkBlacklisted: false,
|
|
@@ -14,40 +13,8 @@ class JwtRefreshStrategyProvider {
|
|
|
14
13
|
isBase64AsymmetricKey: false,
|
|
15
14
|
signOption: {
|
|
16
15
|
expiresIn: "7h",
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
this.jwtOptions = Object.assign({}, extraOptions, jwtOptions);
|
|
20
|
-
this.jwtProvider = (0, utils_1.createJwtProvider)(jwtOptions);
|
|
21
|
-
this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
|
|
22
|
-
this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
|
|
23
|
-
this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
|
|
24
|
-
this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
|
|
25
|
-
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
26
|
-
}
|
|
27
|
-
getStrategyOptions() {
|
|
28
|
-
const partialOptions = {
|
|
29
|
-
ignoreExpiration: this.ignoreExpiration,
|
|
30
|
-
};
|
|
31
|
-
if (this.passReqToCallback) {
|
|
32
|
-
return {
|
|
33
|
-
...partialOptions,
|
|
34
|
-
jwtFromRequest: this.jwtFromRequestFunction,
|
|
35
|
-
secretOrKey: this.secretOrPublicKey,
|
|
36
|
-
passReqToCallback: true
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...partialOptions,
|
|
41
|
-
jwtFromRequest: this.jwtFromRequestFunction,
|
|
42
|
-
secretOrKey: this.secretOrPublicKey,
|
|
43
|
-
passReqToCallback: false,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
sign(payload) {
|
|
47
|
-
return this.jwtProvider.sign(payload);
|
|
48
|
-
}
|
|
49
|
-
verify(token, verifyOption) {
|
|
50
|
-
return this.jwtProvider.verify(token, verifyOption);
|
|
16
|
+
},
|
|
17
|
+
});
|
|
51
18
|
}
|
|
52
19
|
}
|
|
53
20
|
exports.JwtRefreshStrategyProvider = JwtRefreshStrategyProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-refresh-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/jwt-refresh-strategy-provider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"jwt-refresh-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/jwt-refresh-strategy-provider.ts"],"names":[],"mappings":";;;AAEA,6EAAuE;AAEvE,MAAsB,0BAA2B,SAAQ,oDAAuB;IAC9E,YAAY,UAAsB;QAChC,KAAK,CAAC,UAAU,EAAE;YAChB,MAAM,EAAE,KAAK;YACb,mBAAmB,EAAE,KAAK;YAC1B,gBAAgB,EAAE,KAAK;YACvB,gBAAgB,EAAE,KAAK;YACvB,iBAAiB,EAAE,IAAI;YACvB,qBAAqB,EAAE,KAAK;YAC5B,UAAU,EAAE;gBACV,SAAS,EAAE,IAAI;aAChB;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAdD,gEAcC;AA0BD,MAAa,iCAAkC,SAAQ,0BAA0B;IAE/E,YAAY,UAAsB;QAChC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpB,CAAC;IAED,QAAQ,CAAiB,GAAQ,EAAE,OAAmB;QACpD,MAAM,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,EAAE,EAAE,OAAO,CAAC,GAAG;YACf,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,KAAK;YAClB,OAAO,EAAE,KAAK;YACd,YAAY;YACZ,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE;SAC3B,CAAC,CAAC;IACjB,CAAC;CAEF;AAnBD,8EAmBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-refresh-strategy.js","sourceRoot":"","sources":["../../lib/strategy/jwt-refresh-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAoD;AACpD,+CAAwC;AACxC,2CAA4C;AAC5C,2DAAqE;AACrE,mFAA6E;
|
|
1
|
+
{"version":3,"file":"jwt-refresh-strategy.js","sourceRoot":"","sources":["../../lib/strategy/jwt-refresh-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAoD;AACpD,+CAAwC;AACxC,2CAA4C;AAC5C,2DAAqE;AACrE,mFAA6E;AAStE,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,EAAE,wCAAyB,CAAC;IAC3F,YAA6B,gBAA4C;QAEvE,KAAK,CAAC,gBAAgB,CAAC,kBAAkB,EAAS,CAAC,CAAC;QAFzB,qBAAgB,GAAhB,gBAAgB,CAA4B;IAGzE,CAAC;IASD,KAAK,CAAC,QAAQ,CAAC,IAAS,EAAE,IAAS;QACjC,MAAM,GAAG,GAAQ,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,OAAO,GAAQ,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAE3E,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AAnBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAEoC,0DAA0B;GAD9D,kBAAkB,CAmB9B"}
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
import { JwtFromRequestFunction, StrategyOptionsWithRequest, StrategyOptionsWithoutRequest } from "passport-jwt";
|
|
2
1
|
import { IPrincipal, AuthProvider } from "../auth-provider";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export declare abstract class JwtStrategyProvider implements StrategyProvider {
|
|
7
|
-
protected readonly jwtOptions: JwtOptions;
|
|
8
|
-
private readonly jwtProvider;
|
|
9
|
-
readonly secretOrPrivateKey: jwt.Secret;
|
|
10
|
-
readonly secretOrPublicKey: jwt.Secret;
|
|
11
|
-
readonly jwtFromRequestFunction: JwtFromRequestFunction;
|
|
12
|
-
readonly ignoreExpiration: boolean;
|
|
13
|
-
readonly passReqToCallback: boolean;
|
|
2
|
+
import { JwtOptions, JwtPayload, Req } from "./type-interface";
|
|
3
|
+
import { BaseJwtStrategyProvider } from "./base-jwt-strategy-provider";
|
|
4
|
+
export declare abstract class JwtStrategyProvider extends BaseJwtStrategyProvider {
|
|
14
5
|
constructor(jwtOptions: JwtOptions);
|
|
15
|
-
getStrategyOptions(): StrategyOptionsWithRequest | StrategyOptionsWithoutRequest;
|
|
16
|
-
sign(payload: string | object | Buffer): string;
|
|
17
|
-
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
18
|
-
abstract validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
19
|
-
abstract validate<T>(req: Req, payload: any): T | Promise<T>;
|
|
20
6
|
}
|
|
21
7
|
export declare class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
22
8
|
private readonly authProvider;
|
|
23
9
|
private readonly logger;
|
|
24
10
|
constructor(jwtOptions: JwtOptions, authProvider: AuthProvider);
|
|
25
|
-
validate(req: Req, payload:
|
|
11
|
+
validate<T = IPrincipal>(req: Req, payload: JwtPayload): Promise<T>;
|
|
26
12
|
}
|
|
27
13
|
export declare class SimpleJwtStrategyProvider extends DefaultJwtStrategyProvider {
|
|
28
14
|
constructor(jwtOptions: JwtOptions);
|
|
@@ -3,51 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SimpleJwtStrategyProvider = exports.DefaultJwtStrategyProvider = exports.JwtStrategyProvider = void 0;
|
|
4
4
|
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const passport_jwt_1 = require("passport-jwt");
|
|
7
6
|
const auth_provider_1 = require("../auth-provider");
|
|
8
|
-
const
|
|
9
|
-
class JwtStrategyProvider {
|
|
7
|
+
const base_jwt_strategy_provider_1 = require("./base-jwt-strategy-provider");
|
|
8
|
+
class JwtStrategyProvider extends base_jwt_strategy_provider_1.BaseJwtStrategyProvider {
|
|
10
9
|
constructor(jwtOptions) {
|
|
11
|
-
|
|
10
|
+
super(jwtOptions, {
|
|
12
11
|
bindIp: false,
|
|
13
12
|
allowDuplicateLogin: true,
|
|
14
13
|
checkBlacklisted: true,
|
|
15
14
|
ignoreExpiration: false,
|
|
16
15
|
passReqToCallback: true,
|
|
17
|
-
isBase64AsymmetricKey: false
|
|
18
|
-
};
|
|
19
|
-
this.jwtOptions = Object.assign({}, extraOptions, jwtOptions);
|
|
20
|
-
this.jwtProvider = (0, utils_1.createJwtProvider)(jwtOptions);
|
|
21
|
-
this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
|
|
22
|
-
this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
|
|
23
|
-
this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
|
|
24
|
-
this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
|
|
25
|
-
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
26
|
-
}
|
|
27
|
-
getStrategyOptions() {
|
|
28
|
-
const partialOptions = {
|
|
29
|
-
ignoreExpiration: this.ignoreExpiration,
|
|
30
|
-
};
|
|
31
|
-
if (this.passReqToCallback) {
|
|
32
|
-
return {
|
|
33
|
-
...partialOptions,
|
|
34
|
-
jwtFromRequest: this.jwtFromRequestFunction,
|
|
35
|
-
secretOrKey: this.secretOrPublicKey,
|
|
36
|
-
passReqToCallback: true
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...partialOptions,
|
|
41
|
-
jwtFromRequest: this.jwtFromRequestFunction,
|
|
42
|
-
secretOrKey: this.secretOrPublicKey,
|
|
43
|
-
passReqToCallback: false,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
sign(payload) {
|
|
47
|
-
return this.jwtProvider.sign(payload);
|
|
48
|
-
}
|
|
49
|
-
verify(token, verifyOption) {
|
|
50
|
-
return this.jwtProvider.verify(token, verifyOption);
|
|
16
|
+
isBase64AsymmetricKey: false,
|
|
17
|
+
});
|
|
51
18
|
}
|
|
52
19
|
}
|
|
53
20
|
exports.JwtStrategyProvider = JwtStrategyProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/jwt-strategy-provider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"jwt-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/jwt-strategy-provider.ts"],"names":[],"mappings":";;;AAAA,0DAAwF;AACxF,2CAAwC;AACxC,oDAAgF;AAEhF,6EAAuE;AAOvE,MAAsB,mBAAoB,SAAQ,oDAAuB;IACvE,YAAY,UAAsB;QAChC,KAAK,CAAC,UAAU,EAAE;YAChB,MAAM,EAAE,KAAK;YACb,mBAAmB,EAAE,IAAI;YACzB,gBAAgB,EAAE,IAAI;YACtB,gBAAgB,EAAE,KAAK;YACvB,iBAAiB,EAAE,IAAI;YACvB,qBAAqB,EAAE,KAAK;SAC7B,CAAC,CAAC;IACL,CAAC;CACF;AAXD,kDAWC;AAOD,MAAa,0BAA2B,SAAQ,mBAAmB;IAEjE,YAAY,UAAsB,EAAmB,YAA0B;QAC7E,KAAK,CAAC,UAAU,CAAC,CAAC;QADiC,iBAAY,GAAZ,YAAY,CAAc;QAD9D,WAAM,GAAG,IAAI,eAAM,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAGtE,CAAC;IAED,KAAK,CAAC,QAA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CAAoD;AACpD,2CAA4C;AAC5C,0CAAgD;AAChD,mEAA8D;
|
|
1
|
+
{"version":3,"file":"jwt-strategy.js","sourceRoot":"","sources":["../../lib/strategy/jwt-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAmG;AACnG,+CAAoD;AACpD,2CAA4C;AAC5C,0CAAgD;AAChD,mEAA8D;AASvD,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,EAAE,4BAAiB,CAAC;IAC5E,YAA6B,gBAAqC;QAEhE,KAAK,CAAC,gBAAgB,CAAC,kBAAkB,EAAS,CAAC,CAAC;QAFzB,qBAAgB,GAAhB,gBAAgB,CAAqB;IAGlE,CAAC;IASD,KAAK,CAAC,QAAQ,CAAC,IAAS,EAAE,IAAS;QACjC,MAAM,GAAG,GAAQ,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,OAAO,GAAQ,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAE3E,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AAnBY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAEoC,2CAAmB;GADvD,WAAW,CAmBvB"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { IPrincipal } from "../auth-provider";
|
|
2
2
|
import { Req, VerifyOptions } from "./type-interface";
|
|
3
|
-
export
|
|
4
|
-
validate(req: Req, payload: any):
|
|
5
|
-
validate<T>(req: Req, payload: any): T | Promise<T>;
|
|
6
|
-
sign(payload: string | object | Buffer): string;
|
|
7
|
-
verify(token: string, verifyOption?: VerifyOptions): object | string;
|
|
8
|
-
getStrategyOptions(): Record<string, any>;
|
|
9
|
-
}
|
|
10
|
-
export declare abstract class StrategyProvider implements IStrategyProvider {
|
|
11
|
-
abstract validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
12
|
-
abstract validate<T>(req: Req, payload: any): T | Promise<T>;
|
|
3
|
+
export declare abstract class StrategyProvider {
|
|
4
|
+
abstract validate<T = IPrincipal>(req: Req, payload: any): T | Promise<T>;
|
|
13
5
|
abstract sign(payload: string | object | Buffer): string;
|
|
14
6
|
abstract verify(token: string, verifyOption?: VerifyOptions): string | object;
|
|
15
7
|
abstract getStrategyOptions(): Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/strategy-provider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/strategy-provider.ts"],"names":[],"mappings":";;;AAOA,MAAsB,gBAAgB;CA6BrC;AA7BD,4CA6BC"}
|
|
@@ -9,7 +9,18 @@ export interface JwtNestJsOptions {
|
|
|
9
9
|
passReqToCallback?: boolean;
|
|
10
10
|
jwtFromRequestFunction?: JwtFromRequestFunction;
|
|
11
11
|
isBase64AsymmetricKey?: boolean;
|
|
12
|
+
issuer?: string;
|
|
13
|
+
audience?: string | string[];
|
|
12
14
|
}
|
|
13
15
|
export declare type JwtOptions = JwtNestJsOptions & jOption;
|
|
14
16
|
export declare type VerifyOptions = jwt.VerifyOptions;
|
|
15
17
|
export declare type Req = any;
|
|
18
|
+
export interface JwtPayload {
|
|
19
|
+
sub: string;
|
|
20
|
+
username?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
authorities?: (string | Record<string, unknown>)[];
|
|
23
|
+
iat?: number;
|
|
24
|
+
exp?: number;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare const isAuthority: (val: any) => val is Authority;
|
|
|
7
7
|
export declare const isCaslPermissionAction: (val: any) => boolean;
|
|
8
8
|
export declare const isRequiredCaslPermission: (permission: PermissionType) => boolean;
|
|
9
9
|
export declare const createJwtProvider: (jwtOptions: JwtOptions) => JwtProvider;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const isAsymmetricAlgo: (algo: string | Algorithm) => boolean;
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isAsymmetricAlgo = exports.createJwtProvider = exports.isRequiredCaslPermission = exports.isCaslPermissionAction = exports.isAuthority = exports.isCaslPermission = void 0;
|
|
4
4
|
const auth_1 = require("@nathapp/auth");
|
|
5
5
|
const permission_1 = require("../permission");
|
|
6
6
|
const isCaslPermission = (val) => {
|
|
7
|
-
return 'subject' in val && 'action' in val;
|
|
7
|
+
return val != null && typeof val === 'object' && 'subject' in val && 'action' in val;
|
|
8
8
|
};
|
|
9
9
|
exports.isCaslPermission = isCaslPermission;
|
|
10
10
|
const isAuthority = (val) => {
|
|
11
|
-
return
|
|
11
|
+
return val != null && typeof val === 'object' && 'id' in val && (typeof val.id === 'string' || typeof val.id === 'number') && 'name' in val && typeof val.name === 'string';
|
|
12
12
|
};
|
|
13
13
|
exports.isAuthority = isAuthority;
|
|
14
14
|
const isCaslPermissionAction = (val) => {
|
|
@@ -21,7 +21,7 @@ const isRequiredCaslPermission = (permission) => {
|
|
|
21
21
|
};
|
|
22
22
|
exports.isRequiredCaslPermission = isRequiredCaslPermission;
|
|
23
23
|
const createJwtProvider = (jwtOptions) => {
|
|
24
|
-
if (jwtOptions.isBase64AsymmetricKey && (0, exports.
|
|
24
|
+
if (jwtOptions.isBase64AsymmetricKey && (0, exports.isAsymmetricAlgo)(jwtOptions.signOption.algorithm)) {
|
|
25
25
|
const privateKeyBuff = typeof jwtOptions.privateKey == 'string' ? Buffer.from(jwtOptions.privateKey, 'base64') : jwtOptions.privateKey;
|
|
26
26
|
const publicKeyBuff = typeof jwtOptions.publicKey == 'string' ? Buffer.from(jwtOptions.publicKey, 'base64') : jwtOptions.publicKey;
|
|
27
27
|
const privateKey = privateKeyBuff ? privateKeyBuff.toString('utf-8') : undefined;
|
|
@@ -37,7 +37,7 @@ const createJwtProvider = (jwtOptions) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.createJwtProvider = createJwtProvider;
|
|
40
|
-
const
|
|
40
|
+
const isAsymmetricAlgo = (algo) => {
|
|
41
41
|
switch (algo) {
|
|
42
42
|
case "RS256":
|
|
43
43
|
case "RS384":
|
|
@@ -52,5 +52,5 @@ const isAysmmetricAlgo = (algo) => {
|
|
|
52
52
|
default: return false;
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
exports.
|
|
55
|
+
exports.isAsymmetricAlgo = isAsymmetricAlgo;
|
|
56
56
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils/utils.ts"],"names":[],"mappings":";;;AAAA,wCAA4C;AAC5C,8CAAgG;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils/utils.ts"],"names":[],"mappings":";;;AAAA,wCAA4C;AAC5C,8CAAgG;AAOzF,MAAO,gBAAgB,GAAG,CAAC,GAAQ,EAAyB,EAAE;IACnE,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,SAAS,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,CAAC;AACvF,CAAC,CAAA;AAFa,QAAA,gBAAgB,oBAE7B;AAKM,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAoB,EAAE;IACxD,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,IAAI,IAAI,GAAG,IAA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,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;QAEnI,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACjF,MAAM,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,OAAO,IAAI,kBAAW,CAAC;YACrB,GAAG,UAAU;YACb,UAAU;YACV,SAAS;SACV,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,kBAAW,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAA;AAhBY,QAAA,iBAAiB,qBAgB7B;AAKM,MAAM,gBAAgB,GAAG,CAAC,IAAwB,EAAW,EAAE;IAClE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,OAAO;YACV,OAAO,IAAI,CAAC;QACd,OAAO,CAAC,CAAC,OAAO,KAAK,CAAC;IACxB,CAAC;AACL,CAAC,CAAA;AAdY,QAAA,gBAAgB,oBAc5B"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Fix Plan: Split nestjs-auth into AuthModule + AuthorizationModule + NathAuthModule
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-02-14
|
|
4
|
+
**Branch:** `feat/monorepo-enterprise-upgrade`
|
|
5
|
+
|
|
6
|
+
## Design
|
|
7
|
+
|
|
8
|
+
### New Module Structure
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
@nathapp/nestjs-auth
|
|
12
|
+
├── lib/
|
|
13
|
+
│ ├── authentication/ ← AuthModule (AuthN)
|
|
14
|
+
│ │ ├── auth-provider.ts (IPrincipal, AuthProvider, SimpleAuthProvider)
|
|
15
|
+
│ │ ├── auth.module.ts (NEW — AuthModule.forRoot/forRootAsync)
|
|
16
|
+
│ │ ├── guard/
|
|
17
|
+
│ │ │ ├── jwt-auth.guard.ts
|
|
18
|
+
│ │ │ └── jwt-refresh.guard.ts
|
|
19
|
+
│ │ ├── strategy/
|
|
20
|
+
│ │ │ ├── jwt-strategy-provider.ts
|
|
21
|
+
│ │ │ ├── jwt-refresh-strategy-provider.ts
|
|
22
|
+
│ │ │ ├── jwt-strategy.ts
|
|
23
|
+
│ │ │ ├── jwt-refresh-strategy.ts
|
|
24
|
+
│ │ │ ├── strategy-provider.ts
|
|
25
|
+
│ │ │ └── type-interface.ts
|
|
26
|
+
│ │ ├── decorator/
|
|
27
|
+
│ │ │ ├── is-public.decorator.ts
|
|
28
|
+
│ │ │ ├── principal.decorator.ts
|
|
29
|
+
│ │ │ └── refresh-token.decorator.ts
|
|
30
|
+
│ │ └── index.ts
|
|
31
|
+
│ │
|
|
32
|
+
│ ├── authorization/ ← AuthorizationModule (AuthZ)
|
|
33
|
+
│ │ ├── authorization.module.ts (NEW — AuthorizationModule.forRoot/forRootAsync)
|
|
34
|
+
│ │ ├── guard/
|
|
35
|
+
│ │ │ └── permission-auth.guard.ts
|
|
36
|
+
│ │ ├── permission/
|
|
37
|
+
│ │ │ └── permission.provider.ts (+ all CASL types)
|
|
38
|
+
│ │ ├── casl/
|
|
39
|
+
│ │ │ └── casl-ability-factory.ts
|
|
40
|
+
│ │ ├── decorator/
|
|
41
|
+
│ │ │ └── permission.decorator.ts
|
|
42
|
+
│ │ └── index.ts
|
|
43
|
+
│ │
|
|
44
|
+
│ ├── nath-auth.module.ts ← NathAuthModule (wires both)
|
|
45
|
+
│ ├── constant/ (shared constants)
|
|
46
|
+
│ ├── utils/ (shared utils)
|
|
47
|
+
│ └── index.ts (re-exports everything)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Module APIs
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// AuthModule — AuthN only
|
|
54
|
+
AuthModule.forRoot({
|
|
55
|
+
jwtOptions: { secret: '...', signOption: { expiresIn: '1h' } },
|
|
56
|
+
refreshJwtOptions?: { ... },
|
|
57
|
+
authProvider?: CustomAuthProvider,
|
|
58
|
+
strategyProvider?: CustomStrategyProvider,
|
|
59
|
+
refreshStrategyProvider?: CustomRefreshStrategyProvider,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// AuthorizationModule — AuthZ only
|
|
63
|
+
AuthorizationModule.forRoot({
|
|
64
|
+
permissionProvider?: CustomPermissionProvider, // default: DefaultPermissionProvider
|
|
65
|
+
caslAbilityFactory?: CustomCaslAbilityFactory, // default: JwtCaslAbilityFactory
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// NathAuthModule — one-stop registration (AuthN + AuthZ)
|
|
69
|
+
NathAuthModule.forRoot({
|
|
70
|
+
// AuthN options
|
|
71
|
+
jwtOptions: { ... },
|
|
72
|
+
refreshJwtOptions?: { ... },
|
|
73
|
+
authProvider?: CustomAuthProvider,
|
|
74
|
+
strategyProvider?: CustomStrategyProvider,
|
|
75
|
+
refreshStrategyProvider?: CustomRefreshStrategyProvider,
|
|
76
|
+
// AuthZ options
|
|
77
|
+
permissionProvider?: CustomPermissionProvider,
|
|
78
|
+
caslAbilityFactory?: CustomCaslAbilityFactory,
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Backward Compatibility
|
|
83
|
+
|
|
84
|
+
- `JwtModule` → **kept as alias** for `AuthModule` with `@deprecated` tag
|
|
85
|
+
- All existing exports remain in `lib/index.ts`
|
|
86
|
+
- Consumers can migrate gradually: `JwtModule.forRoot()` → `NathAuthModule.forRoot()` or `AuthModule.forRoot()` + `AuthorizationModule.forRoot()`
|
|
87
|
+
|
|
88
|
+
## Phase 1: Restructure directories + create AuthModule
|
|
89
|
+
|
|
90
|
+
### 1.1: Move files to authentication/ and authorization/ subdirectories
|
|
91
|
+
- Move AuthN files to `lib/authentication/`
|
|
92
|
+
- Move AuthZ files to `lib/authorization/`
|
|
93
|
+
- Keep `lib/constant/`, `lib/utils/` as shared
|
|
94
|
+
- Update all internal imports
|
|
95
|
+
|
|
96
|
+
### 1.2: Create AuthModule (rename from JwtModule internals)
|
|
97
|
+
**File:** `lib/authentication/auth.module.ts`
|
|
98
|
+
- Extract AuthN providers from `JwtModule` → `AuthModule`
|
|
99
|
+
- `AuthModule.forRoot(options: AuthModuleOptions)` — registers JWT strategies, auth provider
|
|
100
|
+
- `AuthModule.forRootAsync(options: AuthModuleAsyncOptions)` — async version
|
|
101
|
+
- Export `JwtStrategyProvider`, `JwtRefreshStrategyProvider`, `AUTH_PROVIDER`, `JWT_OPTIONS`
|
|
102
|
+
|
|
103
|
+
### 1.3: Create AuthorizationModule
|
|
104
|
+
**File:** `lib/authorization/authorization.module.ts`
|
|
105
|
+
- `AuthorizationModule.forRoot(options?: AuthorizationModuleOptions)` — registers permission provider + CASL factory
|
|
106
|
+
- Options: `{ permissionProvider?, caslAbilityFactory? }`
|
|
107
|
+
- Defaults: `DefaultPermissionProvider` + `JwtCaslAbilityFactory`
|
|
108
|
+
- Make `CaslAbilityFactory` injectable via DI (fixes ARCH concern from review)
|
|
109
|
+
- Export `PermissionProvider`, `PERMISSION_PROVIDER` token
|
|
110
|
+
|
|
111
|
+
### 1.4: Create NathAuthModule
|
|
112
|
+
**File:** `lib/nath-auth.module.ts`
|
|
113
|
+
- Combines `AuthModule` + `AuthorizationModule`
|
|
114
|
+
- `NathAuthModule.forRoot(options: NathAuthModuleOptions)` — splits options and delegates to both modules
|
|
115
|
+
- `NathAuthModule.forRootAsync(options: NathAuthModuleAsyncOptions)` — async version
|
|
116
|
+
- This is the "developer registers in one place" module
|
|
117
|
+
|
|
118
|
+
### 1.5: Deprecate JwtModule
|
|
119
|
+
- Keep `JwtModule` as re-export alias of `AuthModule` with `@deprecated` JSDoc
|
|
120
|
+
- Keep all existing interfaces (`JwtModuleOptions`, etc.) working
|
|
121
|
+
|
|
122
|
+
## Phase 2: Also do Must-Have improvements from review
|
|
123
|
+
|
|
124
|
+
### 2.1: Extract BaseJwtStrategyProvider (DRY)
|
|
125
|
+
- Shared code between `JwtStrategyProvider` and `JwtRefreshStrategyProvider`
|
|
126
|
+
- Constructor, `getStrategyOptions()`, `sign()`, `verify()` → base class
|
|
127
|
+
|
|
128
|
+
### 2.2: Code cleanup
|
|
129
|
+
- Remove commented-out code in `permission.decorator.ts`
|
|
130
|
+
- Remove duplicate `abstract validate` signatures
|
|
131
|
+
- Remove unused `SetMetadata` import
|
|
132
|
+
- Remove `IStrategyProvider` (redundant)
|
|
133
|
+
- Clean up deprecated constants
|
|
134
|
+
|
|
135
|
+
## Test Strategy
|
|
136
|
+
- **Mode:** two-session-tdd
|
|
137
|
+
- **TDD targets:**
|
|
138
|
+
- `AuthModule.forRoot()` / `forRootAsync()` — module creates correct providers
|
|
139
|
+
- `AuthorizationModule.forRoot()` / `forRootAsync()` — module creates correct providers, CaslAbilityFactory injectable
|
|
140
|
+
- `NathAuthModule.forRoot()` / `forRootAsync()` — wires both modules correctly
|
|
141
|
+
- Backward compat: `JwtModule.forRoot()` still works
|
|
142
|
+
- **Test-after targets:** Directory restructure (existing tests should still pass)
|
|
143
|
+
|
|
144
|
+
## Commits
|
|
145
|
+
1. `refactor(nestjs-auth): restructure into authentication/ and authorization/ directories`
|
|
146
|
+
2. `feat(nestjs-auth): add AuthModule, AuthorizationModule, NathAuthModule`
|
|
147
|
+
3. `refactor(nestjs-auth): extract BaseJwtStrategyProvider, cleanup dead code`
|
|
148
|
+
4. `feat(nestjs-auth): deprecate JwtModule in favor of NathAuthModule`
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Fix Plan: nestjs-auth Security Fixes
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-02-14
|
|
4
|
+
**Branch:** `feat/monorepo-enterprise-upgrade`
|
|
5
|
+
**Review:** `packages/nestjs-auth/docs/20260214-review-auth.md`
|
|
6
|
+
|
|
7
|
+
## Phase 1: Critical Security Fixes
|
|
8
|
+
|
|
9
|
+
### Fix 1: SEC-1 — Remove @RefreshToken() bypass from JwtAuthGuard
|
|
10
|
+
**File:** `packages/nestjs-auth/lib/guard/jwt-auth.guard.ts`
|
|
11
|
+
**Impact:** CRITICAL — endpoints with @RefreshToken() are currently unprotected
|
|
12
|
+
**Change:** Remove the `RefreshToken` check that returns `true`. Instead, refresh endpoints should use `@Public()` to skip `JwtAuthGuard`, and explicitly apply `@UseGuards(JwtRefreshGuard)`.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
// REMOVE this block from canActivate():
|
|
16
|
+
const RefreshToken = this.reflector.get<boolean>(REFRESH_TOKEN, context.getHandler());
|
|
17
|
+
if (RefreshToken) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Also fix the variable shadowing — the variable `RefreshToken` shadows the concept of the constant.
|
|
23
|
+
|
|
24
|
+
### Fix 2: BUG-4 — PermissionAuthGuard drops multi-CASL permissions
|
|
25
|
+
**File:** `packages/nestjs-auth/lib/guard/permission-auth.guard.ts`
|
|
26
|
+
**Impact:** HIGH — `@RequiredPermission(['create', 'Invoice'], ['read', 'Invoice'])` only checks first permission
|
|
27
|
+
**Change:** Fix the branching logic. When `firstPermission` is a CASL tuple, pass the ENTIRE `requirePermission` array, not just the first wrapped in an array.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// Before (buggy)
|
|
31
|
+
} else if (isRequiredCaslPermission(firstPermission)) {
|
|
32
|
+
return this.permissionProvider.checkPermission(context, [firstPermission] as RequiredCaslPermission[]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// After (fixed)
|
|
36
|
+
} else if (isRequiredCaslPermission(firstPermission)) {
|
|
37
|
+
return this.permissionProvider.checkPermission(context, requirePermission as RequiredCaslPermission[]);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Fix 3: BUG-3 — isAuthority operator precedence bug
|
|
42
|
+
**File:** `packages/nestjs-auth/lib/utils/utils.ts`
|
|
43
|
+
**Impact:** HIGH — objects with `id: string` but no `name` pass the type guard
|
|
44
|
+
**Change:** Add parentheses for correct precedence:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Before
|
|
48
|
+
return ('id' in val && typeof val.id === 'string' || typeof val.id === 'number') && 'name' in val && typeof val.name === 'string';
|
|
49
|
+
|
|
50
|
+
// After
|
|
51
|
+
return 'id' in val && (typeof val.id === 'string' || typeof val.id === 'number') && 'name' in val && typeof val.name === 'string';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Commit:** `fix(nestjs-auth)!: remove RefreshToken bypass from JwtAuthGuard, fix permission dropping and isAuthority bugs`
|
|
55
|
+
|
|
56
|
+
## Phase 2: Medium Security & Quality Fixes
|
|
57
|
+
|
|
58
|
+
### Fix 4: SEC-7 — Add audit logging for auth failures
|
|
59
|
+
**File:** `packages/nestjs-auth/lib/guard/jwt-auth.guard.ts`
|
|
60
|
+
**Change:** Add logger and log failed auth attempts in `handleRequest()`:
|
|
61
|
+
```typescript
|
|
62
|
+
private readonly logger = new Logger(JwtAuthGuard.name);
|
|
63
|
+
|
|
64
|
+
handleRequest(err, user, info) {
|
|
65
|
+
if (err || !user) {
|
|
66
|
+
this.logger.warn(`Authentication failed: ${info?.message || err?.message || 'Unknown reason'}`);
|
|
67
|
+
throw err || new AppException(CommonExceptionCode.UNAUTHORIZED);
|
|
68
|
+
}
|
|
69
|
+
return user;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Same for `jwt-refresh.guard.ts`.
|
|
74
|
+
|
|
75
|
+
### Fix 5: TYPE-2 — Remove duplicate abstract validate signatures
|
|
76
|
+
**Files:** `packages/nestjs-auth/lib/strategy/jwt-strategy-provider.ts`, `packages/nestjs-auth/lib/strategy/jwt-refresh-strategy-provider.ts`, `packages/nestjs-auth/lib/strategy/strategy-provider.ts`
|
|
77
|
+
**Change:** Remove the duplicate `abstract validate(req, payload): IPrincipal` signature. Keep only the generic one:
|
|
78
|
+
```typescript
|
|
79
|
+
abstract validate<T = IPrincipal>(req: Req, payload: any): T | Promise<T>;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Fix 6: CLEAN-1,2,3,4 — Code cleanup
|
|
83
|
+
- Remove commented-out code in `permission.decorator.ts`
|
|
84
|
+
- Fix typo: `isAysmmetricAlgo` → `isAsymmetricAlgo` in `utils.ts`
|
|
85
|
+
- Fix variable shadowing in `jwt-auth.guard.ts` (already addressed by Fix 1)
|
|
86
|
+
- Remove unused `SetMetadata` import in `principal.decorator.ts`
|
|
87
|
+
|
|
88
|
+
### Fix 7: Over-exports cleanup
|
|
89
|
+
**File:** `packages/nestjs-auth/lib/constant/jwt-constant.ts`
|
|
90
|
+
- Remove or mark as deprecated: `JWT_PROVIDER`, `STRATEGY_PROVIDER`, `JWT_API_STRATEGY_NAME`, `JWT_GRPC_STRATEGY_NAME` (unused constants)
|
|
91
|
+
|
|
92
|
+
**Commit:** `fix(nestjs-auth): add auth failure logging, remove dead code, fix typos`
|
|
93
|
+
|
|
94
|
+
## Test Strategy
|
|
95
|
+
- **Mode:** two-session-tdd
|
|
96
|
+
- **TDD targets:** JwtAuthGuard (SEC-1 bypass removed), PermissionAuthGuard (multi-CASL), isAuthority (operator precedence)
|
|
97
|
+
- **Test-after targets:** Audit logging, code cleanup
|
|
98
|
+
|
|
99
|
+
### Test Cases for Session 1 (Test Writer)
|
|
100
|
+
|
|
101
|
+
#### jwt-auth.guard.spec.ts
|
|
102
|
+
- Should call super.canActivate() for normal requests (no @Public, no @RefreshToken)
|
|
103
|
+
- Should return true for @Public() decorated endpoints
|
|
104
|
+
- Should NOT bypass auth for @RefreshToken() decorated endpoints (SEC-1 fix validation)
|
|
105
|
+
- Should throw AppException(UNAUTHORIZED) when user is null
|
|
106
|
+
- Should throw AppException(UNAUTHORIZED) when err exists
|
|
107
|
+
- Should return user when auth succeeds
|
|
108
|
+
- Should log warning on auth failure (SEC-7)
|
|
109
|
+
|
|
110
|
+
#### permission-auth.guard.spec.ts (extend existing)
|
|
111
|
+
- Should check ALL CASL permissions when multiple tuples provided (BUG-4 fix validation)
|
|
112
|
+
- `@RequiredPermission(['create', 'Invoice'], ['read', 'Invoice'])` should pass both to checkPermission
|
|
113
|
+
- Single CASL permission still works: `@RequiredPermission(['create', 'Invoice'])`
|
|
114
|
+
- String permission still works: `@RequiredPermission('admin')`
|
|
115
|
+
|
|
116
|
+
#### utils.spec.ts
|
|
117
|
+
- `isAuthority({ id: 'abc' })` without `name` should return false (BUG-3 fix validation)
|
|
118
|
+
- `isAuthority({ id: 123, name: 'admin' })` should return true
|
|
119
|
+
- `isAuthority({ id: 'abc', name: 'admin' })` should return true
|
|
120
|
+
- `isAuthority({ name: 'admin' })` without `id` should return false
|
|
121
|
+
- `isAuthority({})` should return false
|
|
122
|
+
- `isAuthority(null)` should return false
|
|
123
|
+
- `isAuthority('string')` should return false
|
|
124
|
+
|
|
125
|
+
## Important Notes
|
|
126
|
+
- Do NOT push to remote — local commits only
|
|
127
|
+
- SEC-1 fix is a BREAKING CHANGE — consumers using `@RefreshToken()` must add `@Public()` + `@UseGuards(JwtRefreshGuard)` to their refresh endpoints
|
|
128
|
+
- The `@RefreshToken()` decorator itself can remain (for metadata marking) but should NOT cause auth bypass
|
|
129
|
+
- Use existing test patterns from `packages/nestjs-auth/test/` as reference
|
|
130
|
+
- Existing e2e tests may break if they rely on @RefreshToken() bypass — update them
|