hazo_auth 4.2.0 → 4.4.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/bin/hazo_auth.mjs +35 -0
- package/cli-src/assets/images/forgot_password_default.jpg +0 -0
- package/cli-src/assets/images/login_default.jpg +0 -0
- package/cli-src/assets/images/register_default.jpg +0 -0
- package/cli-src/assets/images/reset_password_default.jpg +0 -0
- package/cli-src/assets/images/verify_email_default.jpg +0 -0
- package/cli-src/cli/generate.ts +276 -0
- package/cli-src/cli/index.ts +207 -0
- package/cli-src/cli/init.ts +254 -0
- package/cli-src/cli/init_users.ts +376 -0
- package/cli-src/cli/validate.ts +581 -0
- package/cli-src/lib/already_logged_in_config.server.ts +46 -0
- package/cli-src/lib/app_logger.ts +24 -0
- package/cli-src/lib/auth/auth_cache.ts +220 -0
- package/cli-src/lib/auth/auth_rate_limiter.ts +121 -0
- package/cli-src/lib/auth/auth_types.ts +117 -0
- package/cli-src/lib/auth/auth_utils.server.ts +196 -0
- package/cli-src/lib/auth/dev_lock_validator.edge.ts +171 -0
- package/cli-src/lib/auth/hazo_get_auth.server.ts +583 -0
- package/cli-src/lib/auth/index.ts +23 -0
- package/cli-src/lib/auth/nextauth_config.ts +227 -0
- package/cli-src/lib/auth/org_cache.ts +148 -0
- package/cli-src/lib/auth/scope_cache.ts +233 -0
- package/cli-src/lib/auth/server_auth.ts +88 -0
- package/cli-src/lib/auth/session_token_validator.edge.ts +92 -0
- package/cli-src/lib/auth_utility_config.server.ts +136 -0
- package/cli-src/lib/config/config_loader.server.ts +164 -0
- package/cli-src/lib/config/default_config.ts +243 -0
- package/cli-src/lib/dev_lock_config.server.ts +148 -0
- package/cli-src/lib/email_verification_config.server.ts +63 -0
- package/cli-src/lib/file_types_config.server.ts +25 -0
- package/cli-src/lib/forgot_password_config.server.ts +63 -0
- package/cli-src/lib/hazo_connect_instance.server.ts +101 -0
- package/cli-src/lib/hazo_connect_setup.server.ts +194 -0
- package/cli-src/lib/hazo_connect_setup.ts +54 -0
- package/cli-src/lib/index.ts +46 -0
- package/cli-src/lib/login_config.server.ts +106 -0
- package/cli-src/lib/messages_config.server.ts +45 -0
- package/cli-src/lib/migrations/apply_migration.ts +105 -0
- package/cli-src/lib/multi_tenancy_config.server.ts +94 -0
- package/cli-src/lib/my_settings_config.server.ts +135 -0
- package/cli-src/lib/oauth_config.server.ts +87 -0
- package/cli-src/lib/password_requirements_config.server.ts +40 -0
- package/cli-src/lib/profile_pic_menu_config.server.ts +138 -0
- package/cli-src/lib/profile_picture_config.server.ts +56 -0
- package/cli-src/lib/register_config.server.ts +101 -0
- package/cli-src/lib/reset_password_config.server.ts +103 -0
- package/cli-src/lib/scope_hierarchy_config.server.ts +151 -0
- package/cli-src/lib/services/email_service.ts +587 -0
- package/cli-src/lib/services/email_verification_service.ts +270 -0
- package/cli-src/lib/services/index.ts +16 -0
- package/cli-src/lib/services/login_service.ts +150 -0
- package/cli-src/lib/services/oauth_service.ts +494 -0
- package/cli-src/lib/services/org_service.ts +965 -0
- package/cli-src/lib/services/password_change_service.ts +154 -0
- package/cli-src/lib/services/password_reset_service.ts +418 -0
- package/cli-src/lib/services/profile_picture_remove_service.ts +120 -0
- package/cli-src/lib/services/profile_picture_service.ts +451 -0
- package/cli-src/lib/services/profile_picture_source_mapper.ts +62 -0
- package/cli-src/lib/services/registration_service.ts +185 -0
- package/cli-src/lib/services/scope_labels_service.ts +348 -0
- package/cli-src/lib/services/scope_service.ts +778 -0
- package/cli-src/lib/services/session_token_service.ts +178 -0
- package/cli-src/lib/services/token_service.ts +240 -0
- package/cli-src/lib/services/user_profiles_cache.ts +189 -0
- package/cli-src/lib/services/user_profiles_service.ts +264 -0
- package/cli-src/lib/services/user_scope_service.ts +554 -0
- package/cli-src/lib/services/user_update_service.ts +141 -0
- package/cli-src/lib/ui_shell_config.server.ts +73 -0
- package/cli-src/lib/ui_sizes_config.server.ts +37 -0
- package/cli-src/lib/user_fields_config.server.ts +31 -0
- package/cli-src/lib/user_management_config.server.ts +39 -0
- package/cli-src/lib/user_profiles_config.server.ts +55 -0
- package/cli-src/lib/utils/api_route_helpers.ts +60 -0
- package/cli-src/lib/utils/error_sanitizer.ts +75 -0
- package/cli-src/lib/utils/password_validator.ts +65 -0
- package/cli-src/lib/utils.ts +11 -0
- package/cli-src/server/logging/logger_service.ts +56 -0
- package/cli-src/server/types/app_types.ts +74 -0
- package/cli-src/server/types/express.d.ts +16 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/init_users.d.ts +17 -0
- package/dist/cli/init_users.d.ts.map +1 -0
- package/dist/cli/init_users.js +307 -0
- package/dist/components/layouts/dev_lock/index.d.ts +29 -0
- package/dist/components/layouts/dev_lock/index.d.ts.map +1 -0
- package/dist/components/layouts/dev_lock/index.js +60 -0
- package/dist/components/layouts/index.d.ts +2 -0
- package/dist/components/layouts/index.d.ts.map +1 -1
- package/dist/components/layouts/index.js +1 -0
- package/dist/components/layouts/org_management/index.d.ts +26 -0
- package/dist/components/layouts/org_management/index.d.ts.map +1 -0
- package/dist/components/layouts/org_management/index.js +75 -0
- package/dist/components/layouts/shared/config/layout_customization.d.ts +2 -7
- package/dist/components/layouts/shared/config/layout_customization.d.ts.map +1 -1
- package/dist/components/layouts/user_management/components/org_hierarchy_tab.d.ts +13 -0
- package/dist/components/layouts/user_management/components/org_hierarchy_tab.d.ts.map +1 -0
- package/dist/components/layouts/user_management/components/org_hierarchy_tab.js +276 -0
- package/dist/components/layouts/user_management/index.d.ts +3 -1
- package/dist/components/layouts/user_management/index.d.ts.map +1 -1
- package/dist/components/layouts/user_management/index.js +10 -4
- package/dist/lib/auth/auth_types.d.ts +6 -0
- package/dist/lib/auth/auth_types.d.ts.map +1 -1
- package/dist/lib/auth/dev_lock_validator.edge.d.ts +38 -0
- package/dist/lib/auth/dev_lock_validator.edge.d.ts.map +1 -0
- package/dist/lib/auth/dev_lock_validator.edge.js +122 -0
- package/dist/lib/auth/hazo_get_auth.server.d.ts.map +1 -1
- package/dist/lib/auth/hazo_get_auth.server.js +61 -1
- package/dist/lib/auth/org_cache.d.ts +65 -0
- package/dist/lib/auth/org_cache.d.ts.map +1 -0
- package/dist/lib/auth/org_cache.js +103 -0
- package/dist/lib/config/default_config.d.ts +76 -0
- package/dist/lib/config/default_config.d.ts.map +1 -1
- package/dist/lib/config/default_config.js +42 -0
- package/dist/lib/dev_lock_config.server.d.ts +41 -0
- package/dist/lib/dev_lock_config.server.d.ts.map +1 -0
- package/dist/lib/dev_lock_config.server.js +50 -0
- package/dist/lib/multi_tenancy_config.server.d.ts +30 -0
- package/dist/lib/multi_tenancy_config.server.d.ts.map +1 -0
- package/dist/lib/multi_tenancy_config.server.js +41 -0
- package/dist/lib/services/org_service.d.ts +191 -0
- package/dist/lib/services/org_service.d.ts.map +1 -0
- package/dist/lib/services/org_service.js +746 -0
- package/dist/lib/utils/password_validator.d.ts +7 -1
- package/dist/lib/utils/password_validator.d.ts.map +1 -1
- package/dist/page_components/dev_lock.d.ts +11 -0
- package/dist/page_components/dev_lock.d.ts.map +1 -0
- package/dist/page_components/dev_lock.js +17 -0
- package/dist/page_components/index.d.ts +1 -0
- package/dist/page_components/index.d.ts.map +1 -1
- package/dist/page_components/index.js +1 -0
- package/dist/page_components/org_management.d.ts +27 -0
- package/dist/page_components/org_management.d.ts.map +1 -0
- package/dist/page_components/org_management.js +18 -0
- package/hazo_auth_config.example.ini +30 -0
- package/package.json +27 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// file_description: server-only helper to read profile picture menu configuration from hazo_auth_config.ini
|
|
2
|
+
// section: imports
|
|
3
|
+
import { get_config_value, get_config_boolean, get_config_array } from "./config/config_loader.server.js";
|
|
4
|
+
|
|
5
|
+
// section: types
|
|
6
|
+
// Note: These types are also used in client components, but TypeScript types are erased at runtime
|
|
7
|
+
// so importing from a server file is safe for type-only imports
|
|
8
|
+
export type MenuItemType = "info" | "link" | "separator";
|
|
9
|
+
|
|
10
|
+
export type ProfilePicMenuMenuItem = {
|
|
11
|
+
type: MenuItemType;
|
|
12
|
+
label?: string; // For info and link types
|
|
13
|
+
value?: string; // For info type (e.g., user name, email)
|
|
14
|
+
href?: string; // For link type
|
|
15
|
+
order: number; // Ordering within type group
|
|
16
|
+
id: string; // Unique identifier for the item
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ProfilePicMenuConfig = {
|
|
20
|
+
show_single_button: boolean;
|
|
21
|
+
sign_up_label: string;
|
|
22
|
+
sign_in_label: string;
|
|
23
|
+
register_path: string;
|
|
24
|
+
login_path: string;
|
|
25
|
+
settings_path: string;
|
|
26
|
+
logout_path: string;
|
|
27
|
+
custom_menu_items: ProfilePicMenuMenuItem[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// section: helpers
|
|
31
|
+
/**
|
|
32
|
+
* Parses custom menu items from config string
|
|
33
|
+
* Format: "type:label:order" or "type:label:href:order" for links
|
|
34
|
+
* Example: "link:My Custom Link:/custom:3"
|
|
35
|
+
* @param items_string - Comma-separated string of menu items
|
|
36
|
+
* @returns Array of parsed menu items
|
|
37
|
+
*/
|
|
38
|
+
function parse_custom_menu_items(items_string: string[]): ProfilePicMenuMenuItem[] {
|
|
39
|
+
const items: ProfilePicMenuMenuItem[] = [];
|
|
40
|
+
|
|
41
|
+
items_string.forEach((item_string, index) => {
|
|
42
|
+
const parts = item_string.split(":").map((p) => p.trim());
|
|
43
|
+
|
|
44
|
+
if (parts.length < 3) {
|
|
45
|
+
return; // Invalid format, skip
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const type = parts[0] as MenuItemType;
|
|
49
|
+
if (type !== "info" && type !== "link" && type !== "separator") {
|
|
50
|
+
return; // Invalid type, skip
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (type === "separator") {
|
|
54
|
+
const order = parseInt(parts[1] || "1", 10);
|
|
55
|
+
items.push({
|
|
56
|
+
type: "separator",
|
|
57
|
+
order: isNaN(order) ? 1 : order,
|
|
58
|
+
id: `custom_separator_${index}`,
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (type === "info") {
|
|
64
|
+
const label = parts[1] || "";
|
|
65
|
+
const value = parts[2] || "";
|
|
66
|
+
const order = parseInt(parts[3] || "1", 10);
|
|
67
|
+
|
|
68
|
+
if (!label || !value) {
|
|
69
|
+
return; // Invalid format, skip
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
items.push({
|
|
73
|
+
type: "info",
|
|
74
|
+
label,
|
|
75
|
+
value,
|
|
76
|
+
order: isNaN(order) ? 1 : order,
|
|
77
|
+
id: `custom_info_${index}`,
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (type === "link") {
|
|
83
|
+
const label = parts[1] || "";
|
|
84
|
+
const href = parts[2] || "";
|
|
85
|
+
const order = parseInt(parts[3] || "1", 10);
|
|
86
|
+
|
|
87
|
+
if (!label || !href) {
|
|
88
|
+
return; // Invalid format, skip
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
items.push({
|
|
92
|
+
type: "link",
|
|
93
|
+
label,
|
|
94
|
+
href,
|
|
95
|
+
order: isNaN(order) ? 1 : order,
|
|
96
|
+
id: `custom_link_${index}`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return items;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Reads profile picture menu configuration from hazo_auth_config.ini file
|
|
106
|
+
* Falls back to defaults if hazo_auth_config.ini is not found or section is missing
|
|
107
|
+
* @returns Profile picture menu configuration options
|
|
108
|
+
*/
|
|
109
|
+
export function get_profile_pic_menu_config(): ProfilePicMenuConfig {
|
|
110
|
+
const section = "hazo_auth__profile_pic_menu";
|
|
111
|
+
|
|
112
|
+
// Read button configuration
|
|
113
|
+
const show_single_button = get_config_boolean(section, "show_single_button", false);
|
|
114
|
+
const sign_up_label = get_config_value(section, "sign_up_label", "Sign Up");
|
|
115
|
+
const sign_in_label = get_config_value(section, "sign_in_label", "Sign In");
|
|
116
|
+
const register_path = get_config_value(section, "register_path", "/hazo_auth/register");
|
|
117
|
+
const login_path = get_config_value(section, "login_path", "/hazo_auth/login");
|
|
118
|
+
|
|
119
|
+
// Read menu paths
|
|
120
|
+
const settings_path = get_config_value(section, "settings_path", "/hazo_auth/my_settings");
|
|
121
|
+
const logout_path = get_config_value(section, "logout_path", "/api/hazo_auth/logout");
|
|
122
|
+
|
|
123
|
+
// Read custom menu items
|
|
124
|
+
const custom_items_string = get_config_array(section, "custom_menu_items", []);
|
|
125
|
+
const custom_menu_items = parse_custom_menu_items(custom_items_string);
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
show_single_button,
|
|
129
|
+
sign_up_label,
|
|
130
|
+
sign_in_label,
|
|
131
|
+
register_path,
|
|
132
|
+
login_path,
|
|
133
|
+
settings_path,
|
|
134
|
+
logout_path,
|
|
135
|
+
custom_menu_items,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// file_description: server-only helper to read profile picture configuration from hazo_auth_config.ini
|
|
2
|
+
// section: imports
|
|
3
|
+
import { get_config_boolean, get_config_value, get_config_number, read_config_section } from "./config/config_loader.server.js";
|
|
4
|
+
import { create_app_logger } from "./app_logger.js";
|
|
5
|
+
|
|
6
|
+
// section: types
|
|
7
|
+
export type ProfilePictureConfig = {
|
|
8
|
+
allow_photo_upload: boolean;
|
|
9
|
+
upload_photo_path?: string;
|
|
10
|
+
max_photo_size: number; // in bytes
|
|
11
|
+
user_photo_default: boolean;
|
|
12
|
+
user_photo_default_priority1: "gravatar" | "library";
|
|
13
|
+
user_photo_default_priority2?: "library" | "gravatar";
|
|
14
|
+
library_photo_path: string; // relative to public directory
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// section: helpers
|
|
18
|
+
/**
|
|
19
|
+
* Reads profile picture configuration from hazo_auth_config.ini file
|
|
20
|
+
* Falls back to defaults if hazo_auth_config.ini is not found or section is missing
|
|
21
|
+
* @returns Profile picture configuration options
|
|
22
|
+
*/
|
|
23
|
+
export function get_profile_picture_config(): ProfilePictureConfig {
|
|
24
|
+
const logger = create_app_logger();
|
|
25
|
+
const section = "hazo_auth__profile_picture";
|
|
26
|
+
|
|
27
|
+
// Read configuration with defaults
|
|
28
|
+
const allow_photo_upload = get_config_boolean(section, "allow_photo_upload", false);
|
|
29
|
+
const upload_photo_path = get_config_value(section, "upload_photo_path", "");
|
|
30
|
+
const max_photo_size = get_config_number(section, "max_photo_size", 51200); // Default: 50kb
|
|
31
|
+
const user_photo_default = get_config_boolean(section, "user_photo_default", true);
|
|
32
|
+
const user_photo_default_priority1 = (get_config_value(section, "user_photo_default_priority1", "gravatar") as "gravatar" | "library");
|
|
33
|
+
const priority2_value = get_config_value(section, "user_photo_default_priority2", "");
|
|
34
|
+
const user_photo_default_priority2 = priority2_value ? (priority2_value as "library" | "gravatar") : undefined;
|
|
35
|
+
const library_photo_path = get_config_value(section, "library_photo_path", "/profile_pictures/library");
|
|
36
|
+
|
|
37
|
+
// Validate upload_photo_path if allow_photo_upload is true
|
|
38
|
+
if (allow_photo_upload && !upload_photo_path) {
|
|
39
|
+
logger.warn("profile_picture_config_validation_failed", {
|
|
40
|
+
filename: "profile_picture_config.server.ts",
|
|
41
|
+
line_number: 0,
|
|
42
|
+
message: "allow_photo_upload is true but upload_photo_path is not set",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
allow_photo_upload,
|
|
48
|
+
upload_photo_path: upload_photo_path || undefined,
|
|
49
|
+
max_photo_size,
|
|
50
|
+
user_photo_default,
|
|
51
|
+
user_photo_default_priority1,
|
|
52
|
+
user_photo_default_priority2,
|
|
53
|
+
library_photo_path,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// file_description: server-only helper to read register layout configuration from hazo_auth_config.ini
|
|
2
|
+
// section: imports
|
|
3
|
+
import { get_config_boolean, get_config_value, read_config_section } from "./config/config_loader.server.js";
|
|
4
|
+
import { get_password_requirements_config } from "./password_requirements_config.server.js";
|
|
5
|
+
import { get_already_logged_in_config } from "./already_logged_in_config.server.js";
|
|
6
|
+
import { get_user_fields_config } from "./user_fields_config.server.js";
|
|
7
|
+
import registerDefaultImage from "../assets/images/register_default.jpg.js";
|
|
8
|
+
|
|
9
|
+
// section: types
|
|
10
|
+
import type { StaticImageData } from "next/image";
|
|
11
|
+
|
|
12
|
+
export type RegisterConfig = {
|
|
13
|
+
showNameField: boolean;
|
|
14
|
+
passwordRequirements: {
|
|
15
|
+
minimum_length: number;
|
|
16
|
+
require_uppercase: boolean;
|
|
17
|
+
require_lowercase: boolean;
|
|
18
|
+
require_number: boolean;
|
|
19
|
+
require_special: boolean;
|
|
20
|
+
};
|
|
21
|
+
alreadyLoggedInMessage: string;
|
|
22
|
+
showLogoutButton: boolean;
|
|
23
|
+
showReturnHomeButton: boolean;
|
|
24
|
+
returnHomeButtonLabel: string;
|
|
25
|
+
returnHomePath: string;
|
|
26
|
+
signInPath: string;
|
|
27
|
+
signInLabel: string;
|
|
28
|
+
imageSrc: string | StaticImageData;
|
|
29
|
+
imageAlt: string;
|
|
30
|
+
imageBackgroundColor: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// section: helpers
|
|
34
|
+
/**
|
|
35
|
+
* Reads register layout configuration from hazo_auth_config.ini file
|
|
36
|
+
* Falls back to defaults if hazo_auth_config.ini is not found or section is missing
|
|
37
|
+
* @returns Register configuration options
|
|
38
|
+
*/
|
|
39
|
+
export function get_register_config(): RegisterConfig {
|
|
40
|
+
// Get shared user fields config (preferred) or fall back to register section for backwards compatibility
|
|
41
|
+
const userFieldsConfig = get_user_fields_config();
|
|
42
|
+
const register_section = read_config_section("hazo_auth__register_layout");
|
|
43
|
+
|
|
44
|
+
// Use register section if explicitly set, otherwise use shared config
|
|
45
|
+
const showNameField = register_section?.show_name_field !== undefined
|
|
46
|
+
? get_config_boolean("hazo_auth__register_layout", "show_name_field", true)
|
|
47
|
+
: userFieldsConfig.show_name_field;
|
|
48
|
+
|
|
49
|
+
// Get shared password requirements
|
|
50
|
+
const passwordRequirements = get_password_requirements_config();
|
|
51
|
+
|
|
52
|
+
// Get shared already logged in config
|
|
53
|
+
const alreadyLoggedInConfig = get_already_logged_in_config();
|
|
54
|
+
|
|
55
|
+
// Read sign in link configuration
|
|
56
|
+
const signInPath = get_config_value(
|
|
57
|
+
"hazo_auth__register_layout",
|
|
58
|
+
"sign_in_path",
|
|
59
|
+
"/hazo_auth/login"
|
|
60
|
+
);
|
|
61
|
+
const signInLabel = get_config_value(
|
|
62
|
+
"hazo_auth__register_layout",
|
|
63
|
+
"sign_in_label",
|
|
64
|
+
"Sign in"
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Read image configuration
|
|
68
|
+
// If not set in config, falls back to default image from assets
|
|
69
|
+
const imageSrc = get_config_value(
|
|
70
|
+
"hazo_auth__register_layout",
|
|
71
|
+
"image_src",
|
|
72
|
+
"" // Empty string means not set in config
|
|
73
|
+
) || registerDefaultImage;
|
|
74
|
+
|
|
75
|
+
const imageAlt = get_config_value(
|
|
76
|
+
"hazo_auth__register_layout",
|
|
77
|
+
"image_alt",
|
|
78
|
+
"Modern building representing user registration"
|
|
79
|
+
);
|
|
80
|
+
const imageBackgroundColor = get_config_value(
|
|
81
|
+
"hazo_auth__register_layout",
|
|
82
|
+
"image_background_color",
|
|
83
|
+
"#e2e8f0"
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
showNameField,
|
|
88
|
+
passwordRequirements,
|
|
89
|
+
alreadyLoggedInMessage: alreadyLoggedInConfig.message,
|
|
90
|
+
showLogoutButton: alreadyLoggedInConfig.showLogoutButton,
|
|
91
|
+
showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
|
|
92
|
+
returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
|
|
93
|
+
returnHomePath: alreadyLoggedInConfig.returnHomePath,
|
|
94
|
+
signInPath,
|
|
95
|
+
signInLabel,
|
|
96
|
+
imageSrc,
|
|
97
|
+
imageAlt,
|
|
98
|
+
imageBackgroundColor,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// file_description: server-only helper to read reset password layout configuration from hazo_auth_config.ini
|
|
2
|
+
// section: imports
|
|
3
|
+
import { get_config_value } from "./config/config_loader.server.js";
|
|
4
|
+
import { get_already_logged_in_config } from "./already_logged_in_config.server.js";
|
|
5
|
+
import { get_password_requirements_config } from "./password_requirements_config.server.js";
|
|
6
|
+
import resetPasswordDefaultImage from "../assets/images/reset_password_default.jpg.js";
|
|
7
|
+
|
|
8
|
+
// section: types
|
|
9
|
+
import type { StaticImageData } from "next/image";
|
|
10
|
+
|
|
11
|
+
export type ResetPasswordConfig = {
|
|
12
|
+
errorMessage: string;
|
|
13
|
+
successMessage: string;
|
|
14
|
+
loginPath: string;
|
|
15
|
+
forgotPasswordPath: string;
|
|
16
|
+
alreadyLoggedInMessage: string;
|
|
17
|
+
showLogoutButton: boolean;
|
|
18
|
+
showReturnHomeButton: boolean;
|
|
19
|
+
returnHomeButtonLabel: string;
|
|
20
|
+
returnHomePath: string;
|
|
21
|
+
passwordRequirements: {
|
|
22
|
+
minimum_length: number;
|
|
23
|
+
require_uppercase: boolean;
|
|
24
|
+
require_lowercase: boolean;
|
|
25
|
+
require_number: boolean;
|
|
26
|
+
require_special: boolean;
|
|
27
|
+
};
|
|
28
|
+
imageSrc: string | StaticImageData;
|
|
29
|
+
imageAlt: string;
|
|
30
|
+
imageBackgroundColor: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// section: helpers
|
|
34
|
+
/**
|
|
35
|
+
* Reads reset password layout configuration from hazo_auth_config.ini file
|
|
36
|
+
* Falls back to defaults if hazo_auth_config.ini is not found or section is missing
|
|
37
|
+
* @returns Reset password configuration options
|
|
38
|
+
*/
|
|
39
|
+
export function get_reset_password_config(): ResetPasswordConfig {
|
|
40
|
+
const section = "hazo_auth__reset_password_layout";
|
|
41
|
+
|
|
42
|
+
// Get shared already logged in config
|
|
43
|
+
const alreadyLoggedInConfig = get_already_logged_in_config();
|
|
44
|
+
|
|
45
|
+
// Read error message (defaults to standard message)
|
|
46
|
+
const errorMessage = get_config_value(
|
|
47
|
+
section,
|
|
48
|
+
"error_message",
|
|
49
|
+
"Reset password link invalid or has expired. Please go to Reset Password page to get a new link."
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// Read success message (defaults to standard message)
|
|
53
|
+
const successMessage = get_config_value(
|
|
54
|
+
section,
|
|
55
|
+
"success_message",
|
|
56
|
+
"Password reset successfully. Redirecting to login..."
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Read login path (defaults to "/hazo_auth/login")
|
|
60
|
+
const loginPath = get_config_value(section, "login_path", "/hazo_auth/login");
|
|
61
|
+
|
|
62
|
+
// Read forgot password path (defaults to "/hazo_auth/forgot_password")
|
|
63
|
+
const forgotPasswordPath = get_config_value(section, "forgot_password_path", "/hazo_auth/forgot_password");
|
|
64
|
+
|
|
65
|
+
// Get shared password requirements
|
|
66
|
+
const passwordRequirements = get_password_requirements_config();
|
|
67
|
+
|
|
68
|
+
// Read image configuration
|
|
69
|
+
// If not set in config, falls back to default image from assets
|
|
70
|
+
const imageSrc = get_config_value(
|
|
71
|
+
section,
|
|
72
|
+
"image_src",
|
|
73
|
+
"" // Empty string means not set in config
|
|
74
|
+
) || resetPasswordDefaultImage;
|
|
75
|
+
|
|
76
|
+
const imageAlt = get_config_value(
|
|
77
|
+
section,
|
|
78
|
+
"image_alt",
|
|
79
|
+
"Reset password illustration"
|
|
80
|
+
);
|
|
81
|
+
const imageBackgroundColor = get_config_value(
|
|
82
|
+
section,
|
|
83
|
+
"image_background_color",
|
|
84
|
+
"#f1f5f9"
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
errorMessage,
|
|
89
|
+
successMessage,
|
|
90
|
+
loginPath,
|
|
91
|
+
forgotPasswordPath,
|
|
92
|
+
alreadyLoggedInMessage: alreadyLoggedInConfig.message,
|
|
93
|
+
showLogoutButton: alreadyLoggedInConfig.showLogoutButton,
|
|
94
|
+
showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
|
|
95
|
+
returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
|
|
96
|
+
returnHomePath: alreadyLoggedInConfig.returnHomePath,
|
|
97
|
+
passwordRequirements,
|
|
98
|
+
imageSrc,
|
|
99
|
+
imageAlt,
|
|
100
|
+
imageBackgroundColor,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// file_description: server-only helper to read HRBAC scope hierarchy configuration from hazo_auth_config.ini
|
|
2
|
+
// section: imports
|
|
3
|
+
import {
|
|
4
|
+
get_config_value,
|
|
5
|
+
get_config_number,
|
|
6
|
+
get_config_boolean,
|
|
7
|
+
get_config_array,
|
|
8
|
+
} from "./config/config_loader.server.js";
|
|
9
|
+
import type { ScopeLevel } from "./services/scope_service";
|
|
10
|
+
import { SCOPE_LEVELS } from "./services/scope_service.js";
|
|
11
|
+
|
|
12
|
+
// section: types
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Scope hierarchy configuration options for HRBAC
|
|
16
|
+
*/
|
|
17
|
+
export type ScopeHierarchyConfig = {
|
|
18
|
+
/** Whether HRBAC is enabled (default: false) */
|
|
19
|
+
enable_hrbac: boolean;
|
|
20
|
+
/** Default organization for single-tenant apps (optional) */
|
|
21
|
+
default_org: string;
|
|
22
|
+
/** Cache TTL in minutes for scope lookups (default: 15) */
|
|
23
|
+
scope_cache_ttl_minutes: number;
|
|
24
|
+
/** Maximum entries in scope cache (default: 5000) */
|
|
25
|
+
scope_cache_max_entries: number;
|
|
26
|
+
/** Which scope levels are active/enabled */
|
|
27
|
+
active_levels: ScopeLevel[];
|
|
28
|
+
/** Default labels for each scope level */
|
|
29
|
+
default_labels: Record<ScopeLevel, string>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// section: constants
|
|
33
|
+
|
|
34
|
+
const SECTION_NAME = "hazo_auth__scope_hierarchy";
|
|
35
|
+
|
|
36
|
+
const DEFAULT_LABELS: Record<ScopeLevel, string> = {
|
|
37
|
+
hazo_scopes_l1: "Level 1",
|
|
38
|
+
hazo_scopes_l2: "Level 2",
|
|
39
|
+
hazo_scopes_l3: "Level 3",
|
|
40
|
+
hazo_scopes_l4: "Level 4",
|
|
41
|
+
hazo_scopes_l5: "Level 5",
|
|
42
|
+
hazo_scopes_l6: "Level 6",
|
|
43
|
+
hazo_scopes_l7: "Level 7",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// section: helpers
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parses the active_levels config value into an array of ScopeLevel
|
|
50
|
+
* If not configured, returns all levels
|
|
51
|
+
*/
|
|
52
|
+
function parse_active_levels(config_value: string): ScopeLevel[] {
|
|
53
|
+
if (!config_value || config_value.trim().length === 0) {
|
|
54
|
+
return [...SCOPE_LEVELS]; // All levels active by default
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const levels = config_value.split(",").map((s) => s.trim());
|
|
58
|
+
const valid_levels: ScopeLevel[] = [];
|
|
59
|
+
|
|
60
|
+
for (const level of levels) {
|
|
61
|
+
if (SCOPE_LEVELS.includes(level as ScopeLevel)) {
|
|
62
|
+
valid_levels.push(level as ScopeLevel);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return valid_levels.length > 0 ? valid_levels : [...SCOPE_LEVELS];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reads default labels from config, falling back to defaults
|
|
71
|
+
*/
|
|
72
|
+
function get_default_labels(): Record<ScopeLevel, string> {
|
|
73
|
+
const labels = { ...DEFAULT_LABELS };
|
|
74
|
+
|
|
75
|
+
for (let i = 1; i <= 7; i++) {
|
|
76
|
+
const level = `hazo_scopes_l${i}` as ScopeLevel;
|
|
77
|
+
const config_key = `default_label_l${i}`;
|
|
78
|
+
const config_value = get_config_value(SECTION_NAME, config_key, "");
|
|
79
|
+
|
|
80
|
+
if (config_value && config_value.trim().length > 0) {
|
|
81
|
+
labels[level] = config_value.trim();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return labels;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Reads HRBAC scope hierarchy configuration from hazo_auth_config.ini file
|
|
90
|
+
* Falls back to defaults if config file is not found or section is missing
|
|
91
|
+
* @returns Scope hierarchy configuration options
|
|
92
|
+
*/
|
|
93
|
+
export function get_scope_hierarchy_config(): ScopeHierarchyConfig {
|
|
94
|
+
// Core HRBAC enablement
|
|
95
|
+
const enable_hrbac = get_config_boolean(SECTION_NAME, "enable_hrbac", false);
|
|
96
|
+
|
|
97
|
+
// Default organization for single-tenant apps
|
|
98
|
+
const default_org = get_config_value(SECTION_NAME, "default_org", "");
|
|
99
|
+
|
|
100
|
+
// Cache settings
|
|
101
|
+
const scope_cache_ttl_minutes = get_config_number(
|
|
102
|
+
SECTION_NAME,
|
|
103
|
+
"scope_cache_ttl_minutes",
|
|
104
|
+
15,
|
|
105
|
+
);
|
|
106
|
+
const scope_cache_max_entries = get_config_number(
|
|
107
|
+
SECTION_NAME,
|
|
108
|
+
"scope_cache_max_entries",
|
|
109
|
+
5000,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// Active levels
|
|
113
|
+
const active_levels_str = get_config_value(SECTION_NAME, "active_levels", "");
|
|
114
|
+
const active_levels = parse_active_levels(active_levels_str);
|
|
115
|
+
|
|
116
|
+
// Default labels
|
|
117
|
+
const default_labels = get_default_labels();
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
enable_hrbac,
|
|
121
|
+
default_org,
|
|
122
|
+
scope_cache_ttl_minutes,
|
|
123
|
+
scope_cache_max_entries,
|
|
124
|
+
active_levels,
|
|
125
|
+
default_labels,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if HRBAC is enabled in the configuration
|
|
131
|
+
* Convenience function for quick checks
|
|
132
|
+
*/
|
|
133
|
+
export function is_hrbac_enabled(): boolean {
|
|
134
|
+
return get_config_boolean(SECTION_NAME, "enable_hrbac", false);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Gets the default organization from config
|
|
139
|
+
* Returns empty string if not configured (multi-tenant mode)
|
|
140
|
+
*/
|
|
141
|
+
export function get_default_org(): string {
|
|
142
|
+
return get_config_value(SECTION_NAME, "default_org", "");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets the default label for a scope level
|
|
147
|
+
*/
|
|
148
|
+
export function get_default_label(level: ScopeLevel): string {
|
|
149
|
+
const config_key = `default_label_l${level.charAt(level.length - 1)}`;
|
|
150
|
+
return get_config_value(SECTION_NAME, config_key, DEFAULT_LABELS[level]);
|
|
151
|
+
}
|