@nathapp/nestjs-auth 4.5.0 → 4.6.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/AGENTS.md +17 -4
- package/CLAUDE.md +16 -3
- package/GEMINI.md +17 -4
- package/codex.md +17 -4
- package/dist/auth.module.d.ts +2 -0
- package/dist/auth.module.js +66 -49
- package/dist/auth.module.js.map +1 -1
- package/dist/authentication/auth.module.d.ts +4 -0
- package/dist/authentication/auth.module.js +57 -19
- package/dist/authentication/auth.module.js.map +1 -1
- package/dist/decorator/optional-auth.decorator.js.map +1 -1
- package/dist/guard/jwt-auth.guard.js +6 -1
- package/dist/guard/jwt-auth.guard.js.map +1 -1
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -15,7 +15,9 @@ These instructions apply to all AI coding agents in this project.
|
|
|
15
15
|
|
|
16
16
|
**Language:** TypeScript
|
|
17
17
|
|
|
18
|
-
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
18
|
+
**Key dependencies:** @nestjs/common, @nestjs/config, @nestjs/core, @nathapp/typescript-config, typescript
|
|
19
|
+
|
|
20
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
19
21
|
|
|
20
22
|
---
|
|
21
23
|
# @nathapp/nestjs-auth
|
|
@@ -23,8 +25,19 @@ These instructions apply to all AI coding agents in this project.
|
|
|
23
25
|
JWT authentication + CASL authorization library for NestJS.
|
|
24
26
|
|
|
25
27
|
## Commands
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
Run from `packages/nestjs-auth/`. Replace the example test path with a path relative to this package.
|
|
30
|
+
|
|
31
|
+
| Purpose | Command |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Build this package | `npm run build` |
|
|
34
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
35
|
+
| Run the default suite | `npm test` |
|
|
36
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
37
|
+
| Type-check library source | `npm run type-check` |
|
|
38
|
+
| Type-check test source | `npm run type-check:test` |
|
|
39
|
+
| Lint library and test source | `npm run lint` |
|
|
40
|
+
| Packed consumer tests after a build | `npm run test:consumer` |
|
|
28
41
|
|
|
29
42
|
## Module Structure
|
|
30
43
|
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
@@ -40,7 +53,7 @@ JWT authentication + CASL authorization library for NestJS.
|
|
|
40
53
|
|
|
41
54
|
## Gotchas
|
|
42
55
|
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
43
|
-
- `AuthModule.forRootAsync
|
|
56
|
+
- With `AuthModule.forRootAsync({ useClass, imports })`, Nest creates the options factory and injects its constructor dependencies. Include the modules that export those dependencies in `imports`. Both child modules share the result of one `createOptions()` call per registration.
|
|
44
57
|
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
45
58
|
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
46
59
|
|
package/CLAUDE.md
CHANGED
|
@@ -15,14 +15,27 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
|
15
15
|
|
|
16
16
|
**Key dependencies:** @nestjs/common, @nestjs/config, @nestjs/core, @nathapp/typescript-config, typescript
|
|
17
17
|
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
19
|
+
|
|
18
20
|
---
|
|
19
21
|
# @nathapp/nestjs-auth
|
|
20
22
|
|
|
21
23
|
JWT authentication + CASL authorization library for NestJS.
|
|
22
24
|
|
|
23
25
|
## Commands
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-auth/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
|
38
|
+
| Packed consumer tests after a build | `npm run test:consumer` |
|
|
26
39
|
|
|
27
40
|
## Module Structure
|
|
28
41
|
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
@@ -38,7 +51,7 @@ JWT authentication + CASL authorization library for NestJS.
|
|
|
38
51
|
|
|
39
52
|
## Gotchas
|
|
40
53
|
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
41
|
-
- `AuthModule.forRootAsync
|
|
54
|
+
- With `AuthModule.forRootAsync({ useClass, imports })`, Nest creates the options factory and injects its constructor dependencies. Include the modules that export those dependencies in `imports`. Both child modules share the result of one `createOptions()` call per registration.
|
|
42
55
|
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
43
56
|
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
44
57
|
|
package/GEMINI.md
CHANGED
|
@@ -13,7 +13,9 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
|
13
13
|
|
|
14
14
|
**Language:** TypeScript
|
|
15
15
|
|
|
16
|
-
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
16
|
+
**Key dependencies:** @nestjs/common, @nestjs/config, @nestjs/core, @nathapp/typescript-config, typescript
|
|
17
|
+
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
17
19
|
|
|
18
20
|
---
|
|
19
21
|
# @nathapp/nestjs-auth
|
|
@@ -21,8 +23,19 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
|
21
23
|
JWT authentication + CASL authorization library for NestJS.
|
|
22
24
|
|
|
23
25
|
## Commands
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-auth/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
|
38
|
+
| Packed consumer tests after a build | `npm run test:consumer` |
|
|
26
39
|
|
|
27
40
|
## Module Structure
|
|
28
41
|
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
@@ -38,7 +51,7 @@ JWT authentication + CASL authorization library for NestJS.
|
|
|
38
51
|
|
|
39
52
|
## Gotchas
|
|
40
53
|
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
41
|
-
- `AuthModule.forRootAsync
|
|
54
|
+
- With `AuthModule.forRootAsync({ useClass, imports })`, Nest creates the options factory and injects its constructor dependencies. Include the modules that export those dependencies in `imports`. Both child modules share the result of one `createOptions()` call per registration.
|
|
42
55
|
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
43
56
|
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
44
57
|
|
package/codex.md
CHANGED
|
@@ -13,7 +13,9 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
|
13
13
|
|
|
14
14
|
**Language:** TypeScript
|
|
15
15
|
|
|
16
|
-
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
16
|
+
**Key dependencies:** @nestjs/common, @nestjs/config, @nestjs/core, @nathapp/typescript-config, typescript
|
|
17
|
+
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
17
19
|
|
|
18
20
|
---
|
|
19
21
|
# @nathapp/nestjs-auth
|
|
@@ -21,8 +23,19 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
|
21
23
|
JWT authentication + CASL authorization library for NestJS.
|
|
22
24
|
|
|
23
25
|
## Commands
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-auth/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
|
38
|
+
| Packed consumer tests after a build | `npm run test:consumer` |
|
|
26
39
|
|
|
27
40
|
## Module Structure
|
|
28
41
|
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
@@ -38,7 +51,7 @@ JWT authentication + CASL authorization library for NestJS.
|
|
|
38
51
|
|
|
39
52
|
## Gotchas
|
|
40
53
|
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
41
|
-
- `AuthModule.forRootAsync
|
|
54
|
+
- With `AuthModule.forRootAsync({ useClass, imports })`, Nest creates the options factory and injects its constructor dependencies. Include the modules that export those dependencies in `imports`. Both child modules share the result of one `createOptions()` call per registration.
|
|
42
55
|
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
43
56
|
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
44
57
|
|
package/dist/auth.module.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { AuthorizationModuleOptions, AuthorizationModuleAsyncOptions } from './a
|
|
|
4
4
|
export declare class AuthModule {
|
|
5
5
|
static forRoot(options: AuthModuleOptions): DynamicModule;
|
|
6
6
|
static forRootAsync(options: AuthModuleAsyncOptions): DynamicModule;
|
|
7
|
+
private static createResolvedOptionsModule;
|
|
8
|
+
private static createOptionsFactoryCaller;
|
|
7
9
|
}
|
|
8
10
|
export interface AuthModuleOptions extends AuthenticationModuleOptions, AuthorizationModuleOptions {
|
|
9
11
|
}
|
package/dist/auth.module.js
CHANGED
|
@@ -9,9 +9,16 @@ var AuthModule_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.AuthModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
-
const auth_provider_1 = require("./auth-provider");
|
|
13
12
|
const auth_module_1 = require("./authentication/auth.module");
|
|
14
13
|
const authorization_module_1 = require("./authorization/authorization.module");
|
|
14
|
+
const AUTH_MODULE_RESOLVED_OPTIONS = Symbol.for('AUTH_MODULE_RESOLVED_OPTIONS');
|
|
15
|
+
const AUTH_MODULE_REGISTRATION_ID = Symbol('AUTH_MODULE_REGISTRATION_ID');
|
|
16
|
+
let authModuleRegistrationSequence = 0;
|
|
17
|
+
let AuthModuleResolvedOptionsModule = class AuthModuleResolvedOptionsModule {
|
|
18
|
+
};
|
|
19
|
+
AuthModuleResolvedOptionsModule = __decorate([
|
|
20
|
+
(0, common_1.Module)({})
|
|
21
|
+
], AuthModuleResolvedOptionsModule);
|
|
15
22
|
let AuthModule = AuthModule_1 = class AuthModule {
|
|
16
23
|
static forRoot(options) {
|
|
17
24
|
const authModule = auth_module_1.AuthenticationModule.forRoot({
|
|
@@ -33,71 +40,81 @@ let AuthModule = AuthModule_1 = class AuthModule {
|
|
|
33
40
|
};
|
|
34
41
|
}
|
|
35
42
|
static forRootAsync(options) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const resolvedOptionsModule = AuthModule_1.createResolvedOptionsModule(options);
|
|
36
45
|
const authAsyncOptions = {
|
|
37
|
-
imports: options.imports,
|
|
38
|
-
|
|
46
|
+
imports: [resolvedOptionsModule, ...((_a = options.imports) !== null && _a !== void 0 ? _a : [])],
|
|
47
|
+
useFactory: (resolvedOptions) => resolvedOptions,
|
|
48
|
+
inject: [AUTH_MODULE_RESOLVED_OPTIONS],
|
|
39
49
|
...(options.authProvider !== undefined && { authProvider: options.authProvider }),
|
|
40
50
|
...(options.strategyProvider !== undefined && { strategyProvider: options.strategyProvider }),
|
|
41
51
|
...(options.refreshStrategyProvider !== undefined && { refreshStrategyProvider: options.refreshStrategyProvider }),
|
|
42
52
|
};
|
|
43
53
|
const authzAsyncOptions = {
|
|
44
|
-
imports: options.imports,
|
|
54
|
+
imports: [resolvedOptionsModule, ...((_b = options.imports) !== null && _b !== void 0 ? _b : [])],
|
|
55
|
+
useFactory: (resolvedOptions) => resolvedOptions,
|
|
56
|
+
inject: [AUTH_MODULE_RESOLVED_OPTIONS],
|
|
45
57
|
...(options.permissionProvider !== undefined && { permissionProvider: options.permissionProvider }),
|
|
46
58
|
...(options.caslAbilityFactory !== undefined && { caslAbilityFactory: options.caslAbilityFactory }),
|
|
47
59
|
};
|
|
60
|
+
const authModule = auth_module_1.AuthenticationModule.forRootAsync(authAsyncOptions);
|
|
61
|
+
const authzModule = authorization_module_1.AuthorizationModule.forRootAsync(authzAsyncOptions);
|
|
62
|
+
return {
|
|
63
|
+
module: AuthModule_1,
|
|
64
|
+
imports: [authModule, authzModule],
|
|
65
|
+
exports: [auth_module_1.AuthenticationModule, authorization_module_1.AuthorizationModule],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static createResolvedOptionsModule(options) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const imports = (_a = options.imports) !== null && _a !== void 0 ? _a : [];
|
|
71
|
+
const registrationProvider = {
|
|
72
|
+
provide: AUTH_MODULE_REGISTRATION_ID,
|
|
73
|
+
useValue: `auth-registration-${++authModuleRegistrationSequence}`,
|
|
74
|
+
};
|
|
48
75
|
if (options.useFactory) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
76
|
+
return {
|
|
77
|
+
module: AuthModuleResolvedOptionsModule,
|
|
78
|
+
imports,
|
|
79
|
+
providers: [
|
|
80
|
+
registrationProvider,
|
|
81
|
+
{
|
|
82
|
+
provide: AUTH_MODULE_RESOLVED_OPTIONS,
|
|
83
|
+
useFactory: options.useFactory,
|
|
84
|
+
inject: (_b = options.inject) !== null && _b !== void 0 ? _b : [],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
exports: [AUTH_MODULE_RESOLVED_OPTIONS],
|
|
58
88
|
};
|
|
59
|
-
authzAsyncOptions.inject = options.inject;
|
|
60
89
|
}
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return new auth_provider_1.SimpleAuthProvider();
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
authzAsyncOptions.useFactory = async () => {
|
|
77
|
-
const combinedOptions = await factory.createOptions();
|
|
78
|
-
return {
|
|
79
|
-
...(combinedOptions.permissionProvider !== undefined && { permissionProvider: combinedOptions.permissionProvider }),
|
|
80
|
-
...(combinedOptions.caslAbilityFactory !== undefined && { caslAbilityFactory: combinedOptions.caslAbilityFactory }),
|
|
81
|
-
};
|
|
90
|
+
if (options.useClass) {
|
|
91
|
+
const OptionsFactory = options.useClass;
|
|
92
|
+
return {
|
|
93
|
+
module: AuthModuleResolvedOptionsModule,
|
|
94
|
+
imports,
|
|
95
|
+
providers: [
|
|
96
|
+
registrationProvider,
|
|
97
|
+
{ provide: OptionsFactory, useClass: OptionsFactory },
|
|
98
|
+
AuthModule_1.createOptionsFactoryCaller(OptionsFactory),
|
|
99
|
+
],
|
|
100
|
+
exports: [AUTH_MODULE_RESOLVED_OPTIONS],
|
|
82
101
|
};
|
|
83
102
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
...(combinedOptions.caslAbilityFactory !== undefined && { caslAbilityFactory: combinedOptions.caslAbilityFactory }),
|
|
91
|
-
};
|
|
103
|
+
if (options.useExisting) {
|
|
104
|
+
return {
|
|
105
|
+
module: AuthModuleResolvedOptionsModule,
|
|
106
|
+
imports,
|
|
107
|
+
providers: [registrationProvider, AuthModule_1.createOptionsFactoryCaller(options.useExisting)],
|
|
108
|
+
exports: [AUTH_MODULE_RESOLVED_OPTIONS],
|
|
92
109
|
};
|
|
93
|
-
authzAsyncOptions.inject = [options.useExisting];
|
|
94
110
|
}
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
throw new Error('Invalid AuthModule async options: one of "useClass", "useExisting" or "useFactory" must be provided.');
|
|
112
|
+
}
|
|
113
|
+
static createOptionsFactoryCaller(factory) {
|
|
97
114
|
return {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
provide: AUTH_MODULE_RESOLVED_OPTIONS,
|
|
116
|
+
useFactory: async (optionsFactory) => optionsFactory.createOptions(),
|
|
117
|
+
inject: [factory],
|
|
101
118
|
};
|
|
102
119
|
}
|
|
103
120
|
};
|
package/dist/auth.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../lib/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../lib/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AACvE,8DAAmI;AACnI,+EAAwI;AAOxI,MAAM,4BAA4B,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAChF,MAAM,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAC1E,IAAI,8BAA8B,GAAG,CAAC,CAAC;AAOvC,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;CAAG,CAAA;AAAlC,+BAA+B;IADpC,IAAA,eAAM,EAAC,EAAE,CAAC;GACL,+BAA+B,CAAG;AAQjC,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAC,OAA0B;QACvC,MAAM,UAAU,GAAG,kCAAoB,CAAC,OAAO,CAAC;YAC9C,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,GAAG,CAAC,OAAO,CAAC,iBAAiB,KAAK,SAAS,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAChG,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;YAClE,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;YACjF,GAAG,CAAC,OAAO,CAAC,gBAAgB,KAAK,SAAS,IAAI,EAAE,gBAAg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9B,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,EAAE;qBAC7B;iBACF;gBACD,OAAO,EAAE,CAAC,4BAA4B,CAAC;aACxC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;YACxC,OAAO;gBACL,MAAM,EAAE,+BAA+B;gBACvC,OAAO;gBACP,SAAS,EAAE;oBACT,oBAAoB;oBACpB,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE;oBACrD,YAAU,CAAC,0BAA0B,CAAC,cAAc,CAAC;iBACtD;gBACD,OAAO,EAAE,CAAC,4BAA4B,CAAC;aACxC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO;gBACL,MAAM,EAAE,+BAA+B;gBACvC,OAAO;gBACP,SAAS,EAAE,CAAC,oBAAoB,EAAE,YAAU,CAAC,0BAA0B,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAC7F,OAAO,EAAE,CAAC,4BAA4B,CAAC;aACxC,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,0BAA0B,CACvC,OAAuC;QAEvC,OAAO;YACL,OAAO,EAAE,4BAA4B;YACrC,UAAU,EAAE,KAAK,EACf,cAAwC,EACZ,EAAE,CAAC,cAAc,CAAC,aAAa,EAAE;YAC/D,MAAM,EAAE,CAAC,OAAO,CAAC;SAClB,CAAC;IACJ,CAAC;CACF,CAAA;AA1HY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CA0HtB"}
|
|
@@ -7,6 +7,8 @@ export declare class AuthenticationModule {
|
|
|
7
7
|
static forRoot(options: AuthenticationModuleOptions): DynamicModule;
|
|
8
8
|
static forRootAsync(options: AuthenticationModuleAsyncOptions): DynamicModule;
|
|
9
9
|
private static sanitizeAuthenticationModuleOptions;
|
|
10
|
+
private static sanitizeAuthenticationModuleAsyncOptions;
|
|
11
|
+
private static applyBase64AsymmetricKeyPropagation;
|
|
10
12
|
private static createStrategyProvider;
|
|
11
13
|
private static createAsyncStrategyProvider;
|
|
12
14
|
private static createDefaultStrategyProvider;
|
|
@@ -14,6 +16,8 @@ export declare class AuthenticationModule {
|
|
|
14
16
|
private static createAsyncRefreshStrategyProvider;
|
|
15
17
|
private static createDefaultRefreshStrategyProvider;
|
|
16
18
|
private static createAsyncAuthProvider;
|
|
19
|
+
private static createResolvedAuthProvider;
|
|
20
|
+
private static instantiateConfiguredAuthProvider;
|
|
17
21
|
private static createAsyncOptionsProviders;
|
|
18
22
|
private static getAsyncOptionsFactoryClass;
|
|
19
23
|
private static createAsyncOptionsProvider;
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.DefaultAuthenticationModuleOptionsFactory = exports.AuthenticationModule = void 0;
|
|
14
14
|
const common_1 = require("@nathapp/common");
|
|
15
15
|
const common_2 = require("@nestjs/common");
|
|
16
|
+
const core_1 = require("@nestjs/core");
|
|
16
17
|
const auth_provider_1 = require("../auth-provider");
|
|
17
18
|
const module_constant_1 = require("../constant/module-constant");
|
|
18
19
|
const strategy_1 = require("../strategy");
|
|
@@ -24,9 +25,7 @@ const defaultOptions = {
|
|
|
24
25
|
authProvider: auth_provider_1.SimpleAuthProvider,
|
|
25
26
|
};
|
|
26
27
|
const defaultAsyncOptions = {
|
|
27
|
-
|
|
28
|
-
useClass: auth_provider_1.SimpleAuthProvider,
|
|
29
|
-
},
|
|
28
|
+
logging: true,
|
|
30
29
|
};
|
|
31
30
|
let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
32
31
|
static forRoot(options) {
|
|
@@ -55,9 +54,10 @@ let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
56
|
static forRootAsync(options) {
|
|
58
|
-
|
|
57
|
+
const hasExplicitAuthProvider = options.authProvider !== undefined && options.authProvider !== null;
|
|
58
|
+
options = this.sanitizeAuthenticationModuleAsyncOptions(options);
|
|
59
59
|
const asyncOptionsProviders = this.createAsyncOptionsProviders(options);
|
|
60
|
-
const authProvider = this.createAsyncAuthProvider(options);
|
|
60
|
+
const authProvider = this.createAsyncAuthProvider(options, hasExplicitAuthProvider);
|
|
61
61
|
const strategyProvider = this.createAsyncStrategyProvider(options);
|
|
62
62
|
const refreshStrategyProvider = this.createAsyncRefreshStrategyProvider(options);
|
|
63
63
|
return {
|
|
@@ -73,18 +73,31 @@ let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
static sanitizeAuthenticationModuleOptions(options) {
|
|
76
|
-
var _a, _b;
|
|
77
76
|
if ('jwtOptions' in options) {
|
|
78
77
|
options = { ...defaultOptions, ...options };
|
|
79
|
-
|
|
80
|
-
options.refreshJwtOptions = { ...options.refreshJwtOptions, isBase64AsymmetricKey: options.jwtOptions.isBase64AsymmetricKey };
|
|
81
|
-
}
|
|
78
|
+
this.applyBase64AsymmetricKeyPropagation(options);
|
|
82
79
|
}
|
|
83
80
|
else {
|
|
84
81
|
options = { ...defaultAsyncOptions, ...options };
|
|
85
82
|
}
|
|
86
83
|
return options;
|
|
87
84
|
}
|
|
85
|
+
static sanitizeAuthenticationModuleAsyncOptions(options) {
|
|
86
|
+
options = { ...defaultAsyncOptions, ...options };
|
|
87
|
+
this.applyBase64AsymmetricKeyPropagation(options);
|
|
88
|
+
return options;
|
|
89
|
+
}
|
|
90
|
+
static applyBase64AsymmetricKeyPropagation(options) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
if (((_a = options.jwtOptions) === null || _a === void 0 ? void 0 : _a.isBase64AsymmetricKey) &&
|
|
93
|
+
options.refreshJwtOptions &&
|
|
94
|
+
((_b = options.refreshJwtOptions) === null || _b === void 0 ? void 0 : _b.isBase64AsymmetricKey) === undefined) {
|
|
95
|
+
options.refreshJwtOptions = {
|
|
96
|
+
...options.refreshJwtOptions,
|
|
97
|
+
isBase64AsymmetricKey: options.jwtOptions.isBase64AsymmetricKey,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
88
101
|
static createStrategyProvider(options) {
|
|
89
102
|
if (options.strategyProvider) {
|
|
90
103
|
return {
|
|
@@ -139,15 +152,31 @@ let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
|
139
152
|
inject: [module_constant_1.JWT_OPTIONS],
|
|
140
153
|
};
|
|
141
154
|
}
|
|
142
|
-
static createAsyncAuthProvider(options) {
|
|
143
|
-
if (
|
|
144
|
-
return
|
|
145
|
-
provide: module_constant_1.AUTH_PROVIDER,
|
|
146
|
-
useClass: auth_provider_1.SimpleAuthProvider,
|
|
147
|
-
};
|
|
155
|
+
static createAsyncAuthProvider(options, hasExplicitAuthProvider) {
|
|
156
|
+
if (hasExplicitAuthProvider && options.authProvider !== undefined && options.authProvider !== null) {
|
|
157
|
+
return (0, nestjs_common_1.createClassTypeOrAsyncOptionsProvider)(module_constant_1.AUTH_PROVIDER, options.authProvider);
|
|
148
158
|
}
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
return this.createResolvedAuthProvider();
|
|
160
|
+
}
|
|
161
|
+
static createResolvedAuthProvider() {
|
|
162
|
+
return {
|
|
163
|
+
provide: module_constant_1.AUTH_PROVIDER,
|
|
164
|
+
useFactory: async (resolvedOptions, moduleRef) => this.instantiateConfiguredAuthProvider(resolvedOptions === null || resolvedOptions === void 0 ? void 0 : resolvedOptions.authProvider, moduleRef),
|
|
165
|
+
inject: [module_constant_1.JWT_OPTIONS, core_1.ModuleRef],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
static async instantiateConfiguredAuthProvider(configured, moduleRef) {
|
|
169
|
+
if (configured === undefined || configured === null) {
|
|
170
|
+
return new auth_provider_1.SimpleAuthProvider();
|
|
171
|
+
}
|
|
172
|
+
if (typeof configured !== 'function') {
|
|
173
|
+
throw new Error('Unsupported "authProvider" returned from the resolved authentication options: ' +
|
|
174
|
+
`${describeReturnedAuthProviderValue(configured)}. A provider returned from resolved ` +
|
|
175
|
+
'options must be a provider class, which Nest instantiates with its constructor ' +
|
|
176
|
+
'dependencies injected. Declare "useClass", "useExisting" or "useFactory" on the async ' +
|
|
177
|
+
'registration options (AuthModule.forRootAsync({ authProvider: ... })) instead.');
|
|
178
|
+
}
|
|
179
|
+
return moduleRef.create(configured);
|
|
151
180
|
}
|
|
152
181
|
static createAsyncOptionsProviders(options) {
|
|
153
182
|
if (options.useExisting || options.useFactory) {
|
|
@@ -175,14 +204,14 @@ let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
|
175
204
|
return {
|
|
176
205
|
provide: module_constant_1.JWT_OPTIONS,
|
|
177
206
|
useFactory: async (...args) => {
|
|
178
|
-
return this.
|
|
207
|
+
return this.sanitizeAuthenticationModuleAsyncOptions((await useFactory(...args)));
|
|
179
208
|
},
|
|
180
209
|
inject: options.inject || [],
|
|
181
210
|
};
|
|
182
211
|
}
|
|
183
212
|
return {
|
|
184
213
|
provide: module_constant_1.JWT_OPTIONS,
|
|
185
|
-
useFactory: async (optionsFactory) => this.
|
|
214
|
+
useFactory: async (optionsFactory) => this.sanitizeAuthenticationModuleAsyncOptions((await optionsFactory.createOptions())),
|
|
186
215
|
inject: [this.getAsyncOptionsFactoryClass(options)],
|
|
187
216
|
};
|
|
188
217
|
}
|
|
@@ -191,6 +220,15 @@ exports.AuthenticationModule = AuthenticationModule;
|
|
|
191
220
|
exports.AuthenticationModule = AuthenticationModule = AuthenticationModule_1 = __decorate([
|
|
192
221
|
(0, common_2.Module)({})
|
|
193
222
|
], AuthenticationModule);
|
|
223
|
+
function describeReturnedAuthProviderValue(configured) {
|
|
224
|
+
if (typeof configured === 'object' && configured !== null) {
|
|
225
|
+
const keys = Object.keys(configured);
|
|
226
|
+
return keys.length > 0
|
|
227
|
+
? `an options object with ${keys.map((key) => `"${key}"`).join(', ')}`
|
|
228
|
+
: 'an empty options object';
|
|
229
|
+
}
|
|
230
|
+
return `a value of type ${typeof configured}`;
|
|
231
|
+
}
|
|
194
232
|
let DefaultAuthenticationModuleOptionsFactory = class DefaultAuthenticationModuleOptionsFactory {
|
|
195
233
|
constructor(configService) {
|
|
196
234
|
this.configService = configService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../lib/authentication/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,4CAA2D;AAC3D,2CAAiI;AACjI,oDAAoE;AACpE,iEAAyE;AACzE,0CAA2K;AAC3K,sFAAgF;AAGhF,2CAA+C;AAC/C,0DAA4G;AAE5G,MAAM,cAAc,GAAyC;IAC3D,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,kCAAkB;CACjC,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../lib/authentication/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,4CAA2D;AAC3D,2CAAiI;AACjI,uCAAyC;AACzC,oDAAoE;AACpE,iEAAyE;AACzE,0CAA2K;AAC3K,sFAAgF;AAGhF,2CAA+C;AAC/C,0DAA4G;AAE5G,MAAM,cAAc,GAAyC;IAC3D,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,kCAAkB;CACjC,CAAC;AASF,MAAM,mBAAmB,GAAyC;IAChE,OAAO,EAAE,IAAI;CACd,CAAC;AAQK,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,OAAoC;;QACjD,OAAO,GAAG,IAAI,CAAC,mCAAmC,CAAC,OAAO,CAAC,CAAC;QAE5D,MAAM,UAAU,GAAkB;YAChC,OAAO,EAAE,6BAAW;YACpB,QAAQ,EAAE,OAAO;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AsB;gBAC9C,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;gBAC9C,UAAU,EAAE;oBACV,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAiC;oBACxD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAsC;iBAC9D;gBACD,qBAAqB,EAAE,MAAA,IAAI,CAAC,YAAY,0CAAE,qBAAqB;aAChE;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxEY,8FAAyC;oDAAzC,yCAAyC;IADrD,IAAA,mBAAU,GAAE;qCAWiC,sBAAa;GAV9C,yCAAyC,CAwErD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional-auth.decorator.js","sourceRoot":"","sources":["../../lib/decorator/optional-auth.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAGhC,QAAA,oBAAoB,GAAG,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"optional-auth.decorator.js","sourceRoot":"","sources":["../../lib/decorator/optional-auth.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAGhC,QAAA,oBAAoB,GAAG,cAAc,CAAC;AAsB5C,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,4BAAoB,EAAE,IAAI,CAAC,CAAC;AAA7D,QAAA,YAAY,gBAAiD"}
|
|
@@ -18,6 +18,11 @@ const passport_1 = require("@nestjs/passport");
|
|
|
18
18
|
const constant_1 = require("../constant");
|
|
19
19
|
const decorator_1 = require("../decorator");
|
|
20
20
|
const base_jwt_strategy_provider_1 = require("../strategy/base-jwt-strategy-provider");
|
|
21
|
+
const credentialRejectionCodes = new Set([
|
|
22
|
+
nestjs_common_1.CommonExceptionCode.UNAUTHORIZED,
|
|
23
|
+
nestjs_common_1.CommonExceptionCode.FORBIDDEN_BLACKLISTED,
|
|
24
|
+
nestjs_common_1.CommonExceptionCode.FORBIDDEN_IP_NOT_MATCH,
|
|
25
|
+
]);
|
|
21
26
|
let JwtAuthGuard = JwtAuthGuard_1 = class JwtAuthGuard extends (0, passport_1.AuthGuard)(constant_1.JWT_STRATEGY_NAME) {
|
|
22
27
|
constructor(reflector) {
|
|
23
28
|
super();
|
|
@@ -50,7 +55,7 @@ let JwtAuthGuard = JwtAuthGuard_1 = class JwtAuthGuard extends (0, passport_1.Au
|
|
|
50
55
|
await super.canActivate(context);
|
|
51
56
|
}
|
|
52
57
|
catch (err) {
|
|
53
|
-
if (err instanceof nestjs_common_1.AppException) {
|
|
58
|
+
if (err instanceof nestjs_common_1.AppException && credentialRejectionCodes.has(err.code)) {
|
|
54
59
|
this.logger.warn(`optional auth: credential rejected, continuing anonymous: ${err.message}`);
|
|
55
60
|
return true;
|
|
56
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../lib/guard/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,0DAA2E;AAC3E,2CAAsE;AACtE,uCAAyC;AACzC,+CAA6C;AAC7C,0CAAgD;AAChD,4CAAmE;AACnE,uFAA4E;
|
|
1
|
+
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../lib/guard/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,0DAA2E;AAC3E,2CAAsE;AACtE,uCAAyC;AACzC,+CAA6C;AAC7C,0CAAgD;AAChD,4CAAmE;AACnE,uFAA4E;AAG5E,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAS;IAC/C,mCAAmB,CAAC,YAAY;IAChC,mCAAmB,CAAC,qBAAqB;IACzC,mCAAmB,CAAC,sBAAsB;CAC3C,CAAC,CAAC;AAYI,IAAM,YAAY,oBAAlB,MAAM,YAAa,SAAQ,IAAA,oBAAS,EAAC,4BAAiB,CAAC;IAI5D,YAAoB,SAAoB;QACtC,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAW;QAFvB,WAAM,GAAG,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AO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,GAAiB,EAAE,IAAS,EAAE,IAAS;QAEnD,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,MAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAA,IAAI,gBAAgB,EAAE,CAAC,CAAC;YAChG,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,GAAG,CAAC;YACZ,CAAC;YAMD,IAAI,IAAI,YAAY,+CAAkB,EAAE,CAAC;gBACvC,MAAM,IAAI,CAAC;YACb,CAAC;YACD,MAAM,IAAI,4BAAY,CAAC,mCAAmB,CAAC,YAAY,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAKoB,gBAAS;GAJ7B,YAAY,CAyExB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-auth",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "nestjs-auth",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist/ .turbo/",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@nathapp/common": "^0.1.14",
|
|
38
|
-
"@nathapp/nestjs-common": "^4.
|
|
38
|
+
"@nathapp/nestjs-common": "^4.6.0",
|
|
39
39
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
40
40
|
"@nestjs/config": "^3.0.0 || ^4.0.0 || ^12.0.0",
|
|
41
41
|
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|