@nathapp/nestjs-auth-2fa 2.1.4 → 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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +146 -0
- package/dist/decorator/index.d.ts +1 -0
- package/dist/decorator/index.js +18 -0
- package/dist/decorator/index.js.map +1 -0
- package/dist/decorator/two-factor.decorator.d.ts +7 -0
- package/dist/decorator/two-factor.decorator.js +14 -0
- package/dist/decorator/two-factor.decorator.js.map +1 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/enum/index.js +1 -0
- package/dist/enum/index.js.map +1 -1
- package/dist/enum/two-factor-policy.enum.d.ts +5 -0
- package/dist/enum/two-factor-policy.enum.js +10 -0
- package/dist/enum/two-factor-policy.enum.js.map +1 -0
- package/dist/enum/two-factor-type.enum.d.ts +4 -1
- package/dist/enum/two-factor-type.enum.js +4 -1
- package/dist/enum/two-factor-type.enum.js.map +1 -1
- package/dist/guard/base-two-factor.guard.d.ts +25 -0
- package/dist/guard/base-two-factor.guard.js +215 -0
- package/dist/guard/base-two-factor.guard.js.map +1 -0
- package/dist/guard/index.d.ts +1 -0
- package/dist/guard/index.js +1 -0
- package/dist/guard/index.js.map +1 -1
- package/dist/guard/two-factor-force.guard.d.ts +3 -10
- package/dist/guard/two-factor-force.guard.js +5 -50
- package/dist/guard/two-factor-force.guard.js.map +1 -1
- package/dist/guard/two-factor.guard.d.ts +4 -11
- package/dist/guard/two-factor.guard.js +8 -54
- package/dist/guard/two-factor.guard.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/module/two-factor-auth.interface.d.ts +17 -2
- package/dist/module/two-factor-auth.interface.js +8 -2
- package/dist/module/two-factor-auth.interface.js.map +1 -1
- package/dist/module/two-factor-auth.module.js +2 -1
- package/dist/module/two-factor-auth.module.js.map +1 -1
- package/dist/module/two-factor.provider.d.ts +1 -0
- package/dist/module/two-factor.provider.js +25 -2
- package/dist/module/two-factor.provider.js.map +1 -1
- package/dist/provider/two-factor-setting.provider.d.ts +13 -4
- package/dist/provider/two-factor-setting.provider.js +4 -0
- package/dist/provider/two-factor-setting.provider.js.map +1 -1
- package/dist/provider/two-factor.provider.d.ts +7 -8
- package/dist/provider/two-factor.provider.js +38 -5
- package/dist/provider/two-factor.provider.js.map +1 -1
- package/docs/20260215-fix-plan-auth-2fa-v3.md +165 -0
- package/docs/20260215-fix-plan-auth-2fa.md +179 -0
- package/docs/20260215-review-auth-2fa-deep.md +264 -0
- package/package.json +5 -5
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,151 @@
|
|
|
1
1
|
# @nathapp/nestjs-auth-2fa
|
|
2
2
|
|
|
3
|
+
## 3.0.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- # 🚀 v3.0.0-rc Monorepo Enterprise Upgrade
|
|
8
|
+
|
|
9
|
+
This release brings significant security, reliability, and observability improvements across the entire Nathapp ecosystem.
|
|
10
|
+
|
|
11
|
+
## ⚠️ [BREAKING CHANGES]
|
|
12
|
+
|
|
13
|
+
### nestjs-common
|
|
14
|
+
|
|
15
|
+
- **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, etc.).
|
|
16
|
+
- **SerializableInterceptor**: Now uses pure transformation. Original response objects are no longer mutated.
|
|
17
|
+
- **AppException**: Now generic `AppException<T>` for strict argument typing.
|
|
18
|
+
|
|
19
|
+
### nestjs-logging
|
|
20
|
+
|
|
21
|
+
- **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
|
|
22
|
+
- **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
|
|
23
|
+
|
|
24
|
+
## ✨ Features & Improvements
|
|
25
|
+
|
|
26
|
+
- **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**.
|
|
27
|
+
- **nestjs-microservices**: Full guard coverage and secured gRPC Bearer token extraction.
|
|
28
|
+
- **nestjs-typeorm**: Automatic mapping of database errors to `AppException`.
|
|
29
|
+
- **nestjs-auth-2fa**: Timing-safe TOTP verification and flexible policy engine.
|
|
30
|
+
- **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage.
|
|
31
|
+
- **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
|
|
32
|
+
- **nestjs-throttler**: Added async trust proxy support.
|
|
33
|
+
- **Global**: Comprehensive JSDoc for all public APIs across all packages.
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies
|
|
38
|
+
- @nathapp/nestjs-common@3.0.0-rc.0
|
|
39
|
+
- @nathapp/nestjs-auth@3.0.0-rc.0
|
|
40
|
+
|
|
41
|
+
## 2.1.5
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- # @nathapp/nestjs-notification v2.2.0 - Enterprise-Grade Upgrade
|
|
46
|
+
|
|
47
|
+
Major enterprise enhancements to the notification system with 9 phases of improvements:
|
|
48
|
+
|
|
49
|
+
## New Features
|
|
50
|
+
|
|
51
|
+
### Phase 1: Pluggable Template Engine
|
|
52
|
+
|
|
53
|
+
- `TemplateEngine` interface for custom template rendering
|
|
54
|
+
- `StringFormatEngine` as default (backwards compatible)
|
|
55
|
+
- Apps can now inject Handlebars, EJS, or custom engines
|
|
56
|
+
|
|
57
|
+
### Phase 2: Configurable Strict Mode
|
|
58
|
+
|
|
59
|
+
- `strict: true` (default) throws errors when services aren't configured
|
|
60
|
+
- `strict: false` for graceful degradation (returns `{ success: false }`)
|
|
61
|
+
- Clear error messages via `NotificationConfigError`
|
|
62
|
+
|
|
63
|
+
### Phase 3: Unified `send()` Method
|
|
64
|
+
|
|
65
|
+
- Single method dispatches to multiple channels
|
|
66
|
+
- `NotificationPayload` with `channels: ['email', 'push', 'sms']`
|
|
67
|
+
- Aggregated results across all channels
|
|
68
|
+
|
|
69
|
+
### Phase 4: Platform Alias
|
|
70
|
+
|
|
71
|
+
- Added `platform` field (deprecated `paltform` typo)
|
|
72
|
+
- Backwards compatible with fallback
|
|
73
|
+
|
|
74
|
+
### Phase 5: SMS Integration
|
|
75
|
+
|
|
76
|
+
- `SmsService` wired into `NotificationModule`
|
|
77
|
+
- `sendSms()` with full template support
|
|
78
|
+
- Ready for provider packages (Twilio, SNS)
|
|
79
|
+
|
|
80
|
+
### Phase 6: Interceptors & Hooks
|
|
81
|
+
|
|
82
|
+
- `NotificationInterceptor` interface
|
|
83
|
+
- `beforeSend`, `afterSend`, `onError` hooks
|
|
84
|
+
- Global logging, auditing, message modification
|
|
85
|
+
|
|
86
|
+
### Phase 7: WhatsApp Channel
|
|
87
|
+
|
|
88
|
+
- `WhatsAppService` abstract class
|
|
89
|
+
- `WhatsAppMessage` interface with Meta Business API support
|
|
90
|
+
- Template-based WhatsApp notifications
|
|
91
|
+
|
|
92
|
+
### Phase 8: Channel Fallback
|
|
93
|
+
|
|
94
|
+
- `fallback: ['sms']` on `NotificationPayload`
|
|
95
|
+
- Auto-retry through fallback channels when primary fails
|
|
96
|
+
- Interceptors receive `isFallback` + `failedChannel` context
|
|
97
|
+
|
|
98
|
+
### Phase 9: Unified Provider Registry (⚠️ Breaking)
|
|
99
|
+
|
|
100
|
+
- Replaced per-channel modules with unified `providers` array
|
|
101
|
+
- `NotificationProviderFactory` validates provider ↔ channel match
|
|
102
|
+
- `NotificationModuleOptionsFactory` for async configuration
|
|
103
|
+
- Simplified API: `NotificationModule.forRoot({ providers: [...] })`
|
|
104
|
+
|
|
105
|
+
## Breaking Changes (Phase 9)
|
|
106
|
+
|
|
107
|
+
- `emailOptions` → removed (use `providers` array)
|
|
108
|
+
- `pushNotificationOptions` → removed (use `providers` array)
|
|
109
|
+
- `smsService` → removed (use `providers` array)
|
|
110
|
+
- `whatsAppService` → removed (use `providers` array)
|
|
111
|
+
- `EmailModule`, `PushNotificationModule` no longer exported from main index
|
|
112
|
+
|
|
113
|
+
## Migration Guide
|
|
114
|
+
|
|
115
|
+
### Before
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
NotificationModule.forRoot({
|
|
119
|
+
emailOptions: EmailModule.forRoot({ option: { type: 'smtp', options: {...} } }),
|
|
120
|
+
templateLoader: MyLoader,
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### After
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
NotificationModule.forRoot({
|
|
128
|
+
providers: [
|
|
129
|
+
{
|
|
130
|
+
channel: "email",
|
|
131
|
+
provider: SmtpEmailProvider,
|
|
132
|
+
options: { url: "...", from: "..." },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
templateLoader: MyLoader,
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Stats
|
|
140
|
+
|
|
141
|
+
- **159 tests** (all passing)
|
|
142
|
+
- **88.5% code coverage**
|
|
143
|
+
- Fully backwards compatible (except Phase 9 breaking changes)
|
|
144
|
+
|
|
145
|
+
- Updated dependencies
|
|
146
|
+
- @nathapp/nestjs-auth@2.1.5
|
|
147
|
+
- @nathapp/nestjs-common@2.1.5
|
|
148
|
+
|
|
3
149
|
## 2.1.1
|
|
4
150
|
|
|
5
151
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './two-factor.decorator';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./two-factor.decorator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/decorator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TwoFactorPolicy } from '../enum/two-factor-policy.enum';
|
|
2
|
+
import { TwoFactorType } from '../enum/two-factor-type.enum';
|
|
3
|
+
export declare const TWO_FACTOR_POLICY = "TWO_FACTOR_POLICY";
|
|
4
|
+
export declare const TWO_FACTOR_ALLOWED_TYPES = "TWO_FACTOR_ALLOWED_TYPES";
|
|
5
|
+
export declare const SKIP_TWO_FACTOR = "SKIP_TWO_FACTOR";
|
|
6
|
+
export declare function TwoFactor(policy?: TwoFactorPolicy, allowedTypes?: TwoFactorType[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
7
|
+
export declare const SkipTwoFactor: () => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkipTwoFactor = exports.SKIP_TWO_FACTOR = exports.TWO_FACTOR_ALLOWED_TYPES = exports.TWO_FACTOR_POLICY = void 0;
|
|
4
|
+
exports.TwoFactor = TwoFactor;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
exports.TWO_FACTOR_POLICY = 'TWO_FACTOR_POLICY';
|
|
7
|
+
exports.TWO_FACTOR_ALLOWED_TYPES = 'TWO_FACTOR_ALLOWED_TYPES';
|
|
8
|
+
exports.SKIP_TWO_FACTOR = 'SKIP_TWO_FACTOR';
|
|
9
|
+
function TwoFactor(policy, allowedTypes) {
|
|
10
|
+
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.TWO_FACTOR_POLICY, policy), (0, common_1.SetMetadata)(exports.TWO_FACTOR_ALLOWED_TYPES, allowedTypes));
|
|
11
|
+
}
|
|
12
|
+
const SkipTwoFactor = () => (0, common_1.SetMetadata)(exports.SKIP_TWO_FACTOR, true);
|
|
13
|
+
exports.SkipTwoFactor = SkipTwoFactor;
|
|
14
|
+
//# sourceMappingURL=two-factor.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-factor.decorator.js","sourceRoot":"","sources":["../../lib/decorator/two-factor.decorator.ts"],"names":[],"mappings":";;;AA2CA,8BAQC;AAnDD,2CAA8D;AAOjD,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAKxC,QAAA,wBAAwB,GAAG,0BAA0B,CAAC;AAKtD,QAAA,eAAe,GAAG,iBAAiB,CAAC;AA0BjD,SAAgB,SAAS,CACvB,MAAwB,EACxB,YAA8B;IAE9B,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,yBAAiB,EAAE,MAAM,CAAC,EACtC,IAAA,oBAAW,EAAC,gCAAwB,EAAE,YAAY,CAAC,CACpD,CAAC;AACJ,CAAC;AAYM,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,uBAAe,EAAE,IAAI,CAAC,CAAC;AAAzD,QAAA,aAAa,iBAA4C"}
|
package/dist/enum/index.d.ts
CHANGED
package/dist/enum/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./two-factor-type.enum"), exports);
|
|
18
|
+
__exportStar(require("./two-factor-policy.enum"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/enum/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/enum/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/enum/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,2DAAyC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TwoFactorPolicy = void 0;
|
|
4
|
+
var TwoFactorPolicy;
|
|
5
|
+
(function (TwoFactorPolicy) {
|
|
6
|
+
TwoFactorPolicy["ANY"] = "ANY";
|
|
7
|
+
TwoFactorPolicy["ALL"] = "ALL";
|
|
8
|
+
TwoFactorPolicy["SPECIFIC"] = "SPECIFIC";
|
|
9
|
+
})(TwoFactorPolicy || (exports.TwoFactorPolicy = TwoFactorPolicy = {}));
|
|
10
|
+
//# sourceMappingURL=two-factor-policy.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-factor-policy.enum.js","sourceRoot":"","sources":["../../lib/enum/two-factor-policy.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,wCAAqB,CAAA;AACvB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TwoFactorType = void 0;
|
|
4
4
|
var TwoFactorType;
|
|
5
5
|
(function (TwoFactorType) {
|
|
6
|
-
TwoFactorType[
|
|
6
|
+
TwoFactorType["TOTP"] = "TOTP";
|
|
7
|
+
TwoFactorType["SMS_OTP"] = "SMS_OTP";
|
|
8
|
+
TwoFactorType["EMAIL_OTP"] = "EMAIL_OTP";
|
|
9
|
+
TwoFactorType["PASSKEY"] = "PASSKEY";
|
|
7
10
|
})(TwoFactorType || (exports.TwoFactorType = TwoFactorType = {}));
|
|
8
11
|
//# sourceMappingURL=two-factor-type.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"two-factor-type.enum.js","sourceRoot":"","sources":["../../lib/enum/two-factor-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"two-factor-type.enum.js","sourceRoot":"","sources":["../../lib/enum/two-factor-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,oCAAmB,CAAA;AACrB,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext, Logger } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { TwoFactorAuthProvider, TwoFactorSettingProvider } from '../provider';
|
|
4
|
+
import { TwoFactorAuthModuleOptionsWithoutProvider } from '../module';
|
|
5
|
+
import { TwoFactorType } from '../enum/two-factor-type.enum';
|
|
6
|
+
export declare abstract class BaseTwoFactorGuard implements CanActivate {
|
|
7
|
+
protected readonly options: TwoFactorAuthModuleOptionsWithoutProvider;
|
|
8
|
+
protected readonly providersMap: Map<TwoFactorType, TwoFactorAuthProvider>;
|
|
9
|
+
protected readonly twoFactorProvider: TwoFactorAuthProvider;
|
|
10
|
+
protected readonly twoFactorSettingProvider: TwoFactorSettingProvider;
|
|
11
|
+
protected readonly reflector?: Reflector;
|
|
12
|
+
protected logger: Logger;
|
|
13
|
+
constructor(options: TwoFactorAuthModuleOptionsWithoutProvider, providersMap: Map<TwoFactorType, TwoFactorAuthProvider>, twoFactorProvider: TwoFactorAuthProvider, twoFactorSettingProvider: TwoFactorSettingProvider, reflector?: Reflector);
|
|
14
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
15
|
+
protected abstract handleNoEnabledMethods(): boolean | Promise<boolean>;
|
|
16
|
+
private getPolicy;
|
|
17
|
+
private getAllowedTypes;
|
|
18
|
+
private verifyAnyPolicy;
|
|
19
|
+
private verifyAllPolicy;
|
|
20
|
+
private verifySpecificPolicy;
|
|
21
|
+
private getProviderForType;
|
|
22
|
+
private getTwoFactorTokenFromRequest;
|
|
23
|
+
private getTwoFactorTokensObjectFromRequest;
|
|
24
|
+
private getFieldFromRequest;
|
|
25
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var BaseTwoFactorGuard_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.BaseTwoFactorGuard = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const core_1 = require("@nestjs/core");
|
|
19
|
+
const provider_1 = require("../provider");
|
|
20
|
+
const module_1 = require("../module");
|
|
21
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
22
|
+
const two_factor_policy_enum_1 = require("../enum/two-factor-policy.enum");
|
|
23
|
+
const two_factor_decorator_1 = require("../decorator/two-factor.decorator");
|
|
24
|
+
let BaseTwoFactorGuard = BaseTwoFactorGuard_1 = class BaseTwoFactorGuard {
|
|
25
|
+
constructor(options, providersMap, twoFactorProvider, twoFactorSettingProvider, reflector) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.providersMap = providersMap;
|
|
28
|
+
this.twoFactorProvider = twoFactorProvider;
|
|
29
|
+
this.twoFactorSettingProvider = twoFactorSettingProvider;
|
|
30
|
+
this.reflector = reflector;
|
|
31
|
+
this.logger = new common_1.Logger(BaseTwoFactorGuard_1.name);
|
|
32
|
+
}
|
|
33
|
+
async canActivate(context) {
|
|
34
|
+
const contextType = context.getType ? context.getType() : 'http';
|
|
35
|
+
if (contextType !== 'http') {
|
|
36
|
+
this.logger.warn(`TwoFactorGuard only supports HTTP context, got: ${contextType}`);
|
|
37
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
38
|
+
}
|
|
39
|
+
if (!this.options.enabled) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (this.reflector) {
|
|
43
|
+
const skipTwoFactor = this.reflector.get(two_factor_decorator_1.SKIP_TWO_FACTOR, context.getHandler());
|
|
44
|
+
if (skipTwoFactor) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const request = context.switchToHttp().getRequest();
|
|
49
|
+
const user = request.user;
|
|
50
|
+
if (!user) {
|
|
51
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
52
|
+
}
|
|
53
|
+
const allSettings = await this.twoFactorSettingProvider.getTwoFactorSettings(user);
|
|
54
|
+
if (!allSettings || allSettings.length === 0) {
|
|
55
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
56
|
+
}
|
|
57
|
+
const enabledSettings = allSettings.filter(s => s.isSet);
|
|
58
|
+
if (enabledSettings.length === 0) {
|
|
59
|
+
return await this.handleNoEnabledMethods();
|
|
60
|
+
}
|
|
61
|
+
const policy = this.getPolicy(context);
|
|
62
|
+
const allowedTypes = this.getAllowedTypes(context);
|
|
63
|
+
switch (policy) {
|
|
64
|
+
case two_factor_policy_enum_1.TwoFactorPolicy.ANY:
|
|
65
|
+
return await this.verifyAnyPolicy(request, enabledSettings);
|
|
66
|
+
case two_factor_policy_enum_1.TwoFactorPolicy.ALL:
|
|
67
|
+
return await this.verifyAllPolicy(request, enabledSettings);
|
|
68
|
+
case two_factor_policy_enum_1.TwoFactorPolicy.SPECIFIC:
|
|
69
|
+
return await this.verifySpecificPolicy(request, enabledSettings, allowedTypes);
|
|
70
|
+
default:
|
|
71
|
+
return await this.verifyAnyPolicy(request, enabledSettings);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getPolicy(context) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (this.reflector) {
|
|
77
|
+
const decoratorPolicy = this.reflector.get(two_factor_decorator_1.TWO_FACTOR_POLICY, context.getHandler());
|
|
78
|
+
if (decoratorPolicy) {
|
|
79
|
+
return decoratorPolicy;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return (_a = this.options.defaultPolicy) !== null && _a !== void 0 ? _a : two_factor_policy_enum_1.TwoFactorPolicy.ANY;
|
|
83
|
+
}
|
|
84
|
+
getAllowedTypes(context) {
|
|
85
|
+
if (this.reflector) {
|
|
86
|
+
return this.reflector.get(two_factor_decorator_1.TWO_FACTOR_ALLOWED_TYPES, context.getHandler());
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
async verifyAnyPolicy(request, enabledSettings) {
|
|
91
|
+
const token = this.getTwoFactorTokenFromRequest(request);
|
|
92
|
+
if (!token) {
|
|
93
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
94
|
+
}
|
|
95
|
+
for (const setting of enabledSettings) {
|
|
96
|
+
const provider = this.getProviderForType(setting.type);
|
|
97
|
+
if (!provider) {
|
|
98
|
+
this.logger.warn(`No provider found for type ${setting.type}`);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const result = await provider.verify(token, setting.context);
|
|
103
|
+
if (result) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
this.logger.debug(`Verification failed for ${setting.type}: ${error.message}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
112
|
+
}
|
|
113
|
+
async verifyAllPolicy(request, enabledSettings) {
|
|
114
|
+
const tokens = this.getTwoFactorTokensObjectFromRequest(request);
|
|
115
|
+
if (!tokens || typeof tokens !== 'object') {
|
|
116
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
117
|
+
}
|
|
118
|
+
for (const setting of enabledSettings) {
|
|
119
|
+
const provider = this.getProviderForType(setting.type);
|
|
120
|
+
if (!provider) {
|
|
121
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
122
|
+
}
|
|
123
|
+
const token = tokens[setting.type];
|
|
124
|
+
if (!token) {
|
|
125
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
126
|
+
}
|
|
127
|
+
const result = await provider.verify(token, setting.context);
|
|
128
|
+
if (!result) {
|
|
129
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
async verifySpecificPolicy(request, enabledSettings, allowedTypes) {
|
|
135
|
+
var _a;
|
|
136
|
+
if (!allowedTypes || allowedTypes.length === 0) {
|
|
137
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
138
|
+
}
|
|
139
|
+
const filteredSettings = enabledSettings.filter(s => allowedTypes.includes(s.type));
|
|
140
|
+
if (filteredSettings.length === 0) {
|
|
141
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
142
|
+
}
|
|
143
|
+
const { typeField } = {
|
|
144
|
+
typeField: '2fa-type',
|
|
145
|
+
...(_a = this.options) === null || _a === void 0 ? void 0 : _a.guardOptions,
|
|
146
|
+
};
|
|
147
|
+
const requestedType = this.getFieldFromRequest(request, typeField);
|
|
148
|
+
const token = this.getTwoFactorTokenFromRequest(request);
|
|
149
|
+
if (!token) {
|
|
150
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
151
|
+
}
|
|
152
|
+
if (!requestedType) {
|
|
153
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
154
|
+
}
|
|
155
|
+
const setting = filteredSettings.find(s => s.type === requestedType);
|
|
156
|
+
if (!setting) {
|
|
157
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
158
|
+
}
|
|
159
|
+
const provider = this.getProviderForType(setting.type);
|
|
160
|
+
if (!provider) {
|
|
161
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
162
|
+
}
|
|
163
|
+
const result = await provider.verify(token, setting.context);
|
|
164
|
+
if (!result) {
|
|
165
|
+
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
getProviderForType(type) {
|
|
170
|
+
if (this.providersMap) {
|
|
171
|
+
return this.providersMap.get(type);
|
|
172
|
+
}
|
|
173
|
+
return this.twoFactorProvider;
|
|
174
|
+
}
|
|
175
|
+
getTwoFactorTokenFromRequest(request) {
|
|
176
|
+
var _a;
|
|
177
|
+
const { from, field } = {
|
|
178
|
+
...module_1.DEFAULT_TWO_FACTOR_GUARD_OPTIONS,
|
|
179
|
+
...(_a = this.options) === null || _a === void 0 ? void 0 : _a.guardOptions,
|
|
180
|
+
};
|
|
181
|
+
return this.getFieldFromRequest(request, field, from);
|
|
182
|
+
}
|
|
183
|
+
getTwoFactorTokensObjectFromRequest(request) {
|
|
184
|
+
var _a;
|
|
185
|
+
const { from, field } = {
|
|
186
|
+
...module_1.DEFAULT_TWO_FACTOR_GUARD_OPTIONS,
|
|
187
|
+
...(_a = this.options) === null || _a === void 0 ? void 0 : _a.guardOptions,
|
|
188
|
+
};
|
|
189
|
+
return this.getFieldFromRequest(request, field, from);
|
|
190
|
+
}
|
|
191
|
+
getFieldFromRequest(request, field, from) {
|
|
192
|
+
var _a, _b, _c;
|
|
193
|
+
const source = (_c = from !== null && from !== void 0 ? from : (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.guardOptions) === null || _b === void 0 ? void 0 : _b.from) !== null && _c !== void 0 ? _c : 'body';
|
|
194
|
+
if (source === 'header') {
|
|
195
|
+
return request.headers[field];
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return request.body[field];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
exports.BaseTwoFactorGuard = BaseTwoFactorGuard;
|
|
203
|
+
exports.BaseTwoFactorGuard = BaseTwoFactorGuard = BaseTwoFactorGuard_1 = __decorate([
|
|
204
|
+
(0, common_1.Injectable)(),
|
|
205
|
+
__param(0, (0, common_1.Inject)(module_1.TWO_FACTOR_AUTH_MODULE_OPTIONS)),
|
|
206
|
+
__param(1, (0, common_1.Optional)()),
|
|
207
|
+
__param(1, (0, common_1.Inject)(module_1.TWO_FACTOR_PROVIDERS_MAP)),
|
|
208
|
+
__param(2, (0, common_1.Optional)()),
|
|
209
|
+
__param(4, (0, common_1.Optional)()),
|
|
210
|
+
__metadata("design:paramtypes", [Object, Map,
|
|
211
|
+
provider_1.TwoFactorAuthProvider,
|
|
212
|
+
provider_1.TwoFactorSettingProvider,
|
|
213
|
+
core_1.Reflector])
|
|
214
|
+
], BaseTwoFactorGuard);
|
|
215
|
+
//# sourceMappingURL=base-two-factor.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-two-factor.guard.js","sourceRoot":"","sources":["../../lib/guard/base-two-factor.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqG;AACrG,uCAAyC;AACzC,0CAAgG;AAChG,sCAAkK;AAClK,0DAA+F;AAC/F,2EAAiE;AAEjE,4EAAiH;AA8B1G,IAAe,kBAAkB,0BAAjC,MAAe,kBAAkB;IAItC,YAEE,OAAqE,EAErE,YAA0E,EAE1E,iBAA2D,EACxC,wBAAkD,EAErE,SAAwC;QAPrB,YAAO,GAAP,OAAO,CAA2C;QAElD,iBAAY,GAAZ,YAAY,CAA2C;QAEvD,sBAAiB,GAAjB,iBAAiB,CAAuB;QACxC,6BAAwB,GAAxB,wBAAwB,CAA0B;QAElD,cAAS,GAAT,SAAS,CAAY;QAXhC,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;IAYrD,CAAC;IAmBH,KAAK,CAAC,WAAW,CAAC,OAAyB;QAEzC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QACjE,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mDAAmD,WAAW,EAAE,CAAC,CAAC;YACnF,MAAM,IAAI,yCAAyB,EAAE,CAAC;QACxC,CAAC;QAGD,IAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAGD,IAAG,IAAI,CAAC,SAAS,EAA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AO,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CAEF,CAAA;AAlRqB,gDAAkB;6BAAlB,kBAAkB;IADvC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,uCAA8B,CAAC,CAAA;IAEtC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,iCAAwB,CAAC,CAAA;IAE5C,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAGV,WAAA,IAAA,iBAAQ,GAAE,CAAA;6CAJsB,GAAG;QAEE,gCAAqB;QACd,mCAAwB;QAEtC,gBAAS;GAbtB,kBAAkB,CAkRvC"}
|
package/dist/guard/index.d.ts
CHANGED
package/dist/guard/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base-two-factor.guard"), exports);
|
|
17
18
|
__exportStar(require("./two-factor.guard"), exports);
|
|
18
19
|
__exportStar(require("./two-factor-force.guard"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/guard/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/guard/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,2DAAyC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/guard/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,qDAAmC;AACnC,2DAAyC"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare class TwoFactorForceGuard implements CanActivate {
|
|
5
|
-
protected readonly options: TwoFactorAuthModuleOptionsWithoutProvider;
|
|
6
|
-
protected readonly twoFactorProvider: TwoFactorAuthProvider;
|
|
7
|
-
protected readonly twoFactorSettingProvider: TwoFactorSettingProvider;
|
|
8
|
-
constructor(options: TwoFactorAuthModuleOptionsWithoutProvider, twoFactorProvider: TwoFactorAuthProvider, twoFactorSettingProvider: TwoFactorSettingProvider);
|
|
9
|
-
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
10
|
-
private getTwoFactorTokenFromRequest;
|
|
1
|
+
import { BaseTwoFactorGuard } from './base-two-factor.guard';
|
|
2
|
+
export declare class TwoFactorForceGuard extends BaseTwoFactorGuard {
|
|
3
|
+
protected handleNoEnabledMethods(): never;
|
|
11
4
|
}
|
|
@@ -5,63 +5,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
9
|
exports.TwoFactorForceGuard = void 0;
|
|
16
10
|
const common_1 = require("@nestjs/common");
|
|
17
|
-
const provider_1 = require("../provider");
|
|
18
|
-
const module_1 = require("../module");
|
|
19
11
|
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.twoFactorSettingProvider = twoFactorSettingProvider;
|
|
25
|
-
}
|
|
26
|
-
async canActivate(context) {
|
|
27
|
-
if (!this.options.enabled) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
const request = context.switchToHttp().getRequest();
|
|
31
|
-
const user = request.user;
|
|
32
|
-
if (!user) {
|
|
33
|
-
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
34
|
-
}
|
|
35
|
-
const twoFactorToken = this.getTwoFactorTokenFromRequest(request);
|
|
36
|
-
if (!twoFactorToken) {
|
|
37
|
-
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
38
|
-
}
|
|
39
|
-
const settings = await this.twoFactorSettingProvider.getTwoFactorSetting(user);
|
|
40
|
-
if (!settings) {
|
|
41
|
-
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
42
|
-
}
|
|
43
|
-
const result = await this.twoFactorProvider.verify(twoFactorToken, settings.secret);
|
|
44
|
-
if (!result) {
|
|
45
|
-
throw new nestjs_common_1.TwoFactorInvalidException();
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
getTwoFactorTokenFromRequest(request) {
|
|
50
|
-
var _a;
|
|
51
|
-
const { from = 'body', field = '2fa' } = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.guardOptions) || {};
|
|
52
|
-
if (from === 'header') {
|
|
53
|
-
return request.headers[field];
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return request.body[field];
|
|
57
|
-
}
|
|
12
|
+
const base_two_factor_guard_1 = require("./base-two-factor.guard");
|
|
13
|
+
let TwoFactorForceGuard = class TwoFactorForceGuard extends base_two_factor_guard_1.BaseTwoFactorGuard {
|
|
14
|
+
handleNoEnabledMethods() {
|
|
15
|
+
throw new nestjs_common_1.TwoFactorRequiredException();
|
|
58
16
|
}
|
|
59
17
|
};
|
|
60
18
|
exports.TwoFactorForceGuard = TwoFactorForceGuard;
|
|
61
19
|
exports.TwoFactorForceGuard = TwoFactorForceGuard = __decorate([
|
|
62
|
-
(0, common_1.Injectable)()
|
|
63
|
-
__param(0, (0, common_1.Inject)(module_1.TWO_FACTOR_AUTH_MODULE_OPTIONS)),
|
|
64
|
-
__metadata("design:paramtypes", [Object, provider_1.TwoFactorAuthProvider,
|
|
65
|
-
provider_1.TwoFactorSettingProvider])
|
|
20
|
+
(0, common_1.Injectable)()
|
|
66
21
|
], TwoFactorForceGuard);
|
|
67
22
|
//# sourceMappingURL=two-factor-force.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"two-factor-force.guard.js","sourceRoot":"","sources":["../../lib/guard/two-factor-force.guard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"two-factor-force.guard.js","sourceRoot":"","sources":["../../lib/guard/two-factor-force.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,0DAAoE;AACpE,mEAA6D;AAiCtD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,0CAAkB;IAS/C,sBAAsB;QAE9B,MAAM,IAAI,0CAA0B,EAAE,CAAC;IACzC,CAAC;CAEF,CAAA;AAdY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CAc/B"}
|