@solidxai/core 0.1.5-beta.1 → 0.1.5-beta.2
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/settings.json +17 -0
- package/.claude/settings.local.json +7 -1
- package/dist/helpers/solid-microservice-adapter.service.d.ts +6 -0
- package/dist/helpers/solid-microservice-adapter.service.d.ts.map +1 -1
- package/dist/helpers/solid-microservice-adapter.service.js +52 -3
- package/dist/helpers/solid-microservice-adapter.service.js.map +1 -1
- package/dist/services/authentication.service.d.ts +2 -0
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +35 -12
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +10 -0
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +1 -0
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/solid-microservice-adapter.service.ts +47 -2
- package/src/services/authentication.service.ts +39 -12
- package/src/services/settings/default-settings-provider.service.ts +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"WebFetch(domain:api.github.com)",
|
|
5
|
+
"Read(//Users/oswald/projects/Solid_Starters/solid-core-ui/**)",
|
|
6
|
+
"Bash(grep -E \"\\\\.md|\\\\.json|\\\\.config|\\\\.ts$|\\\\.js$\")",
|
|
7
|
+
"Bash(xargs basename -a)",
|
|
8
|
+
"Read(//Users/oswald/projects/Solid_Starters/solid-code-builder/**)",
|
|
9
|
+
"Bash(grep -E \"\\\\.\\(md|json\\)$|^d\")",
|
|
10
|
+
"Bash(ls -la /Users/oswald/projects/Solid_Starters/solid-code-builder/*.json)"
|
|
11
|
+
],
|
|
12
|
+
"additionalDirectories": [
|
|
13
|
+
"/Users/oswald/projects/Solid_Starters/solid-core-ui",
|
|
14
|
+
"/Users/oswald/projects/Solid_Starters/solid-code-builder"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
"permissions": {
|
|
3
3
|
"allow": [
|
|
4
4
|
"Bash(node -e:*)",
|
|
5
|
-
"WebFetch(domain:docs.solidxai.com)"
|
|
5
|
+
"WebFetch(domain:docs.solidxai.com)",
|
|
6
|
+
"WebFetch(domain:github.com)",
|
|
7
|
+
"Read(//Users/oswald/projects/Solid_Starters/solidctl/**)",
|
|
8
|
+
"Read(//Users/oswald/projects/Solid_Starters/**)"
|
|
9
|
+
],
|
|
10
|
+
"additionalDirectories": [
|
|
11
|
+
"/Users/oswald/projects/Solid_Starters/solidctl"
|
|
6
12
|
]
|
|
7
13
|
}
|
|
8
14
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cache } from 'cache-manager';
|
|
1
2
|
export interface SolidxIamAuthRequest {
|
|
2
3
|
email?: string;
|
|
3
4
|
username?: string;
|
|
@@ -23,9 +24,14 @@ export interface SolidxIamAuthResponse {
|
|
|
23
24
|
data: SolidxIamAuthData;
|
|
24
25
|
}
|
|
25
26
|
export declare class SolidMicroserviceAdapter {
|
|
27
|
+
private readonly cacheManager;
|
|
26
28
|
private readonly logger;
|
|
27
29
|
private baseUrl?;
|
|
30
|
+
constructor(cacheManager: Cache);
|
|
28
31
|
setBaseUrl(baseUrl: string): this;
|
|
29
32
|
authenticate({ email, username, password }: SolidxIamAuthRequest): Promise<SolidxIamAuthResponse>;
|
|
33
|
+
private getAuthCacheKey;
|
|
34
|
+
private getJwtTtlSeconds;
|
|
35
|
+
private base64UrlToBase64;
|
|
30
36
|
}
|
|
31
37
|
//# sourceMappingURL=solid-microservice-adapter.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-microservice-adapter.service.d.ts","sourceRoot":"","sources":["../../src/helpers/solid-microservice-adapter.service.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,qBACa,wBAAwB;
|
|
1
|
+
{"version":3,"file":"solid-microservice-adapter.service.d.ts","sourceRoot":"","sources":["../../src/helpers/solid-microservice-adapter.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,qBACa,wBAAwB;IAIA,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHhE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;IACpE,OAAO,CAAC,OAAO,CAAC,CAAS;gBAE2B,YAAY,EAAE,KAAK;IAEvE,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK3B,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0CvG,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,iBAAiB;CAK1B"}
|
|
@@ -5,16 +5,24 @@ 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
|
+
};
|
|
8
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
16
|
};
|
|
11
17
|
var SolidMicroserviceAdapter_1;
|
|
12
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
19
|
exports.SolidMicroserviceAdapter = void 0;
|
|
20
|
+
const cache_manager_1 = require("@nestjs/cache-manager");
|
|
14
21
|
const common_1 = require("@nestjs/common");
|
|
15
22
|
const axios_1 = __importDefault(require("axios"));
|
|
16
23
|
let SolidMicroserviceAdapter = SolidMicroserviceAdapter_1 = class SolidMicroserviceAdapter {
|
|
17
|
-
constructor() {
|
|
24
|
+
constructor(cacheManager) {
|
|
25
|
+
this.cacheManager = cacheManager;
|
|
18
26
|
this.logger = new common_1.Logger(SolidMicroserviceAdapter_1.name);
|
|
19
27
|
}
|
|
20
28
|
setBaseUrl(baseUrl) {
|
|
@@ -28,6 +36,13 @@ let SolidMicroserviceAdapter = SolidMicroserviceAdapter_1 = class SolidMicroserv
|
|
|
28
36
|
if (!email && !username) {
|
|
29
37
|
throw new Error('email or username is required for IAM authentication');
|
|
30
38
|
}
|
|
39
|
+
const cacheKey = this.getAuthCacheKey(email, username);
|
|
40
|
+
const cachedResponse = (await this.cacheManager.get(cacheKey));
|
|
41
|
+
if (cachedResponse) {
|
|
42
|
+
this.logger.debug(`IAM auth cache hit for ${cacheKey}`);
|
|
43
|
+
return cachedResponse;
|
|
44
|
+
}
|
|
45
|
+
this.logger.debug(`IAM auth cache miss for ${cacheKey}`);
|
|
31
46
|
if (!this.baseUrl) {
|
|
32
47
|
throw new Error('baseUrl must be set before IAM authentication');
|
|
33
48
|
}
|
|
@@ -43,11 +58,45 @@ let SolidMicroserviceAdapter = SolidMicroserviceAdapter_1 = class SolidMicroserv
|
|
|
43
58
|
'Content-Type': 'application/json',
|
|
44
59
|
},
|
|
45
60
|
});
|
|
46
|
-
|
|
61
|
+
const responseData = response.data;
|
|
62
|
+
const ttlSeconds = this.getJwtTtlSeconds(responseData?.data?.accessToken);
|
|
63
|
+
if (ttlSeconds && ttlSeconds > 0) {
|
|
64
|
+
await this.cacheManager.set(cacheKey, responseData, ttlSeconds);
|
|
65
|
+
}
|
|
66
|
+
return responseData;
|
|
67
|
+
}
|
|
68
|
+
getAuthCacheKey(email, username) {
|
|
69
|
+
return `iam-auth:${email ?? ''}:${username ?? ''}`;
|
|
70
|
+
}
|
|
71
|
+
getJwtTtlSeconds(accessToken) {
|
|
72
|
+
if (!accessToken)
|
|
73
|
+
return undefined;
|
|
74
|
+
const parts = accessToken.split('.');
|
|
75
|
+
if (parts.length < 2)
|
|
76
|
+
return undefined;
|
|
77
|
+
try {
|
|
78
|
+
const payloadJson = Buffer.from(this.base64UrlToBase64(parts[1]), 'base64').toString('utf-8');
|
|
79
|
+
const payload = JSON.parse(payloadJson);
|
|
80
|
+
if (!payload?.exp || typeof payload.exp !== 'number')
|
|
81
|
+
return undefined;
|
|
82
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
83
|
+
const ttl = payload.exp - nowSeconds - 10;
|
|
84
|
+
return ttl > 0 ? ttl : undefined;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
base64UrlToBase64(value) {
|
|
91
|
+
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
92
|
+
const padLength = (4 - (normalized.length % 4)) % 4;
|
|
93
|
+
return normalized + '='.repeat(padLength);
|
|
47
94
|
}
|
|
48
95
|
};
|
|
49
96
|
exports.SolidMicroserviceAdapter = SolidMicroserviceAdapter;
|
|
50
97
|
exports.SolidMicroserviceAdapter = SolidMicroserviceAdapter = SolidMicroserviceAdapter_1 = __decorate([
|
|
51
|
-
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT })
|
|
98
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
99
|
+
__param(0, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)),
|
|
100
|
+
__metadata("design:paramtypes", [Object])
|
|
52
101
|
], SolidMicroserviceAdapter);
|
|
53
102
|
//# sourceMappingURL=solid-microservice-adapter.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-microservice-adapter.service.js","sourceRoot":"","sources":["../../src/helpers/solid-microservice-adapter.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"solid-microservice-adapter.service.js","sourceRoot":"","sources":["../../src/helpers/solid-microservice-adapter.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,yDAAsD;AACtD,2CAAmE;AACnE,kDAA0B;AAgCnB,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAInC,YAAmC,YAAoC;QAAnB,iBAAY,GAAZ,YAAY,CAAO;QAHtD,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAGM,CAAC;IAE3E,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAwB;QACpE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,MAAM,cAAc,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAsC,CAAC;QACpG,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;YACxD,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,QAAQ,EAAE,CAAC,C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ent":["import { CACHE_MANAGER } from '@nestjs/cache-manager';\nimport { Inject, Injectable, Logger, Scope } from '@nestjs/common';\nimport axios from 'axios';\nimport { Cache } from 'cache-manager';\n\nexport interface SolidxIamAuthRequest {\n email?: string;\n username?: string;\n password: string;\n}\n\nexport interface SolidxIamUser {\n email: string;\n mobile: string;\n username: string;\n forcePasswordChange: boolean;\n id: number;\n roles: string[];\n}\n\nexport interface SolidxIamAuthData {\n user: SolidxIamUser;\n accessToken: string;\n refreshToken: string;\n}\n\nexport interface SolidxIamAuthResponse {\n statusCode: number;\n message: string[];\n error: string;\n data: SolidxIamAuthData;\n}\n\n@Injectable({ scope: Scope.TRANSIENT })\nexport class SolidMicroserviceAdapter {\n private readonly logger = new Logger(SolidMicroserviceAdapter.name);\n private baseUrl?: string;\n\n constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}\n\n setBaseUrl(baseUrl: string): this {\n this.baseUrl = baseUrl;\n return this;\n }\n\n async authenticate({ email, username, password }: SolidxIamAuthRequest): Promise<SolidxIamAuthResponse> {\n if (!password) {\n throw new Error('password is required for IAM authentication');\n }\n if (!email && !username) {\n throw new Error('email or username is required for IAM authentication');\n }\n\n const cacheKey = this.getAuthCacheKey(email, username);\n const cachedResponse = (await this.cacheManager.get(cacheKey)) as SolidxIamAuthResponse | undefined;\n if (cachedResponse) {\n this.logger.debug(`IAM auth cache hit for ${cacheKey}`);\n return cachedResponse;\n }\n this.logger.debug(`IAM auth cache miss for ${cacheKey}`);\n\n if (!this.baseUrl) {\n throw new Error('baseUrl must be set before IAM authentication');\n }\n\n const payload: SolidxIamAuthRequest = { password };\n if (email) payload.email = email;\n if (username) payload.username = username;\n\n this.logger.debug(`Requesting IAM access token from ${this.baseUrl}/api/iam/authenticate`);\n\n const response = await axios.post(`${this.baseUrl}/api/iam/authenticate`, payload, {\n timeout: 10000,\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n const responseData = response.data as SolidxIamAuthResponse;\n const ttlSeconds = this.getJwtTtlSeconds(responseData?.data?.accessToken);\n if (ttlSeconds && ttlSeconds > 0) {\n await this.cacheManager.set(cacheKey, responseData, ttlSeconds);\n }\n\n return responseData;\n }\n\n private getAuthCacheKey(email?: string, username?: string): string {\n return `iam-auth:${email ?? ''}:${username ?? ''}`;\n }\n\n private getJwtTtlSeconds(accessToken?: string): number | undefined {\n if (!accessToken) return undefined;\n const parts = accessToken.split('.');\n if (parts.length < 2) return undefined;\n try {\n const payloadJson = Buffer.from(this.base64UrlToBase64(parts[1]), 'base64').toString('utf-8');\n const payload = JSON.parse(payloadJson) as { exp?: number };\n if (!payload?.exp || typeof payload.exp !== 'number') return undefined;\n const nowSeconds = Math.floor(Date.now() / 1000);\n const ttl = payload.exp - nowSeconds - 10;\n return ttl > 0 ? ttl : undefined;\n } catch {\n return undefined;\n }\n }\n\n private base64UrlToBase64(value: string): string {\n const normalized = value.replace(/-/g, '+').replace(/_/g, '/');\n const padLength = (4 - (normalized.length % 4)) % 4;\n return normalized + '='.repeat(padLength);\n }\n}\n"]}
|
|
@@ -74,6 +74,8 @@ export declare class AuthenticationService {
|
|
|
74
74
|
private triggerRegistrationEvent;
|
|
75
75
|
private areAllPasswordlessRegistrationValidationSourcesVerified;
|
|
76
76
|
private otp;
|
|
77
|
+
private getDummyOtpForUser;
|
|
78
|
+
private getDummyOtpUsers;
|
|
77
79
|
signIn(signInDto: SignInDto): Promise<{
|
|
78
80
|
accessToken: string;
|
|
79
81
|
refreshToken: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO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;;IAuC3B,YAAY,CAAC,MAAM,EAAE,MAAM;IAS3B,EAAE,CAAC,UAAU,EAAE,cAAc;;;;;;;;;;CA8BtC"}
|
|
@@ -347,7 +347,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
347
347
|
}
|
|
348
348
|
async notifyUserOnOtpInitiateRegistration(user, registrationValidationSource) {
|
|
349
349
|
const companyLogo = await this.getCompanyLogo();
|
|
350
|
-
const dummyOtp = this.
|
|
350
|
+
const dummyOtp = this.getDummyOtpForUser(user);
|
|
351
351
|
if (dummyOtp)
|
|
352
352
|
return;
|
|
353
353
|
if (registrationValidationSource === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
@@ -443,16 +443,41 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
443
443
|
}
|
|
444
444
|
return true;
|
|
445
445
|
}
|
|
446
|
-
async otp() {
|
|
446
|
+
async otp(user) {
|
|
447
447
|
const now = new Date();
|
|
448
448
|
const otpExpiry = this.settingService.getConfigValue('otpExpiry');
|
|
449
|
-
const dummyOtp = this.
|
|
449
|
+
const dummyOtp = this.getDummyOtpForUser(user);
|
|
450
450
|
now.setMinutes(now.getMinutes() + otpExpiry);
|
|
451
451
|
return {
|
|
452
452
|
token: dummyOtp ? dummyOtp : (0, crypto_1.randomInt)(100000, 999999).toString(),
|
|
453
453
|
expiresAt: now,
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
|
+
getDummyOtpForUser(user) {
|
|
457
|
+
const dummyOtp = this.settingService.getConfigValue('dummyOtp');
|
|
458
|
+
if (!dummyOtp || !user?.username) {
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
const allowedUsers = this.getDummyOtpUsers();
|
|
462
|
+
if (!allowedUsers.size) {
|
|
463
|
+
return undefined;
|
|
464
|
+
}
|
|
465
|
+
const username = user.username.trim().toLowerCase();
|
|
466
|
+
if (!username) {
|
|
467
|
+
return undefined;
|
|
468
|
+
}
|
|
469
|
+
return allowedUsers.has(username) ? dummyOtp : undefined;
|
|
470
|
+
}
|
|
471
|
+
getDummyOtpUsers() {
|
|
472
|
+
const rawUsers = this.settingService.getConfigValue('dummyOtpUsers');
|
|
473
|
+
if (!rawUsers || typeof rawUsers !== 'string') {
|
|
474
|
+
return new Set();
|
|
475
|
+
}
|
|
476
|
+
return new Set(rawUsers
|
|
477
|
+
.split(',')
|
|
478
|
+
.map((value) => value.trim().toLowerCase())
|
|
479
|
+
.filter(Boolean));
|
|
480
|
+
}
|
|
456
481
|
async signIn(signInDto) {
|
|
457
482
|
const user = await this.resolveUser(signInDto.username, signInDto.email);
|
|
458
483
|
if (!user) {
|
|
@@ -538,7 +563,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
538
563
|
return user;
|
|
539
564
|
}
|
|
540
565
|
async assignLoginOtp(user, type) {
|
|
541
|
-
const { token, expiresAt } = await this.otp();
|
|
566
|
+
const { token, expiresAt } = await this.otp(user);
|
|
542
567
|
if (type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
543
568
|
user.emailVerificationTokenOnLogin = token;
|
|
544
569
|
user.emailVerificationTokenOnLoginExpiresAt = expiresAt;
|
|
@@ -557,7 +582,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
557
582
|
}
|
|
558
583
|
async notifyUserOnOtpInititateLogin(user, loginType) {
|
|
559
584
|
const companyLogo = await this.getCompanyLogo();
|
|
560
|
-
const dummyOtp = this.
|
|
585
|
+
const dummyOtp = this.getDummyOtpForUser(user);
|
|
561
586
|
if (dummyOtp)
|
|
562
587
|
return;
|
|
563
588
|
if (loginType === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
@@ -602,7 +627,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
602
627
|
await this.incrementFailedAttempts(user);
|
|
603
628
|
throw e;
|
|
604
629
|
}
|
|
605
|
-
const dummyOtp = this.
|
|
630
|
+
const dummyOtp = this.getDummyOtpForUser(user);
|
|
606
631
|
if (!dummyOtp)
|
|
607
632
|
this.clearLoginOtp(user, type);
|
|
608
633
|
user.failedLoginAttempts = 0;
|
|
@@ -670,15 +695,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
670
695
|
await this.userRepository.save(user);
|
|
671
696
|
return true;
|
|
672
697
|
}
|
|
673
|
-
async generateForgotPasswordToken() {
|
|
698
|
+
async generateForgotPasswordToken(user) {
|
|
674
699
|
const expiryTime = new Date();
|
|
675
700
|
const forgotPasswordVerificationTokenExpiry = this.settingService.getConfigValue('forgotPasswordVerificationTokenExpiry');
|
|
676
|
-
const dummyOtp = this.
|
|
701
|
+
const dummyOtp = this.getDummyOtpForUser(user);
|
|
677
702
|
expiryTime.setMinutes(expiryTime.getMinutes() + forgotPasswordVerificationTokenExpiry);
|
|
678
703
|
return {
|
|
679
|
-
token: dummyOtp
|
|
680
|
-
? dummyOtp
|
|
681
|
-
: (0, uuid_1.v4)(),
|
|
704
|
+
token: dummyOtp ? dummyOtp : (0, uuid_1.v4)(),
|
|
682
705
|
expiresAt: expiryTime,
|
|
683
706
|
};
|
|
684
707
|
}
|
|
@@ -695,7 +718,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
695
718
|
isValidUser = false;
|
|
696
719
|
}
|
|
697
720
|
if (isValidUser) {
|
|
698
|
-
const { token, expiresAt } = await this.generateForgotPasswordToken();
|
|
721
|
+
const { token, expiresAt } = await this.generateForgotPasswordToken(user);
|
|
699
722
|
user.verificationTokenOnForgotPassword = token;
|
|
700
723
|
user.verificationTokenOnForgotPasswordExpiresAt = expiresAt;
|
|
701
724
|
await this.userRepository.save(user);
|