fiberx-backend-toolkit 0.0.65 → 0.0.66
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.
|
@@ -2,7 +2,8 @@ import { GenerateSecretOptionsType, VerifyResultType, VerifyOptionsType, TOTPSer
|
|
|
2
2
|
declare class TOTPServiceUtil {
|
|
3
3
|
readonly name = "totp_service_util";
|
|
4
4
|
private static instance;
|
|
5
|
-
private logger;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private readonly env_manager;
|
|
6
7
|
private readonly STEP;
|
|
7
8
|
private readonly DIGITS;
|
|
8
9
|
private readonly WINDOW;
|
|
@@ -14,6 +15,7 @@ declare class TOTPServiceUtil {
|
|
|
14
15
|
private base32Encode;
|
|
15
16
|
private generateForCounter;
|
|
16
17
|
generateSecret(options: GenerateSecretOptionsType): GenerateSecretResult;
|
|
18
|
+
generateAppSecret(member_email: string, custom_app_name?: string): GenerateSecretResult;
|
|
17
19
|
verify(options: VerifyOptionsType & {
|
|
18
20
|
last_used_counter?: number;
|
|
19
21
|
}): VerifyResultType;
|
|
@@ -7,10 +7,12 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
7
7
|
const constants_1 = require("../config/constants");
|
|
8
8
|
const logger_util_1 = __importDefault(require("./logger_util"));
|
|
9
9
|
const input_validator_util_1 = __importDefault(require("./input_validator_util"));
|
|
10
|
+
const env_manager_util_1 = __importDefault(require("./env_manager_util"));
|
|
10
11
|
class TOTPServiceUtil {
|
|
11
12
|
name = "totp_service_util";
|
|
12
13
|
static instance;
|
|
13
14
|
logger = new logger_util_1.default(this.name);
|
|
15
|
+
env_manager = env_manager_util_1.default.getInstance();
|
|
14
16
|
// ===============================
|
|
15
17
|
// CONFIG
|
|
16
18
|
// ===============================
|
|
@@ -117,6 +119,12 @@ class TOTPServiceUtil {
|
|
|
117
119
|
otpauth_url,
|
|
118
120
|
};
|
|
119
121
|
}
|
|
122
|
+
generateAppSecret(member_email, custom_app_name = "") {
|
|
123
|
+
const app_name = this.env_manager.getEnvVar("APP_NAME", custom_app_name) ?? custom_app_name;
|
|
124
|
+
const name = input_validator_util_1.default.isProduction() ? `${app_name}:${member_email}` : `Dev ${app_name}:${member_email}`;
|
|
125
|
+
const issuer = (this.env_manager.getEnvVar("APP_ID", custom_app_name) ?? custom_app_name)?.toLowerCase();
|
|
126
|
+
return this.generateSecret({ name, issuer });
|
|
127
|
+
}
|
|
120
128
|
// ===============================
|
|
121
129
|
// PUBLIC: VERIFY TOKEN
|
|
122
130
|
// ===============================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|