digitaltwin-core 0.14.2 → 1.0.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/LICENSE +20 -20
- package/README.md +494 -359
- package/dist/auth/apisix_parser.d.ts +141 -0
- package/dist/auth/apisix_parser.d.ts.map +1 -0
- package/dist/auth/apisix_parser.js +161 -0
- package/dist/auth/apisix_parser.js.map +1 -0
- package/dist/auth/auth_config.d.ts +126 -0
- package/dist/auth/auth_config.d.ts.map +1 -0
- package/dist/auth/auth_config.js +169 -0
- package/dist/auth/auth_config.js.map +1 -0
- package/dist/auth/auth_provider.d.ts +118 -0
- package/dist/auth/auth_provider.d.ts.map +1 -0
- package/dist/auth/auth_provider.js +8 -0
- package/dist/auth/auth_provider.js.map +1 -0
- package/dist/auth/auth_provider_factory.d.ts +91 -0
- package/dist/auth/auth_provider_factory.d.ts.map +1 -0
- package/dist/auth/auth_provider_factory.js +146 -0
- package/dist/auth/auth_provider_factory.js.map +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +7 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/providers/gateway_auth_provider.d.ts +78 -0
- package/dist/auth/providers/gateway_auth_provider.d.ts.map +1 -0
- package/dist/auth/providers/gateway_auth_provider.js +109 -0
- package/dist/auth/providers/gateway_auth_provider.js.map +1 -0
- package/dist/auth/providers/index.d.ts +4 -0
- package/dist/auth/providers/index.d.ts.map +1 -0
- package/dist/auth/providers/index.js +4 -0
- package/dist/auth/providers/index.js.map +1 -0
- package/dist/auth/providers/jwt_auth_provider.d.ts +91 -0
- package/dist/auth/providers/jwt_auth_provider.d.ts.map +1 -0
- package/dist/auth/providers/jwt_auth_provider.js +204 -0
- package/dist/auth/providers/jwt_auth_provider.js.map +1 -0
- package/dist/auth/providers/no_auth_provider.d.ts +61 -0
- package/dist/auth/providers/no_auth_provider.d.ts.map +1 -0
- package/dist/auth/providers/no_auth_provider.js +76 -0
- package/dist/auth/providers/no_auth_provider.js.map +1 -0
- package/dist/auth/types.d.ts +100 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/user_service.d.ts +86 -0
- package/dist/auth/user_service.d.ts.map +1 -0
- package/dist/auth/user_service.js +237 -0
- package/dist/auth/user_service.js.map +1 -0
- package/dist/components/assets_manager.d.ts +662 -0
- package/dist/components/assets_manager.d.ts.map +1 -0
- package/dist/components/assets_manager.js +1537 -0
- package/dist/components/assets_manager.js.map +1 -0
- package/dist/components/async_upload.d.ts +20 -0
- package/dist/components/async_upload.d.ts.map +1 -0
- package/dist/components/async_upload.js +10 -0
- package/dist/components/async_upload.js.map +1 -0
- package/dist/components/collector.d.ts +203 -0
- package/dist/components/collector.d.ts.map +1 -0
- package/dist/components/collector.js +214 -0
- package/dist/components/collector.js.map +1 -0
- package/dist/components/custom_table_manager.d.ts +503 -0
- package/dist/components/custom_table_manager.d.ts.map +1 -0
- package/dist/components/custom_table_manager.js +1023 -0
- package/dist/components/custom_table_manager.js.map +1 -0
- package/dist/components/global_assets_handler.d.ts +63 -0
- package/dist/components/global_assets_handler.d.ts.map +1 -0
- package/dist/components/global_assets_handler.js +127 -0
- package/dist/components/global_assets_handler.js.map +1 -0
- package/dist/components/handler.d.ts +104 -0
- package/dist/components/handler.d.ts.map +1 -0
- package/dist/components/handler.js +110 -0
- package/dist/components/handler.js.map +1 -0
- package/dist/components/harvester.d.ts +182 -0
- package/dist/components/harvester.d.ts.map +1 -0
- package/dist/components/harvester.js +406 -0
- package/dist/components/harvester.js.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +9 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/interfaces.d.ts +126 -0
- package/dist/components/interfaces.d.ts.map +1 -0
- package/dist/components/interfaces.js +8 -0
- package/dist/components/interfaces.js.map +1 -0
- package/dist/components/map_manager.d.ts +61 -0
- package/dist/components/map_manager.d.ts.map +1 -0
- package/dist/components/map_manager.js +242 -0
- package/dist/components/map_manager.js.map +1 -0
- package/dist/components/tileset_manager.d.ts +125 -0
- package/dist/components/tileset_manager.d.ts.map +1 -0
- package/dist/components/tileset_manager.js +623 -0
- package/dist/components/tileset_manager.js.map +1 -0
- package/dist/components/types.d.ts +226 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +8 -0
- package/dist/components/types.js.map +1 -0
- package/dist/database/adapters/knex_database_adapter.d.ts +97 -0
- package/dist/database/adapters/knex_database_adapter.d.ts.map +1 -0
- package/dist/database/adapters/knex_database_adapter.js +729 -0
- package/dist/database/adapters/knex_database_adapter.js.map +1 -0
- package/dist/database/database_adapter.d.ts +262 -0
- package/dist/database/database_adapter.d.ts.map +1 -0
- package/dist/database/database_adapter.js +46 -0
- package/dist/database/database_adapter.js.map +1 -0
- package/dist/engine/digital_twin_engine.d.ts +295 -0
- package/dist/engine/digital_twin_engine.d.ts.map +1 -0
- package/dist/engine/digital_twin_engine.js +907 -0
- package/dist/engine/digital_twin_engine.js.map +1 -0
- package/dist/engine/endpoints.d.ts +47 -0
- package/dist/engine/endpoints.d.ts.map +1 -0
- package/dist/engine/endpoints.js +88 -0
- package/dist/engine/endpoints.js.map +1 -0
- package/dist/engine/error_handler.d.ts +20 -0
- package/dist/engine/error_handler.d.ts.map +1 -0
- package/dist/engine/error_handler.js +69 -0
- package/dist/engine/error_handler.js.map +1 -0
- package/dist/engine/events.d.ts +93 -0
- package/dist/engine/events.d.ts.map +1 -0
- package/dist/engine/events.js +71 -0
- package/dist/engine/events.js.map +1 -0
- package/dist/engine/health.d.ts +112 -0
- package/dist/engine/health.d.ts.map +1 -0
- package/dist/engine/health.js +190 -0
- package/dist/engine/health.js.map +1 -0
- package/dist/engine/initializer.d.ts +62 -0
- package/dist/engine/initializer.d.ts.map +1 -0
- package/dist/engine/initializer.js +108 -0
- package/dist/engine/initializer.js.map +1 -0
- package/dist/engine/queue_manager.d.ts +87 -0
- package/dist/engine/queue_manager.d.ts.map +1 -0
- package/dist/engine/queue_manager.js +196 -0
- package/dist/engine/queue_manager.js.map +1 -0
- package/dist/engine/scheduler.d.ts +30 -0
- package/dist/engine/scheduler.d.ts.map +1 -0
- package/dist/engine/scheduler.js +378 -0
- package/dist/engine/scheduler.js.map +1 -0
- package/dist/engine/upload_processor.d.ts +36 -0
- package/dist/engine/upload_processor.d.ts.map +1 -0
- package/dist/engine/upload_processor.js +113 -0
- package/dist/engine/upload_processor.js.map +1 -0
- package/dist/env/env.d.ts +134 -0
- package/dist/env/env.d.ts.map +1 -0
- package/dist/env/env.js +177 -0
- package/dist/env/env.js.map +1 -0
- package/dist/errors/index.d.ts +94 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +149 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi/generator.d.ts +93 -0
- package/dist/openapi/generator.d.ts.map +1 -0
- package/dist/openapi/generator.js +293 -0
- package/dist/openapi/generator.js.map +1 -0
- package/dist/openapi/index.d.ts +9 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +9 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/types.d.ts +182 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/openapi/types.js +16 -0
- package/dist/openapi/types.js.map +1 -0
- package/dist/storage/adapters/local_storage_service.d.ts +57 -0
- package/dist/storage/adapters/local_storage_service.d.ts.map +1 -0
- package/dist/storage/adapters/local_storage_service.js +132 -0
- package/dist/storage/adapters/local_storage_service.js.map +1 -0
- package/dist/storage/adapters/ovh_storage_service.d.ts +72 -0
- package/dist/storage/adapters/ovh_storage_service.d.ts.map +1 -0
- package/dist/storage/adapters/ovh_storage_service.js +205 -0
- package/dist/storage/adapters/ovh_storage_service.js.map +1 -0
- package/dist/storage/storage_factory.d.ts +14 -0
- package/dist/storage/storage_factory.d.ts.map +1 -0
- package/dist/storage/storage_factory.js +43 -0
- package/dist/storage/storage_factory.js.map +1 -0
- package/dist/storage/storage_service.d.ts +163 -0
- package/dist/storage/storage_service.d.ts.map +1 -0
- package/dist/storage/storage_service.js +58 -0
- package/dist/storage/storage_service.js.map +1 -0
- package/dist/types/data_record.d.ts +123 -0
- package/dist/types/data_record.d.ts.map +1 -0
- package/dist/types/data_record.js +8 -0
- package/dist/types/data_record.js.map +1 -0
- package/dist/utils/graceful_shutdown.d.ts +44 -0
- package/dist/utils/graceful_shutdown.d.ts.map +1 -0
- package/dist/utils/graceful_shutdown.js +79 -0
- package/dist/utils/graceful_shutdown.js.map +1 -0
- package/dist/utils/http_responses.d.ts +175 -0
- package/dist/utils/http_responses.d.ts.map +1 -0
- package/dist/utils/http_responses.js +216 -0
- package/dist/utils/http_responses.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +74 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +92 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/map_to_data_record.d.ts +10 -0
- package/dist/utils/map_to_data_record.d.ts.map +1 -0
- package/dist/utils/map_to_data_record.js +36 -0
- package/dist/utils/map_to_data_record.js.map +1 -0
- package/dist/utils/safe_async.d.ts +50 -0
- package/dist/utils/safe_async.d.ts.map +1 -0
- package/dist/utils/safe_async.js +90 -0
- package/dist/utils/safe_async.js.map +1 -0
- package/dist/utils/servable_endpoint.d.ts +63 -0
- package/dist/utils/servable_endpoint.d.ts.map +1 -0
- package/dist/utils/servable_endpoint.js +67 -0
- package/dist/utils/servable_endpoint.js.map +1 -0
- package/dist/utils/zip_utils.d.ts +66 -0
- package/dist/utils/zip_utils.d.ts.map +1 -0
- package/dist/utils/zip_utils.js +169 -0
- package/dist/utils/zip_utils.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +7 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +273 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +82 -0
- package/dist/validation/schemas.js.map +1 -0
- package/dist/validation/validate.d.ts +49 -0
- package/dist/validation/validate.d.ts.map +1 -0
- package/dist/validation/validate.js +110 -0
- package/dist/validation/validate.js.map +1 -0
- package/package.json +23 -13
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { AuthenticatedUser } from './types.js';
|
|
2
|
+
import type { AuthProvider } from './auth_provider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parses authentication information from Apache APISIX headers set after Keycloak authentication.
|
|
5
|
+
*
|
|
6
|
+
* This class provides a static API for backward compatibility while internally using
|
|
7
|
+
* the AuthProvider system. It automatically handles:
|
|
8
|
+
* - Gateway mode (x-user-id, x-user-roles headers)
|
|
9
|
+
* - JWT mode (Authorization: Bearer token)
|
|
10
|
+
* - No-auth mode (DIGITALTWIN_DISABLE_AUTH=true)
|
|
11
|
+
*
|
|
12
|
+
* For new code, consider using AuthProviderFactory directly:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const authProvider = AuthProviderFactory.fromEnv()
|
|
15
|
+
* const user = authProvider.parseRequest(req)
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // In an AssetsManager handler
|
|
21
|
+
* if (!ApisixAuthParser.hasValidAuth(req.headers)) {
|
|
22
|
+
* return { status: 401, content: 'Authentication required' }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
|
|
26
|
+
* const userRecord = await this.userService.findOrCreateUser(authUser!)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class ApisixAuthParser {
|
|
30
|
+
private static _provider;
|
|
31
|
+
/**
|
|
32
|
+
* Get the authentication provider instance.
|
|
33
|
+
* Creates it on first use based on environment configuration.
|
|
34
|
+
*/
|
|
35
|
+
private static getProvider;
|
|
36
|
+
/**
|
|
37
|
+
* Reset the provider instance (useful for testing).
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
static _resetProvider(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Set a custom provider (useful for testing).
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
static _setProvider(provider: AuthProvider): void;
|
|
46
|
+
/**
|
|
47
|
+
* Create a request-like object from headers for the AuthProvider.
|
|
48
|
+
*/
|
|
49
|
+
private static toAuthRequest;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts user information from authentication headers.
|
|
52
|
+
*
|
|
53
|
+
* Parses the authentication headers (gateway mode) or JWT token (jwt mode):
|
|
54
|
+
* - Gateway: `x-user-id` and `x-user-roles` headers
|
|
55
|
+
* - JWT: `Authorization: Bearer <token>` header
|
|
56
|
+
*
|
|
57
|
+
* When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
|
|
58
|
+
* returns a default anonymous user.
|
|
59
|
+
*
|
|
60
|
+
* @param headers - HTTP request headers
|
|
61
|
+
* @returns Parsed user authentication data, or null if not authenticated
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const headers = {
|
|
66
|
+
* 'x-user-id': '6e06a527-a89d-4390-95cd-10ae63cfc939',
|
|
67
|
+
* 'x-user-roles': 'default-roles-master,offline_access'
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* const authUser = ApisixAuthParser.parseAuthHeaders(headers)
|
|
71
|
+
* // Returns: { id: '6e06a527...', roles: ['default-roles-master', 'offline_access'] }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
static parseAuthHeaders(headers: Record<string, string>): AuthenticatedUser | null;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a request has valid authentication.
|
|
77
|
+
*
|
|
78
|
+
* Performs a quick validation to determine if the request contains
|
|
79
|
+
* valid authentication credentials (gateway headers or JWT token).
|
|
80
|
+
*
|
|
81
|
+
* When authentication is disabled, this always returns true.
|
|
82
|
+
*
|
|
83
|
+
* @param headers - HTTP request headers
|
|
84
|
+
* @returns true if authentication is valid or disabled, false otherwise
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* if (!ApisixAuthParser.hasValidAuth(req.headers)) {
|
|
89
|
+
* return { status: 401, content: 'Authentication required' }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
static hasValidAuth(headers: Record<string, string>): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Extracts just the user ID from headers.
|
|
96
|
+
*
|
|
97
|
+
* Convenience method for cases where you only need the user ID.
|
|
98
|
+
*
|
|
99
|
+
* @param headers - HTTP request headers
|
|
100
|
+
* @returns User ID, or null if not authenticated
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const userId = ApisixAuthParser.getUserId(req.headers)
|
|
105
|
+
* if (userId) {
|
|
106
|
+
* console.log(`Request from user: ${userId}`)
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static getUserId(headers: Record<string, string>): string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts just the user roles from headers.
|
|
113
|
+
*
|
|
114
|
+
* @param headers - HTTP request headers
|
|
115
|
+
* @returns Array of role names, empty array if not authenticated
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const roles = ApisixAuthParser.getUserRoles(req.headers)
|
|
120
|
+
* if (roles.includes('admin')) {
|
|
121
|
+
* console.log('User has admin privileges')
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
static getUserRoles(headers: Record<string, string>): string[];
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a user has the admin role.
|
|
128
|
+
*
|
|
129
|
+
* @param headers - HTTP request headers
|
|
130
|
+
* @returns true if user has admin role, false otherwise
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* if (ApisixAuthParser.isAdmin(req.headers)) {
|
|
135
|
+
* // Admin-only logic
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
static isAdmin(headers: Record<string, string>): boolean;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=apisix_parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apisix_parser.d.ts","sourceRoot":"","sources":["../../src/auth/apisix_parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAA;AAGnE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,MAAM,CAAC,SAAS,CAA4B;IAEpD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAO1B;;;OAGG;IACH,MAAM,CAAC,cAAc,IAAI,IAAI;IAI7B;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAIjD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAI5B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,iBAAiB,GAAG,IAAI;IAIlF;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO;IAI7D;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI;IAIhE;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE;IAI9D;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO;CAG3D"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { AuthProviderFactory } from './auth_provider_factory.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses authentication information from Apache APISIX headers set after Keycloak authentication.
|
|
4
|
+
*
|
|
5
|
+
* This class provides a static API for backward compatibility while internally using
|
|
6
|
+
* the AuthProvider system. It automatically handles:
|
|
7
|
+
* - Gateway mode (x-user-id, x-user-roles headers)
|
|
8
|
+
* - JWT mode (Authorization: Bearer token)
|
|
9
|
+
* - No-auth mode (DIGITALTWIN_DISABLE_AUTH=true)
|
|
10
|
+
*
|
|
11
|
+
* For new code, consider using AuthProviderFactory directly:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const authProvider = AuthProviderFactory.fromEnv()
|
|
14
|
+
* const user = authProvider.parseRequest(req)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // In an AssetsManager handler
|
|
20
|
+
* if (!ApisixAuthParser.hasValidAuth(req.headers)) {
|
|
21
|
+
* return { status: 401, content: 'Authentication required' }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const authUser = ApisixAuthParser.parseAuthHeaders(req.headers)
|
|
25
|
+
* const userRecord = await this.userService.findOrCreateUser(authUser!)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class ApisixAuthParser {
|
|
29
|
+
static { this._provider = null; }
|
|
30
|
+
/**
|
|
31
|
+
* Get the authentication provider instance.
|
|
32
|
+
* Creates it on first use based on environment configuration.
|
|
33
|
+
*/
|
|
34
|
+
static getProvider() {
|
|
35
|
+
if (!this._provider) {
|
|
36
|
+
this._provider = AuthProviderFactory.fromEnv();
|
|
37
|
+
}
|
|
38
|
+
return this._provider;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reset the provider instance (useful for testing).
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
static _resetProvider() {
|
|
45
|
+
this._provider = null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set a custom provider (useful for testing).
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
static _setProvider(provider) {
|
|
52
|
+
this._provider = provider;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a request-like object from headers for the AuthProvider.
|
|
56
|
+
*/
|
|
57
|
+
static toAuthRequest(headers) {
|
|
58
|
+
return { headers };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extracts user information from authentication headers.
|
|
62
|
+
*
|
|
63
|
+
* Parses the authentication headers (gateway mode) or JWT token (jwt mode):
|
|
64
|
+
* - Gateway: `x-user-id` and `x-user-roles` headers
|
|
65
|
+
* - JWT: `Authorization: Bearer <token>` header
|
|
66
|
+
*
|
|
67
|
+
* When authentication is disabled (DIGITALTWIN_DISABLE_AUTH=true),
|
|
68
|
+
* returns a default anonymous user.
|
|
69
|
+
*
|
|
70
|
+
* @param headers - HTTP request headers
|
|
71
|
+
* @returns Parsed user authentication data, or null if not authenticated
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const headers = {
|
|
76
|
+
* 'x-user-id': '6e06a527-a89d-4390-95cd-10ae63cfc939',
|
|
77
|
+
* 'x-user-roles': 'default-roles-master,offline_access'
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* const authUser = ApisixAuthParser.parseAuthHeaders(headers)
|
|
81
|
+
* // Returns: { id: '6e06a527...', roles: ['default-roles-master', 'offline_access'] }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static parseAuthHeaders(headers) {
|
|
85
|
+
return this.getProvider().parseRequest(this.toAuthRequest(headers));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if a request has valid authentication.
|
|
89
|
+
*
|
|
90
|
+
* Performs a quick validation to determine if the request contains
|
|
91
|
+
* valid authentication credentials (gateway headers or JWT token).
|
|
92
|
+
*
|
|
93
|
+
* When authentication is disabled, this always returns true.
|
|
94
|
+
*
|
|
95
|
+
* @param headers - HTTP request headers
|
|
96
|
+
* @returns true if authentication is valid or disabled, false otherwise
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* if (!ApisixAuthParser.hasValidAuth(req.headers)) {
|
|
101
|
+
* return { status: 401, content: 'Authentication required' }
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
static hasValidAuth(headers) {
|
|
106
|
+
return this.getProvider().hasValidAuth(this.toAuthRequest(headers));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Extracts just the user ID from headers.
|
|
110
|
+
*
|
|
111
|
+
* Convenience method for cases where you only need the user ID.
|
|
112
|
+
*
|
|
113
|
+
* @param headers - HTTP request headers
|
|
114
|
+
* @returns User ID, or null if not authenticated
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const userId = ApisixAuthParser.getUserId(req.headers)
|
|
119
|
+
* if (userId) {
|
|
120
|
+
* console.log(`Request from user: ${userId}`)
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
static getUserId(headers) {
|
|
125
|
+
return this.getProvider().getUserId(this.toAuthRequest(headers));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Extracts just the user roles from headers.
|
|
129
|
+
*
|
|
130
|
+
* @param headers - HTTP request headers
|
|
131
|
+
* @returns Array of role names, empty array if not authenticated
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const roles = ApisixAuthParser.getUserRoles(req.headers)
|
|
136
|
+
* if (roles.includes('admin')) {
|
|
137
|
+
* console.log('User has admin privileges')
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
static getUserRoles(headers) {
|
|
142
|
+
return this.getProvider().getUserRoles(this.toAuthRequest(headers));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a user has the admin role.
|
|
146
|
+
*
|
|
147
|
+
* @param headers - HTTP request headers
|
|
148
|
+
* @returns true if user has admin role, false otherwise
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* if (ApisixAuthParser.isAdmin(req.headers)) {
|
|
153
|
+
* // Admin-only logic
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
static isAdmin(headers) {
|
|
158
|
+
return this.getProvider().isAdmin(this.toAuthRequest(headers));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=apisix_parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apisix_parser.js","sourceRoot":"","sources":["../../src/auth/apisix_parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,gBAAgB;aACV,cAAS,GAAwB,IAAI,CAAA;IAEpD;;;OAGG;IACK,MAAM,CAAC,WAAW;QACtB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,IAAI,CAAC,SAAS,GAAG,mBAAmB,CAAC,OAAO,EAAE,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,QAAsB;QACtC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;IAC7B,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,aAAa,CAAC,OAA+B;QACxD,OAAO,EAAE,OAAO,EAAE,CAAA;IACtB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAA+B;QACnD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IACvE,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,YAAY,CAAC,OAA+B;QAC/C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IACvE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,SAAS,CAAC,OAA+B;QAC5C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IACpE,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,YAAY,CAAC,OAA+B;QAC/C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IACvE,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,OAAO,CAAC,OAA+B;QAC1C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IAClE,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication configuration for Digital Twin framework.
|
|
3
|
+
*
|
|
4
|
+
* Controls whether authentication is required for components that support it.
|
|
5
|
+
* When authentication is disabled, all requests are treated as authenticated
|
|
6
|
+
* with a default anonymous user.
|
|
7
|
+
*
|
|
8
|
+
* Environment variables:
|
|
9
|
+
* - DIGITALTWIN_DISABLE_AUTH: Set to "true" or "1" to disable authentication (default: false)
|
|
10
|
+
* - DIGITALTWIN_ANONYMOUS_USER_ID: User ID to use when auth is disabled (default: "anonymous")
|
|
11
|
+
* - DIGITALTWIN_ADMIN_ROLE_NAME: Name of the admin role in Keycloak (default: "admin")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```bash
|
|
15
|
+
* # Disable authentication for development
|
|
16
|
+
* export DIGITALTWIN_DISABLE_AUTH=true
|
|
17
|
+
* export DIGITALTWIN_ANONYMOUS_USER_ID=dev-user-123
|
|
18
|
+
*
|
|
19
|
+
* # Configure admin role name
|
|
20
|
+
* export DIGITALTWIN_ADMIN_ROLE_NAME=administrator
|
|
21
|
+
*
|
|
22
|
+
* # Enable authentication (default)
|
|
23
|
+
* export DIGITALTWIN_DISABLE_AUTH=false
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { AuthConfig } from './auth_config.js'
|
|
29
|
+
*
|
|
30
|
+
* if (AuthConfig.isAuthDisabled()) {
|
|
31
|
+
* console.log('Authentication is disabled')
|
|
32
|
+
* const anonymousUser = AuthConfig.getAnonymousUser()
|
|
33
|
+
* console.log(`Using anonymous user: ${anonymousUser.id}`)
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const adminRole = AuthConfig.getAdminRoleName()
|
|
37
|
+
* console.log(`Admin role is: ${adminRole}`)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class AuthConfig {
|
|
41
|
+
private static _config;
|
|
42
|
+
/**
|
|
43
|
+
* Loads and validates authentication configuration from environment variables.
|
|
44
|
+
* This is called automatically the first time any method is used.
|
|
45
|
+
*/
|
|
46
|
+
private static loadConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the loaded configuration, ensuring it's initialized.
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private static getConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if authentication is disabled via environment variables.
|
|
54
|
+
*
|
|
55
|
+
* @returns true if DIGITALTWIN_DISABLE_AUTH is set to "true" or "1", false otherwise
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* if (AuthConfig.isAuthDisabled()) {
|
|
60
|
+
* console.log('Running in no-auth mode')
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
static isAuthDisabled(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if authentication is enabled (opposite of isAuthDisabled).
|
|
67
|
+
*
|
|
68
|
+
* @returns true if authentication should be enforced, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
static isAuthEnabled(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the anonymous user ID to use when authentication is disabled.
|
|
73
|
+
*
|
|
74
|
+
* @returns The user ID configured for anonymous access
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const userId = AuthConfig.getAnonymousUserId()
|
|
79
|
+
* console.log(`Anonymous user ID: ${userId}`) // "anonymous" by default
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static getAnonymousUserId(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Gets a fake authenticated user object for anonymous access.
|
|
85
|
+
*
|
|
86
|
+
* @returns An AuthenticatedUser object representing the anonymous user
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import type { AuthenticatedUser } from './types.js'
|
|
91
|
+
*
|
|
92
|
+
* const anonymousUser: AuthenticatedUser = AuthConfig.getAnonymousUser()
|
|
93
|
+
* console.log(anonymousUser) // { id: "anonymous", roles: ["anonymous"] }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
static getAnonymousUser(): {
|
|
97
|
+
id: string;
|
|
98
|
+
roles: string[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Gets the name of the admin role configured for the system.
|
|
102
|
+
*
|
|
103
|
+
* This role name is used to determine if a user has full administrative
|
|
104
|
+
* access to all resources, including private assets owned by other users.
|
|
105
|
+
*
|
|
106
|
+
* @returns The admin role name (default: "admin")
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const adminRole = AuthConfig.getAdminRoleName()
|
|
111
|
+
* console.log(`Admin role: ${adminRole}`) // "admin" by default
|
|
112
|
+
*
|
|
113
|
+
* // Check if user has admin role
|
|
114
|
+
* const userRoles = ['user', 'admin', 'moderator']
|
|
115
|
+
* const isAdmin = userRoles.includes(adminRole)
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
static getAdminRoleName(): string;
|
|
119
|
+
/**
|
|
120
|
+
* Resets the cached configuration (useful for testing).
|
|
121
|
+
*
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
static _resetConfig(): void;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=auth_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth_config.d.ts","sourceRoot":"","sources":["../../src/auth/auth_config.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAIP;IAEf;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAqCzB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAQxB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,cAAc,IAAI,OAAO;IAIhC;;;;OAIG;IACH,MAAM,CAAC,aAAa,IAAI,OAAO;IAI/B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,kBAAkB,IAAI,MAAM;IAInC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,gBAAgB;;;;IAOvB;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,gBAAgB,IAAI,MAAM;IAIjC;;;;OAIG;IACH,MAAM,CAAC,YAAY;CAGtB"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Env } from '../env/env.js';
|
|
2
|
+
/**
|
|
3
|
+
* Authentication configuration for Digital Twin framework.
|
|
4
|
+
*
|
|
5
|
+
* Controls whether authentication is required for components that support it.
|
|
6
|
+
* When authentication is disabled, all requests are treated as authenticated
|
|
7
|
+
* with a default anonymous user.
|
|
8
|
+
*
|
|
9
|
+
* Environment variables:
|
|
10
|
+
* - DIGITALTWIN_DISABLE_AUTH: Set to "true" or "1" to disable authentication (default: false)
|
|
11
|
+
* - DIGITALTWIN_ANONYMOUS_USER_ID: User ID to use when auth is disabled (default: "anonymous")
|
|
12
|
+
* - DIGITALTWIN_ADMIN_ROLE_NAME: Name of the admin role in Keycloak (default: "admin")
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```bash
|
|
16
|
+
* # Disable authentication for development
|
|
17
|
+
* export DIGITALTWIN_DISABLE_AUTH=true
|
|
18
|
+
* export DIGITALTWIN_ANONYMOUS_USER_ID=dev-user-123
|
|
19
|
+
*
|
|
20
|
+
* # Configure admin role name
|
|
21
|
+
* export DIGITALTWIN_ADMIN_ROLE_NAME=administrator
|
|
22
|
+
*
|
|
23
|
+
* # Enable authentication (default)
|
|
24
|
+
* export DIGITALTWIN_DISABLE_AUTH=false
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { AuthConfig } from './auth_config.js'
|
|
30
|
+
*
|
|
31
|
+
* if (AuthConfig.isAuthDisabled()) {
|
|
32
|
+
* console.log('Authentication is disabled')
|
|
33
|
+
* const anonymousUser = AuthConfig.getAnonymousUser()
|
|
34
|
+
* console.log(`Using anonymous user: ${anonymousUser.id}`)
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* const adminRole = AuthConfig.getAdminRoleName()
|
|
38
|
+
* console.log(`Admin role is: ${adminRole}`)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class AuthConfig {
|
|
42
|
+
static { this._config = null; }
|
|
43
|
+
/**
|
|
44
|
+
* Loads and validates authentication configuration from environment variables.
|
|
45
|
+
* This is called automatically the first time any method is used.
|
|
46
|
+
*/
|
|
47
|
+
static loadConfig() {
|
|
48
|
+
if (this._config !== null)
|
|
49
|
+
return;
|
|
50
|
+
const config = Env.validate({
|
|
51
|
+
DIGITALTWIN_DISABLE_AUTH: Env.schema.boolean({
|
|
52
|
+
optional: true,
|
|
53
|
+
default: false
|
|
54
|
+
}),
|
|
55
|
+
DIGITALTWIN_ANONYMOUS_USER_ID: Env.schema.string({
|
|
56
|
+
optional: true
|
|
57
|
+
}),
|
|
58
|
+
DIGITALTWIN_ADMIN_ROLE_NAME: Env.schema.string({
|
|
59
|
+
optional: true
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
// Set default anonymous user ID if not provided
|
|
63
|
+
if (!config.DIGITALTWIN_ANONYMOUS_USER_ID) {
|
|
64
|
+
config.DIGITALTWIN_ANONYMOUS_USER_ID = 'anonymous';
|
|
65
|
+
}
|
|
66
|
+
// Set default admin role name if not provided
|
|
67
|
+
if (!config.DIGITALTWIN_ADMIN_ROLE_NAME) {
|
|
68
|
+
config.DIGITALTWIN_ADMIN_ROLE_NAME = 'admin';
|
|
69
|
+
}
|
|
70
|
+
this._config = config;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the loaded configuration, ensuring it's initialized.
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
static getConfig() {
|
|
77
|
+
this.loadConfig();
|
|
78
|
+
if (this._config === null) {
|
|
79
|
+
throw new Error('Failed to load authentication configuration');
|
|
80
|
+
}
|
|
81
|
+
return this._config;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checks if authentication is disabled via environment variables.
|
|
85
|
+
*
|
|
86
|
+
* @returns true if DIGITALTWIN_DISABLE_AUTH is set to "true" or "1", false otherwise
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* if (AuthConfig.isAuthDisabled()) {
|
|
91
|
+
* console.log('Running in no-auth mode')
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
static isAuthDisabled() {
|
|
96
|
+
return this.getConfig().DIGITALTWIN_DISABLE_AUTH;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Checks if authentication is enabled (opposite of isAuthDisabled).
|
|
100
|
+
*
|
|
101
|
+
* @returns true if authentication should be enforced, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
static isAuthEnabled() {
|
|
104
|
+
return !this.isAuthDisabled();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets the anonymous user ID to use when authentication is disabled.
|
|
108
|
+
*
|
|
109
|
+
* @returns The user ID configured for anonymous access
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const userId = AuthConfig.getAnonymousUserId()
|
|
114
|
+
* console.log(`Anonymous user ID: ${userId}`) // "anonymous" by default
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
static getAnonymousUserId() {
|
|
118
|
+
return this.getConfig().DIGITALTWIN_ANONYMOUS_USER_ID;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Gets a fake authenticated user object for anonymous access.
|
|
122
|
+
*
|
|
123
|
+
* @returns An AuthenticatedUser object representing the anonymous user
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import type { AuthenticatedUser } from './types.js'
|
|
128
|
+
*
|
|
129
|
+
* const anonymousUser: AuthenticatedUser = AuthConfig.getAnonymousUser()
|
|
130
|
+
* console.log(anonymousUser) // { id: "anonymous", roles: ["anonymous"] }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
static getAnonymousUser() {
|
|
134
|
+
return {
|
|
135
|
+
id: this.getAnonymousUserId(),
|
|
136
|
+
roles: ['anonymous']
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets the name of the admin role configured for the system.
|
|
141
|
+
*
|
|
142
|
+
* This role name is used to determine if a user has full administrative
|
|
143
|
+
* access to all resources, including private assets owned by other users.
|
|
144
|
+
*
|
|
145
|
+
* @returns The admin role name (default: "admin")
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const adminRole = AuthConfig.getAdminRoleName()
|
|
150
|
+
* console.log(`Admin role: ${adminRole}`) // "admin" by default
|
|
151
|
+
*
|
|
152
|
+
* // Check if user has admin role
|
|
153
|
+
* const userRoles = ['user', 'admin', 'moderator']
|
|
154
|
+
* const isAdmin = userRoles.includes(adminRole)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
static getAdminRoleName() {
|
|
158
|
+
return this.getConfig().DIGITALTWIN_ADMIN_ROLE_NAME;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resets the cached configuration (useful for testing).
|
|
162
|
+
*
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
static _resetConfig() {
|
|
166
|
+
this._config = null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=auth_config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth_config.js","sourceRoot":"","sources":["../../src/auth/auth_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,OAAO,UAAU;aACJ,YAAO,GAIX,IAAI,CAAA;IAEf;;;OAGG;IACK,MAAM,CAAC,UAAU;QACrB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;YAAE,OAAM;QAEjC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC;YACxB,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC;gBACzC,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,KAAK;aACjB,CAAC;YACF,6BAA6B,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC7C,QAAQ,EAAE,IAAI;aACjB,CAAC;YACF,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC3C,QAAQ,EAAE,IAAI;aACjB,CAAC;SACL,CAIA,CAAA;QAED,gDAAgD;QAChD,IAAI,CAAC,MAAM,CAAC,6BAA6B,EAAE,CAAC;YACxC,MAAM,CAAC,6BAA6B,GAAG,WAAW,CAAA;QACtD,CAAC;QAED,8CAA8C;QAC9C,IAAI,CAAC,MAAM,CAAC,2BAA2B,EAAE,CAAC;YACtC,MAAM,CAAC,2BAA2B,GAAG,OAAO,CAAA;QAChD,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAId,CAAA;IACL,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,SAAS;QACpB,IAAI,CAAC,UAAU,EAAE,CAAA;QACjB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAClE,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAA;IACvB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,cAAc;QACjB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,wBAAwB,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa;QAChB,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,CAAA;IACjC,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,kBAAkB;QACrB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,6BAA6B,CAAA;IACzD,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,gBAAgB;QACnB,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,kBAAkB,EAAE;YAC7B,KAAK,EAAE,CAAC,WAAW,CAAC;SACvB,CAAA;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,gBAAgB;QACnB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAA;IACvD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY;QACf,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACvB,CAAC"}
|