emilsoftware-utilities 2.0.0-dev.66 → 2.0.0-dev.68
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/dist/EmilsoftwareModule.d.ts +11 -3
- package/dist/EmilsoftwareModule.js +1 -1
- package/dist/EmilsoftwareModule.js.map +1 -1
- package/dist/accessi/client/index.d.ts +26 -0
- package/dist/accessi/client/index.js +49 -0
- package/dist/accessi/client/index.js.map +1 -0
- package/dist/accessi/console/index.d.ts +15 -0
- package/dist/accessi/console/index.js +25 -0
- package/dist/accessi/console/index.js.map +1 -0
- package/dist/accessi/contracts/dtos.d.ts +8 -0
- package/dist/accessi/contracts/dtos.js +25 -0
- package/dist/accessi/contracts/dtos.js.map +1 -0
- package/dist/accessi/contracts/index.d.ts +25 -0
- package/dist/accessi/contracts/index.js +28 -0
- package/dist/accessi/contracts/index.js.map +1 -0
- package/dist/accessi/openapi/index.d.ts +2 -0
- package/dist/accessi/openapi/index.js +19 -0
- package/dist/accessi/openapi/index.js.map +1 -0
- package/dist/accessi/resource-server/core.d.ts +6 -0
- package/dist/accessi/resource-server/core.js +23 -0
- package/dist/accessi/resource-server/core.js.map +1 -0
- package/dist/accessi/resource-server/errors.d.ts +10 -0
- package/dist/accessi/resource-server/errors.js +19 -0
- package/dist/accessi/resource-server/errors.js.map +1 -0
- package/dist/accessi/resource-server/express.d.ts +17 -0
- package/dist/accessi/resource-server/express.js +66 -0
- package/dist/accessi/resource-server/express.js.map +1 -0
- package/dist/accessi/resource-server/index.d.ts +3 -0
- package/dist/accessi/resource-server/index.js +20 -0
- package/dist/accessi/resource-server/index.js.map +1 -0
- package/dist/accessi/resource-server/introspection.d.ts +16 -0
- package/dist/accessi/resource-server/introspection.js +115 -0
- package/dist/accessi/resource-server/introspection.js.map +1 -0
- package/dist/accessi/resource-server/keys.d.ts +11 -0
- package/dist/accessi/resource-server/keys.js +22 -0
- package/dist/accessi/resource-server/keys.js.map +1 -0
- package/dist/accessi/resource-server/nest.d.ts +9 -0
- package/dist/accessi/resource-server/nest.js +62 -0
- package/dist/accessi/resource-server/nest.js.map +1 -0
- package/dist/accessi/resource-server/runtime.d.ts +27 -0
- package/dist/accessi/resource-server/runtime.js +128 -0
- package/dist/accessi/resource-server/runtime.js.map +1 -0
- package/dist/accessi/resource-server/token.d.ts +23 -0
- package/dist/accessi/resource-server/token.js +230 -0
- package/dist/accessi/resource-server/token.js.map +1 -0
- package/dist/accessi/resource-server/types.d.ts +78 -0
- package/dist/accessi/resource-server/types.js +3 -0
- package/dist/accessi/resource-server/types.js.map +1 -0
- package/dist/accessi/server/index.d.ts +10 -0
- package/dist/accessi/server/index.js +29 -0
- package/dist/accessi/server/index.js.map +1 -0
- package/dist/accessi/ui/index.d.ts +13 -0
- package/dist/accessi/ui/index.js +19 -0
- package/dist/accessi/ui/index.js.map +1 -0
- package/dist/accessi-module/AccessiModule.d.ts +52 -2
- package/dist/accessi-module/AccessiModule.js +2 -0
- package/dist/accessi-module/AccessiModule.js.map +1 -1
- package/dist/accessi-module/Console/accessiFetch.d.ts +4 -0
- package/dist/accessi-module/Console/accessiFetch.js +18 -4
- package/dist/accessi-module/Console/accessiFetch.js.map +1 -1
- package/dist/accessi-module/Console/console.js +122 -11
- package/dist/accessi-module/Console/console.js.map +1 -1
- package/dist/accessi-module/Console/generated/{accessiApi.d.ts → emilsoftware-utilities.d.ts} +11 -1
- package/dist/accessi-module/Console/generated/{accessiApi.js → emilsoftware-utilities.js} +10 -2
- package/dist/accessi-module/Console/generated/emilsoftware-utilities.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.d.ts +16 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.js +3 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/index.d.ts +3 -0
- package/dist/accessi-module/Console/generated/model/index.js +3 -0
- package/dist/accessi-module/Console/generated/model/index.js.map +1 -1
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.d.ts +10 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.js +9 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.d.ts +14 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.js +3 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.js.map +1 -0
- package/dist/accessi-module/Console/wiki.js +106 -5
- package/dist/accessi-module/Console/wiki.js.map +1 -1
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.d.ts +17 -0
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.js +93 -0
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.js.map +1 -0
- package/dist/accessi-module/Controllers/AuthController.js +6 -6
- package/dist/accessi-module/Controllers/AuthController.js.map +1 -1
- package/dist/accessi-module/Controllers/ConsoleEntryController.d.ts +2 -0
- package/dist/accessi-module/Controllers/ConsoleEntryController.js +11 -3
- package/dist/accessi-module/Controllers/ConsoleEntryController.js.map +1 -1
- package/dist/accessi-module/Controllers/EmailController.js +1 -1
- package/dist/accessi-module/Controllers/EmailController.js.map +1 -1
- package/dist/accessi-module/Controllers/UserController.js +1 -1
- package/dist/accessi-module/Controllers/UserController.js.map +1 -1
- package/dist/accessi-module/Dtos/IntrospectionDtos.d.ts +16 -0
- package/dist/accessi-module/Dtos/IntrospectionDtos.js +59 -0
- package/dist/accessi-module/Dtos/IntrospectionDtos.js.map +1 -0
- package/dist/accessi-module/Dtos/index.d.ts +1 -0
- package/dist/accessi-module/Dtos/index.js +1 -0
- package/dist/accessi-module/Dtos/index.js.map +1 -1
- package/dist/accessi-module/Services/AuthService/AuthService.d.ts +13 -0
- package/dist/accessi-module/Services/AuthService/AuthService.js +42 -10
- package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
- package/dist/accessi-module/database-updates/accessiOptionsFromEnv.js +18 -19
- package/dist/accessi-module/database-updates/accessiOptionsFromEnv.js.map +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeed.d.ts +2 -2
- package/dist/accessi-module/database-updates/menuScopeSeed.js +101 -53
- package/dist/accessi-module/database-updates/menuScopeSeed.js.map +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeeder.js +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeeder.js.map +1 -1
- package/dist/accessi-module/index.d.ts +25 -4
- package/dist/accessi-module/index.js +47 -21
- package/dist/accessi-module/index.js.map +1 -1
- package/dist/accessi-module/jwt/jwt.strategy.js +5 -5
- package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
- package/dist/accessi-module/middleware/authenticateGen.js +5 -5
- package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
- package/dist/accessi-module/security/consoleEntry.d.ts +56 -11
- package/dist/accessi-module/security/consoleEntry.js +165 -31
- package/dist/accessi-module/security/consoleEntry.js.map +1 -1
- package/dist/accessi-module/security/edgeRateLimit.d.ts +31 -0
- package/dist/accessi-module/security/edgeRateLimit.js +70 -0
- package/dist/accessi-module/security/edgeRateLimit.js.map +1 -0
- package/dist/accessi-module/security/jwks.d.ts +33 -0
- package/dist/accessi-module/security/jwks.js +83 -0
- package/dist/accessi-module/security/jwks.js.map +1 -0
- package/dist/accessi-module/security/jwtTokenOptions.d.ts +15 -0
- package/dist/accessi-module/security/jwtTokenOptions.js +44 -0
- package/dist/accessi-module/security/jwtTokenOptions.js.map +1 -0
- package/dist/accessi-module/security/publicAuthRateLimit.d.ts +8 -6
- package/dist/accessi-module/security/publicAuthRateLimit.js +54 -78
- package/dist/accessi-module/security/publicAuthRateLimit.js.map +1 -1
- package/dist/accessi-module/security/rateLimitStore.d.ts +32 -0
- package/dist/accessi-module/security/rateLimitStore.js +129 -0
- package/dist/accessi-module/security/rateLimitStore.js.map +1 -0
- package/dist/accessi-module/security/serviceTokenGuard.d.ts +3 -1
- package/dist/accessi-module/security/serviceTokenGuard.js +11 -6
- package/dist/accessi-module/security/serviceTokenGuard.js.map +1 -1
- package/dist/accessi-module/security/serviceTokenRateLimit.d.ts +5 -4
- package/dist/accessi-module/security/serviceTokenRateLimit.js +33 -29
- package/dist/accessi-module/security/serviceTokenRateLimit.js.map +1 -1
- package/dist/accessi-module/startupLog.d.ts +3 -2
- package/dist/accessi-module/startupLog.js +8 -4
- package/dist/accessi-module/startupLog.js.map +1 -1
- package/dist/allegati-module/index.js +2 -2
- package/dist/allegati-module/index.js.map +1 -1
- package/dist/angular-components/aree-disponibili/demo.html +4 -4
- package/dist/emilsoftware-utilities-2.0.0-dev.68.tgz +0 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/initEmilsoftwareModule.d.ts +11 -1
- package/dist/initEmilsoftwareModule.js +29 -23
- package/dist/initEmilsoftwareModule.js.map +1 -1
- package/dist/openapi/OpenApiConfig.d.ts +68 -0
- package/dist/openapi/OpenApiConfig.js +157 -0
- package/dist/openapi/OpenApiConfig.js.map +1 -0
- package/dist/openapi/OpenApiMerge.d.ts +15 -0
- package/dist/openapi/OpenApiMerge.js +119 -0
- package/dist/openapi/OpenApiMerge.js.map +1 -0
- package/docs/gateway-rate-limit.md +98 -0
- package/integration-prompt.md +612 -0
- package/package.json +89 -5
- package/dist/accessi-module/Console/generated/accessiApi.js.map +0 -1
- package/dist/emilsoftware-utilities-2.0.0-dev.66.tgz +0 -0
- package/dist/swagger/SwaggerConfig.d.ts +0 -8
- package/dist/swagger/SwaggerConfig.js +0 -41
- package/dist/swagger/SwaggerConfig.js.map +0 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createAccessiTokenVerifier = createAccessiTokenVerifier;
|
|
46
|
+
exports.verifyAccessiAccessToken = verifyAccessiAccessToken;
|
|
47
|
+
const crypto_1 = require("crypto");
|
|
48
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
49
|
+
const contracts_1 = require("../contracts");
|
|
50
|
+
const errors_1 = require("./errors");
|
|
51
|
+
const keys_1 = require("./keys");
|
|
52
|
+
function isRecord(value) {
|
|
53
|
+
return typeof value === "object" && value !== null;
|
|
54
|
+
}
|
|
55
|
+
function extractUser(payload) {
|
|
56
|
+
const userData = isRecord(payload.userData) ? payload.userData : undefined;
|
|
57
|
+
const utente = isRecord(payload.utente)
|
|
58
|
+
? payload.utente
|
|
59
|
+
: isRecord(userData === null || userData === void 0 ? void 0 : userData.utente)
|
|
60
|
+
? userData.utente
|
|
61
|
+
: undefined;
|
|
62
|
+
return utente !== null && utente !== void 0 ? utente : {};
|
|
63
|
+
}
|
|
64
|
+
function defaultAlgorithms(options) {
|
|
65
|
+
if (options.algorithms && options.algorithms.length > 0)
|
|
66
|
+
return options.algorithms;
|
|
67
|
+
const algorithms = [];
|
|
68
|
+
if (options.secret || options.serverSecret)
|
|
69
|
+
algorithms.push("HS256");
|
|
70
|
+
if (options.publicKey || options.jwks) {
|
|
71
|
+
algorithms.push("RS256", "RS384", "RS512", "ES256", "ES384", "ES512");
|
|
72
|
+
}
|
|
73
|
+
return algorithms;
|
|
74
|
+
}
|
|
75
|
+
function algorithmFamily(algorithm) {
|
|
76
|
+
return algorithm.startsWith("HS") ? "hmac" : "asymmetric";
|
|
77
|
+
}
|
|
78
|
+
function fetchJwks(options) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch;
|
|
82
|
+
if (typeof fetchImpl !== "function") {
|
|
83
|
+
throw (0, errors_1.accessiAuthError)(500, "AUTH_CONFIG_INVALID", "fetch non disponibile per caricare la JWKS.");
|
|
84
|
+
}
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const timeout = setTimeout(() => controller.abort(), (_b = options.timeoutMs) !== null && _b !== void 0 ? _b : 3000);
|
|
87
|
+
try {
|
|
88
|
+
const response = yield fetchImpl(options.url, {
|
|
89
|
+
method: "GET",
|
|
90
|
+
headers: { Accept: "application/json" },
|
|
91
|
+
signal: controller.signal,
|
|
92
|
+
});
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw (0, errors_1.accessiAuthError)(503, "AUTH_JWKS_UNAVAILABLE", `JWKS non disponibile (HTTP ${response.status}).`);
|
|
95
|
+
}
|
|
96
|
+
const payload = yield response.json();
|
|
97
|
+
if (!isRecord(payload) || !Array.isArray(payload.keys)) {
|
|
98
|
+
throw (0, errors_1.accessiAuthError)(503, "AUTH_JWKS_UNAVAILABLE", "Risposta JWKS non valida.");
|
|
99
|
+
}
|
|
100
|
+
return payload.keys.filter(isRecord);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error && typeof error === "object" && "code" in error && "status" in error) {
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
throw (0, errors_1.accessiAuthError)(503, "AUTH_JWKS_UNAVAILABLE", "JWKS non raggiungibile.");
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
clearTimeout(timeout);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function selectJwk(keys, kid, algorithm) {
|
|
114
|
+
const candidates = keys.filter((key) => {
|
|
115
|
+
const keyAlg = typeof key.alg === "string" ? key.alg : undefined;
|
|
116
|
+
const keyKid = typeof key.kid === "string" ? key.kid : undefined;
|
|
117
|
+
if (keyAlg && keyAlg !== algorithm)
|
|
118
|
+
return false;
|
|
119
|
+
if (kid && keyKid && keyKid !== kid)
|
|
120
|
+
return false;
|
|
121
|
+
return true;
|
|
122
|
+
});
|
|
123
|
+
const selected = candidates[0];
|
|
124
|
+
if (!selected) {
|
|
125
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Chiave JWKS non trovata per il token.");
|
|
126
|
+
}
|
|
127
|
+
return selected;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Crea un verificatore locale riutilizzabile.
|
|
131
|
+
*
|
|
132
|
+
* Supporta HMAC, chiavi pubbliche PEM (RS ed ES) e JWKS remoto. La cache
|
|
133
|
+
* JWKS e legata all'istanza del verificatore.
|
|
134
|
+
*/
|
|
135
|
+
function createAccessiTokenVerifier(options) {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
const algorithms = defaultAlgorithms(options);
|
|
138
|
+
if (algorithms.length === 0) {
|
|
139
|
+
throw (0, errors_1.accessiAuthError)(500, "AUTH_CONFIG_INVALID", "Configurare almeno una tra jwt.secret, jwt.serverSecret, jwt.publicKey e jwt.jwks.");
|
|
140
|
+
}
|
|
141
|
+
const clockTolerance = (_a = options.clockToleranceSeconds) !== null && _a !== void 0 ? _a : 5;
|
|
142
|
+
const hmacSecret = (_b = options.secret) !== null && _b !== void 0 ? _b : (options.serverSecret ? (0, keys_1.deriveAccessiAccessSecret)(options.serverSecret) : undefined);
|
|
143
|
+
let jwksCache;
|
|
144
|
+
const getJwksKeys = () => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
var _a;
|
|
146
|
+
if (!options.jwks)
|
|
147
|
+
return [];
|
|
148
|
+
if (jwksCache && jwksCache.expiresAt > Date.now())
|
|
149
|
+
return jwksCache.keys;
|
|
150
|
+
const keys = yield fetchJwks(options.jwks);
|
|
151
|
+
jwksCache = {
|
|
152
|
+
keys,
|
|
153
|
+
expiresAt: Date.now() + Math.max(1000, (_a = options.jwks.cacheTtlMs) !== null && _a !== void 0 ? _a : 300000),
|
|
154
|
+
};
|
|
155
|
+
return keys;
|
|
156
|
+
});
|
|
157
|
+
const verify = (token) => __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const decoded = jwt.decode(token, { complete: true });
|
|
159
|
+
if (!decoded || typeof decoded === "string" || !isRecord(decoded.header)) {
|
|
160
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Token JWT non valido.");
|
|
161
|
+
}
|
|
162
|
+
const algorithm = typeof decoded.header.alg === "string" ? decoded.header.alg : undefined;
|
|
163
|
+
if (!algorithm || !algorithms.includes(algorithm)) {
|
|
164
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Algoritmo JWT non consentito.");
|
|
165
|
+
}
|
|
166
|
+
let key;
|
|
167
|
+
if (algorithmFamily(algorithm) === "hmac") {
|
|
168
|
+
if (!hmacSecret) {
|
|
169
|
+
throw (0, errors_1.accessiAuthError)(500, "AUTH_CONFIG_INVALID", "jwt.secret o jwt.serverSecret non configurato per token HS*.");
|
|
170
|
+
}
|
|
171
|
+
key = hmacSecret;
|
|
172
|
+
}
|
|
173
|
+
else if (options.publicKey) {
|
|
174
|
+
key = options.publicKey;
|
|
175
|
+
}
|
|
176
|
+
else if (options.jwks) {
|
|
177
|
+
const keys = yield getJwksKeys();
|
|
178
|
+
const kid = typeof decoded.header.kid === "string" ? decoded.header.kid : undefined;
|
|
179
|
+
key = (0, crypto_1.createPublicKey)({ key: selectJwk(keys, kid, algorithm), format: "jwk" })
|
|
180
|
+
.export({ type: "spki", format: "pem" });
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
throw (0, errors_1.accessiAuthError)(500, "AUTH_CONFIG_INVALID", "jwt.publicKey/jwt.jwks non configurati.");
|
|
184
|
+
}
|
|
185
|
+
let verified;
|
|
186
|
+
try {
|
|
187
|
+
verified = jwt.verify(token, key, Object.assign(Object.assign(Object.assign({ algorithms: [algorithm] }, (options.issuer ? { issuer: options.issuer } : {})), (options.audience
|
|
188
|
+
? { audience: options.audience }
|
|
189
|
+
: {})), { clockTolerance }));
|
|
190
|
+
}
|
|
191
|
+
catch (_a) {
|
|
192
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Token non valido o scaduto.");
|
|
193
|
+
}
|
|
194
|
+
if (!isRecord(verified)) {
|
|
195
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Payload JWT non valido.");
|
|
196
|
+
}
|
|
197
|
+
if (verified.typ !== "access") {
|
|
198
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_INVALID", "Il token non e un access token Accessi.");
|
|
199
|
+
}
|
|
200
|
+
const codiceUtente = (0, contracts_1.resolveCodiceUtenteFromTokenPayload)(verified);
|
|
201
|
+
if (!codiceUtente) {
|
|
202
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_USER_CODE_MISSING", "Token privo di un utente valido.");
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
token,
|
|
206
|
+
payload: verified,
|
|
207
|
+
codiceUtente,
|
|
208
|
+
user: extractUser(verified),
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
verify,
|
|
213
|
+
verifyAuthorizationHeader(header) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const token = (0, contracts_1.extractAccessiBearerToken)(header);
|
|
216
|
+
if (!token) {
|
|
217
|
+
throw (0, errors_1.accessiAuthError)(401, "AUTH_TOKEN_MISSING", "Token Bearer mancante o malformato.");
|
|
218
|
+
}
|
|
219
|
+
return verify(token);
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** Converte un header `Authorization` in verifica del token, senza cache JWKS condivisa. */
|
|
225
|
+
function verifyAccessiAccessToken(header, options) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
return createAccessiTokenVerifier(options).verifyAuthorizationHeader(header);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../src/accessi/resource-server/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHA,gEAsGC;AAGD,4DAKC;AAtOD,mCAAyC;AAEzC,kDAAoC;AAEpC,4CAA8F;AAC9F,qCAA4C;AAC5C,iCAAmD;AAsBnD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,WAAW,CAAC,OAAgC;IACnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;QACrC,CAAC,CAAC,OAAO,CAAC,MAAM;QAChB,CAAC,CAAC,QAAQ,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC;YAC1B,CAAC,CAAC,QAAQ,CAAC,MAAM;YACjB,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAwC;IACjE,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC,UAAU,CAAC;IAEnF,MAAM,UAAU,GAA0B,EAAE,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,YAAY;QAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC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AC;QAED,MAAM,YAAY,GAAG,IAAA,+CAAmC,EAAC,QAAQ,CAAC,CAAC;QACnE,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAA,yBAAgB,EAAC,GAAG,EAAE,wBAAwB,EAAE,kCAAkC,CAAC,CAAC;QAC5F,CAAC;QAED,OAAO;YACL,KAAK;YACL,OAAO,EAAE,QAAqC;YAC9C,YAAY;YACZ,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC;SAC5B,CAAC;IACJ,CAAC,CAAA,CAAC;IAEF,OAAO;QACL,MAAM;QACA,yBAAyB,CAAC,MAAe;;gBAC7C,MAAM,KAAK,GAAG,IAAA,qCAAyB,EAAC,MAAM,CAAC,CAAC;gBAChD,IAAI,CAAC,KAAK,EAAE,CAAC;oBACX,MAAM,IAAA,yBAAgB,EAAC,GAAG,EAAE,oBAAoB,EAAE,qCAAqC,CAAC,CAAC;gBAC3F,CAAC;gBACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;SAAA;KACF,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,SAAsB,wBAAwB,CAC5C,MAAe,EACf,OAAwC;;QAExC,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;CAAA","sourcesContent":["import { createPublicKey } from \"crypto\";\nimport type { JsonWebKey } from \"crypto\";\nimport * as jwt from \"jsonwebtoken\";\nimport type { AccessiAccessTokenPayload } from \"../contracts\";\nimport { extractAccessiBearerToken, resolveCodiceUtenteFromTokenPayload } from \"../contracts\";\nimport { accessiAuthError } from \"./errors\";\nimport { deriveAccessiAccessSecret } from \"./keys\";\nimport type { AccessiJwtAlgorithm, AccessiResourceServerJwtOptions } from \"./types\";\n\n/** Esito della verifica locale di un access token. */\nexport interface AccessiTokenVerification {\n token: string;\n payload: AccessiAccessTokenPayload;\n codiceUtente: number;\n user: Record<string, unknown>;\n}\n\n/** Verificatore riutilizzabile: conserva la cache JWKS tra una richiesta e l'altra. */\nexport interface AccessiTokenVerifier {\n verify(token: string): Promise<AccessiTokenVerification>;\n verifyAuthorizationHeader(header: unknown): Promise<AccessiTokenVerification>;\n}\n\ninterface JwksCacheEntry {\n keys: Array<Record<string, unknown>>;\n expiresAt: number;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction extractUser(payload: Record<string, unknown>): Record<string, unknown> {\n const userData = isRecord(payload.userData) ? payload.userData : undefined;\n const utente = isRecord(payload.utente)\n ? payload.utente\n : isRecord(userData?.utente)\n ? userData.utente\n : undefined;\n return utente ?? {};\n}\n\nfunction defaultAlgorithms(options: AccessiResourceServerJwtOptions): AccessiJwtAlgorithm[] {\n if (options.algorithms && options.algorithms.length > 0) return options.algorithms;\n\n const algorithms: AccessiJwtAlgorithm[] = [];\n if (options.secret || options.serverSecret) algorithms.push(\"HS256\");\n if (options.publicKey || options.jwks) {\n algorithms.push(\"RS256\", \"RS384\", \"RS512\", \"ES256\", \"ES384\", \"ES512\");\n }\n return algorithms;\n}\n\nfunction algorithmFamily(algorithm: string): \"hmac\" | \"asymmetric\" {\n return algorithm.startsWith(\"HS\") ? \"hmac\" : \"asymmetric\";\n}\n\nasync function fetchJwks(\n options: NonNullable<AccessiResourceServerJwtOptions[\"jwks\"]>,\n): Promise<Array<Record<string, unknown>>> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") {\n throw accessiAuthError(500, \"AUTH_CONFIG_INVALID\", \"fetch non disponibile per caricare la JWKS.\");\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? 3000);\n try {\n const response = await fetchImpl(options.url, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n signal: controller.signal,\n });\n if (!response.ok) {\n throw accessiAuthError(\n 503,\n \"AUTH_JWKS_UNAVAILABLE\",\n `JWKS non disponibile (HTTP ${response.status}).`,\n );\n }\n const payload: unknown = await response.json();\n if (!isRecord(payload) || !Array.isArray(payload.keys)) {\n throw accessiAuthError(503, \"AUTH_JWKS_UNAVAILABLE\", \"Risposta JWKS non valida.\");\n }\n return payload.keys.filter(isRecord);\n } catch (error) {\n if (error && typeof error === \"object\" && \"code\" in error && \"status\" in error) {\n throw error;\n }\n throw accessiAuthError(503, \"AUTH_JWKS_UNAVAILABLE\", \"JWKS non raggiungibile.\");\n } finally {\n clearTimeout(timeout);\n }\n}\n\nfunction selectJwk(\n keys: Array<Record<string, unknown>>,\n kid: string | undefined,\n algorithm: string,\n): JsonWebKey {\n const candidates = keys.filter((key) => {\n const keyAlg = typeof key.alg === \"string\" ? key.alg : undefined;\n const keyKid = typeof key.kid === \"string\" ? key.kid : undefined;\n if (keyAlg && keyAlg !== algorithm) return false;\n if (kid && keyKid && keyKid !== kid) return false;\n return true;\n });\n const selected = candidates[0];\n if (!selected) {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Chiave JWKS non trovata per il token.\");\n }\n return selected as unknown as JsonWebKey;\n}\n\n/**\n * Crea un verificatore locale riutilizzabile.\n *\n * Supporta HMAC, chiavi pubbliche PEM (RS ed ES) e JWKS remoto. La cache\n * JWKS e legata all'istanza del verificatore.\n */\nexport function createAccessiTokenVerifier(options: AccessiResourceServerJwtOptions): AccessiTokenVerifier {\n const algorithms = defaultAlgorithms(options);\n if (algorithms.length === 0) {\n throw accessiAuthError(\n 500,\n \"AUTH_CONFIG_INVALID\",\n \"Configurare almeno una tra jwt.secret, jwt.serverSecret, jwt.publicKey e jwt.jwks.\",\n );\n }\n\n const clockTolerance = options.clockToleranceSeconds ?? 5;\n const hmacSecret = options.secret\n ?? (options.serverSecret ? deriveAccessiAccessSecret(options.serverSecret) : undefined);\n let jwksCache: JwksCacheEntry | undefined;\n\n const getJwksKeys = async (): Promise<Array<Record<string, unknown>>> => {\n if (!options.jwks) return [];\n if (jwksCache && jwksCache.expiresAt > Date.now()) return jwksCache.keys;\n const keys = await fetchJwks(options.jwks);\n jwksCache = {\n keys,\n expiresAt: Date.now() + Math.max(1_000, options.jwks.cacheTtlMs ?? 300_000),\n };\n return keys;\n };\n\n const verify = async (token: string): Promise<AccessiTokenVerification> => {\n const decoded = jwt.decode(token, { complete: true });\n if (!decoded || typeof decoded === \"string\" || !isRecord(decoded.header)) {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Token JWT non valido.\");\n }\n\n const algorithm = typeof decoded.header.alg === \"string\" ? decoded.header.alg : undefined;\n if (!algorithm || !algorithms.includes(algorithm as AccessiJwtAlgorithm)) {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Algoritmo JWT non consentito.\");\n }\n\n let key: jwt.Secret;\n if (algorithmFamily(algorithm) === \"hmac\") {\n if (!hmacSecret) {\n throw accessiAuthError(\n 500,\n \"AUTH_CONFIG_INVALID\",\n \"jwt.secret o jwt.serverSecret non configurato per token HS*.\",\n );\n }\n key = hmacSecret;\n } else if (options.publicKey) {\n key = options.publicKey;\n } else if (options.jwks) {\n const keys = await getJwksKeys();\n const kid = typeof decoded.header.kid === \"string\" ? decoded.header.kid : undefined;\n key = createPublicKey({ key: selectJwk(keys, kid, algorithm), format: \"jwk\" })\n .export({ type: \"spki\", format: \"pem\" });\n } else {\n throw accessiAuthError(500, \"AUTH_CONFIG_INVALID\", \"jwt.publicKey/jwt.jwks non configurati.\");\n }\n\n let verified: unknown;\n try {\n verified = jwt.verify(token, key, {\n algorithms: [algorithm as jwt.Algorithm],\n ...(options.issuer ? { issuer: options.issuer } : {}),\n ...(options.audience\n ? { audience: options.audience as jwt.VerifyOptions[\"audience\"] }\n : {}),\n clockTolerance,\n });\n } catch {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Token non valido o scaduto.\");\n }\n\n if (!isRecord(verified)) {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Payload JWT non valido.\");\n }\n if (verified.typ !== \"access\") {\n throw accessiAuthError(401, \"AUTH_TOKEN_INVALID\", \"Il token non e un access token Accessi.\");\n }\n\n const codiceUtente = resolveCodiceUtenteFromTokenPayload(verified);\n if (!codiceUtente) {\n throw accessiAuthError(401, \"AUTH_USER_CODE_MISSING\", \"Token privo di un utente valido.\");\n }\n\n return {\n token,\n payload: verified as AccessiAccessTokenPayload,\n codiceUtente,\n user: extractUser(verified),\n };\n };\n\n return {\n verify,\n async verifyAuthorizationHeader(header: unknown): Promise<AccessiTokenVerification> {\n const token = extractAccessiBearerToken(header);\n if (!token) {\n throw accessiAuthError(401, \"AUTH_TOKEN_MISSING\", \"Token Bearer mancante o malformato.\");\n }\n return verify(token);\n },\n };\n}\n\n/** Converte un header `Authorization` in verifica del token, senza cache JWKS condivisa. */\nexport async function verifyAccessiAccessToken(\n header: unknown,\n options: AccessiResourceServerJwtOptions,\n): Promise<AccessiTokenVerification> {\n return createAccessiTokenVerifier(options).verifyAuthorizationHeader(header);\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AccessiAuthorizationOptions, AccessiGrant, GrantsResult } from "../contracts";
|
|
2
|
+
/** Algoritmi JWT supportati dal resource server. */
|
|
3
|
+
export type AccessiJwtAlgorithm = "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512";
|
|
4
|
+
/** Opzioni di verifica locale del JWT. Almeno una tra `secret`, `publicKey` e `jwks` e obbligatoria. */
|
|
5
|
+
export interface AccessiResourceServerJwtOptions {
|
|
6
|
+
/** Chiave HMAC gia derivata (access key). Alternativa a `serverSecret`. */
|
|
7
|
+
secret?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Segreto Accessi grezzo (`ACCESSI_JWT_SECRET`).
|
|
10
|
+
*
|
|
11
|
+
* Il resource server deriva automaticamente la chiave access con la stessa
|
|
12
|
+
* KDF del server: e il modo consigliato quando si condivide il segreto HS256.
|
|
13
|
+
*/
|
|
14
|
+
serverSecret?: string;
|
|
15
|
+
/** Chiave pubblica PEM per algoritmi RS ed ES. */
|
|
16
|
+
publicKey?: string | Buffer;
|
|
17
|
+
/** JWKS remoto per verificare token firmati con chiavi asimmetriche. */
|
|
18
|
+
jwks?: {
|
|
19
|
+
url: string;
|
|
20
|
+
cacheTtlMs?: number;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
};
|
|
24
|
+
/** Default: HS256 con `secret`, altrimenti RS/ES con `publicKey`/`jwks`. */
|
|
25
|
+
algorithms?: AccessiJwtAlgorithm[];
|
|
26
|
+
/** Issuer atteso (`iss`). */
|
|
27
|
+
issuer?: string;
|
|
28
|
+
/** Audience attesa (`aud`). */
|
|
29
|
+
audience?: string | string[];
|
|
30
|
+
/** Tolleranza orologio in secondi. Default: 5. */
|
|
31
|
+
clockToleranceSeconds?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Configurazione del client di introspection verso Accessi Service. */
|
|
34
|
+
export interface AccessiIntrospectionOptions {
|
|
35
|
+
/** URL completo, es. `https://accessi.example.com/api/accessi/auth/introspect`. */
|
|
36
|
+
url: string;
|
|
37
|
+
/** Service token Accessi con scope `accessi:introspect`. */
|
|
38
|
+
serviceToken: string;
|
|
39
|
+
/** TTL della cache locale dei risultati attivi. Default: 30000 ms. */
|
|
40
|
+
cacheTtlMs?: number;
|
|
41
|
+
/** Timeout HTTP. Default: 3000 ms. */
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
/** Fetch iniettabile per test o runtime non-Node. */
|
|
44
|
+
fetch?: typeof fetch;
|
|
45
|
+
}
|
|
46
|
+
/** Risultato dell'introspection. */
|
|
47
|
+
export interface AccessiIntrospectionResult {
|
|
48
|
+
active: boolean;
|
|
49
|
+
user?: Record<string, unknown>;
|
|
50
|
+
codiceUtente?: number;
|
|
51
|
+
grants?: GrantsResult;
|
|
52
|
+
}
|
|
53
|
+
/** Modalita di autenticazione del resource server. */
|
|
54
|
+
export type AccessiResourceServerMode = "local" | "introspection";
|
|
55
|
+
/**
|
|
56
|
+
* Configurazione di un backend fratello che non possiede il database Accessi.
|
|
57
|
+
*
|
|
58
|
+
* - `mode: "local"` verifica il JWT con chiave locale e, se servono grant, usa
|
|
59
|
+
* l'introspection per leggerli.
|
|
60
|
+
* - `mode: "introspection"` delega la verifica del token ad Accessi Service.
|
|
61
|
+
*/
|
|
62
|
+
export interface AccessiResourceServerOptions {
|
|
63
|
+
mode?: AccessiResourceServerMode;
|
|
64
|
+
jwt?: AccessiResourceServerJwtOptions;
|
|
65
|
+
introspection?: AccessiIntrospectionOptions;
|
|
66
|
+
/** Policy di autorizzazione opzionale applicata dopo l'autenticazione. */
|
|
67
|
+
authorization?: AccessiAuthorizationOptions;
|
|
68
|
+
}
|
|
69
|
+
/** Dati allegati alla request dopo l'autenticazione. */
|
|
70
|
+
export interface AccessiRequestContext {
|
|
71
|
+
token: string;
|
|
72
|
+
user: Record<string, unknown>;
|
|
73
|
+
codiceUtente?: number;
|
|
74
|
+
grants?: GrantsResult;
|
|
75
|
+
payload?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
/** Grant esposto per compatibilita con il middleware storico. */
|
|
78
|
+
export type AccessiRequestGrants = AccessiGrant[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/accessi/resource-server/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccessiAuthorizationOptions,\n AccessiGrant,\n GrantsResult,\n} from \"../contracts\";\n\n/** Algoritmi JWT supportati dal resource server. */\nexport type AccessiJwtAlgorithm =\n | \"HS256\"\n | \"HS384\"\n | \"HS512\"\n | \"RS256\"\n | \"RS384\"\n | \"RS512\"\n | \"ES256\"\n | \"ES384\"\n | \"ES512\";\n\n/** Opzioni di verifica locale del JWT. Almeno una tra `secret`, `publicKey` e `jwks` e obbligatoria. */\nexport interface AccessiResourceServerJwtOptions {\n /** Chiave HMAC gia derivata (access key). Alternativa a `serverSecret`. */\n secret?: string;\n /**\n * Segreto Accessi grezzo (`ACCESSI_JWT_SECRET`).\n *\n * Il resource server deriva automaticamente la chiave access con la stessa\n * KDF del server: e il modo consigliato quando si condivide il segreto HS256.\n */\n serverSecret?: string;\n /** Chiave pubblica PEM per algoritmi RS ed ES. */\n publicKey?: string | Buffer;\n /** JWKS remoto per verificare token firmati con chiavi asimmetriche. */\n jwks?: {\n url: string;\n cacheTtlMs?: number;\n timeoutMs?: number;\n fetch?: typeof fetch;\n };\n /** Default: HS256 con `secret`, altrimenti RS/ES con `publicKey`/`jwks`. */\n algorithms?: AccessiJwtAlgorithm[];\n /** Issuer atteso (`iss`). */\n issuer?: string;\n /** Audience attesa (`aud`). */\n audience?: string | string[];\n /** Tolleranza orologio in secondi. Default: 5. */\n clockToleranceSeconds?: number;\n}\n\n/** Configurazione del client di introspection verso Accessi Service. */\nexport interface AccessiIntrospectionOptions {\n /** URL completo, es. `https://accessi.example.com/api/accessi/auth/introspect`. */\n url: string;\n /** Service token Accessi con scope `accessi:introspect`. */\n serviceToken: string;\n /** TTL della cache locale dei risultati attivi. Default: 30000 ms. */\n cacheTtlMs?: number;\n /** Timeout HTTP. Default: 3000 ms. */\n timeoutMs?: number;\n /** Fetch iniettabile per test o runtime non-Node. */\n fetch?: typeof fetch;\n}\n\n/** Risultato dell'introspection. */\nexport interface AccessiIntrospectionResult {\n active: boolean;\n user?: Record<string, unknown>;\n codiceUtente?: number;\n grants?: GrantsResult;\n}\n\n/** Modalita di autenticazione del resource server. */\nexport type AccessiResourceServerMode = \"local\" | \"introspection\";\n\n/**\n * Configurazione di un backend fratello che non possiede il database Accessi.\n *\n * - `mode: \"local\"` verifica il JWT con chiave locale e, se servono grant, usa\n * l'introspection per leggerli.\n * - `mode: \"introspection\"` delega la verifica del token ad Accessi Service.\n */\nexport interface AccessiResourceServerOptions {\n mode?: AccessiResourceServerMode;\n jwt?: AccessiResourceServerJwtOptions;\n introspection?: AccessiIntrospectionOptions;\n /** Policy di autorizzazione opzionale applicata dopo l'autenticazione. */\n authorization?: AccessiAuthorizationOptions;\n}\n\n/** Dati allegati alla request dopo l'autenticazione. */\nexport interface AccessiRequestContext {\n token: string;\n user: Record<string, unknown>;\n codiceUtente?: number;\n grants?: GrantsResult;\n payload?: Record<string, unknown>;\n}\n\n/** Grant esposto per compatibilita con il middleware storico. */\nexport type AccessiRequestGrants = AccessiGrant[];\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point server Accessi.
|
|
3
|
+
*
|
|
4
|
+
* Questo e l'unico entry point che puo importare database, SMTP, migrazioni,
|
|
5
|
+
* console e servizi Nest completi. I backend fratelli devono usare
|
|
6
|
+
* `accessi/resource-server` e `accessi/client`.
|
|
7
|
+
*/
|
|
8
|
+
export * from "../../accessi-module";
|
|
9
|
+
export type { AccessiOptions as AccessiServerOptions } from "../../accessi-module";
|
|
10
|
+
export { createAccessiOptionsFromEnv, createCatalogScriptsOptionsFromEnv, } from "../../accessi-module/database-updates/accessiOptionsFromEnv";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createCatalogScriptsOptionsFromEnv = exports.createAccessiOptionsFromEnv = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Entry point server Accessi.
|
|
20
|
+
*
|
|
21
|
+
* Questo e l'unico entry point che puo importare database, SMTP, migrazioni,
|
|
22
|
+
* console e servizi Nest completi. I backend fratelli devono usare
|
|
23
|
+
* `accessi/resource-server` e `accessi/client`.
|
|
24
|
+
*/
|
|
25
|
+
__exportStar(require("../../accessi-module"), exports);
|
|
26
|
+
var accessiOptionsFromEnv_1 = require("../../accessi-module/database-updates/accessiOptionsFromEnv");
|
|
27
|
+
Object.defineProperty(exports, "createAccessiOptionsFromEnv", { enumerable: true, get: function () { return accessiOptionsFromEnv_1.createAccessiOptionsFromEnv; } });
|
|
28
|
+
Object.defineProperty(exports, "createCatalogScriptsOptionsFromEnv", { enumerable: true, get: function () { return accessiOptionsFromEnv_1.createCatalogScriptsOptionsFromEnv; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/accessi/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,uDAAqC;AAErC,qGAGqE;AAFnE,oIAAA,2BAA2B,OAAA;AAC3B,2IAAA,kCAAkC,OAAA","sourcesContent":["/**\n * Entry point server Accessi.\n *\n * Questo e l'unico entry point che puo importare database, SMTP, migrazioni,\n * console e servizi Nest completi. I backend fratelli devono usare\n * `accessi/resource-server` e `accessi/client`.\n */\nexport * from \"../../accessi-module\";\nexport type { AccessiOptions as AccessiServerOptions } from \"../../accessi-module\";\nexport {\n createAccessiOptionsFromEnv,\n createCatalogScriptsOptionsFromEnv,\n} from \"../../accessi-module/database-updates/accessiOptionsFromEnv\";\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset UI frameworkless pubblicati con il pacchetto.
|
|
3
|
+
*
|
|
4
|
+
* I componenti sono Web Components senza dipendenze runtime: vanno inclusi
|
|
5
|
+
* come `<script>` o copiati nel build dell'app. I percorsi sono relativi alla
|
|
6
|
+
* root del pacchetto distribuito (`dist/`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const ACCESSI_UI_ASSETS: {
|
|
9
|
+
readonly areeDisponibili: "angular-components/aree-disponibili/aree-disponibili.js";
|
|
10
|
+
};
|
|
11
|
+
export type AccessiUiComponent = keyof typeof ACCESSI_UI_ASSETS;
|
|
12
|
+
/** Restituisce il path dell'asset UI relativo a `dist/`. */
|
|
13
|
+
export declare function getAccessiUiAssetPath(component: AccessiUiComponent): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACCESSI_UI_ASSETS = void 0;
|
|
4
|
+
exports.getAccessiUiAssetPath = getAccessiUiAssetPath;
|
|
5
|
+
/**
|
|
6
|
+
* Asset UI frameworkless pubblicati con il pacchetto.
|
|
7
|
+
*
|
|
8
|
+
* I componenti sono Web Components senza dipendenze runtime: vanno inclusi
|
|
9
|
+
* come `<script>` o copiati nel build dell'app. I percorsi sono relativi alla
|
|
10
|
+
* root del pacchetto distribuito (`dist/`).
|
|
11
|
+
*/
|
|
12
|
+
exports.ACCESSI_UI_ASSETS = {
|
|
13
|
+
areeDisponibili: "angular-components/aree-disponibili/aree-disponibili.js",
|
|
14
|
+
};
|
|
15
|
+
/** Restituisce il path dell'asset UI relativo a `dist/`. */
|
|
16
|
+
function getAccessiUiAssetPath(component) {
|
|
17
|
+
return exports.ACCESSI_UI_ASSETS[component];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/accessi/ui/index.ts"],"names":[],"mappings":";;;AAcA,sDAEC;AAhBD;;;;;;GAMG;AACU,QAAA,iBAAiB,GAAG;IAC/B,eAAe,EAAE,yDAAyD;CAClE,CAAC;AAIX,4DAA4D;AAC5D,SAAgB,qBAAqB,CAAC,SAA6B;IACjE,OAAO,yBAAiB,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\n * Asset UI frameworkless pubblicati con il pacchetto.\n *\n * I componenti sono Web Components senza dipendenze runtime: vanno inclusi\n * come `<script>` o copiati nel build dell'app. I percorsi sono relativi alla\n * root del pacchetto distribuito (`dist/`).\n */\nexport const ACCESSI_UI_ASSETS = {\n areeDisponibili: \"angular-components/aree-disponibili/aree-disponibili.js\",\n} as const;\n\nexport type AccessiUiComponent = keyof typeof ACCESSI_UI_ASSETS;\n\n/** Restituisce il path dell'asset UI relativo a `dist/`. */\nexport function getAccessiUiAssetPath(component: AccessiUiComponent): string {\n return ACCESSI_UI_ASSETS[component];\n}\n"]}
|
|
@@ -6,13 +6,46 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Options } from 'node-firebird';
|
|
8
8
|
import { DynamicModule } from '@nestjs/common';
|
|
9
|
+
import type { LoggerService } from '@nestjs/common';
|
|
10
|
+
import type { OpenApiSetupOptions } from '../openapi/OpenApiConfig';
|
|
11
|
+
import type { AccessiAccessTokenAlgorithm } from './security/jwtTokenOptions';
|
|
12
|
+
import type { ConsoleEntryStore } from './security/consoleEntry';
|
|
13
|
+
import type { RateLimitStore } from './security/rateLimitStore';
|
|
14
|
+
import type { AccessiEdgeRateLimitOptions } from './security/edgeRateLimit';
|
|
9
15
|
/** JWT emesso da Accessi dopo un login locale o SSO. Non riutilizzare il segreto del provider SSO. */
|
|
10
16
|
export interface JwtOptions {
|
|
11
17
|
/** Segreto simmetrico per firmare e verificare i JWT Accessi; deve essere unico per ambiente. */
|
|
12
18
|
secret: string;
|
|
19
|
+
/** Issuer (`iss`) opzionale degli access token. Consigliato in una topologia multi-servizio. */
|
|
20
|
+
issuer?: string;
|
|
21
|
+
/** Audience (`aud`) opzionale degli access token. */
|
|
22
|
+
audience?: string | string[];
|
|
23
|
+
/** Algoritmo degli access token. Default `HS256` per retrocompatibilita. */
|
|
24
|
+
algorithm?: AccessiAccessTokenAlgorithm;
|
|
25
|
+
/** Chiave privata PEM per RS/ES. Obbligatoria quando `algorithm` non e HS*. */
|
|
26
|
+
privateKey?: string;
|
|
27
|
+
/** Chiave pubblica PEM per la verifica RS/ES. */
|
|
28
|
+
publicKey?: string;
|
|
29
|
+
/** Key id pubblicato nella JWKS, per rotazione chiavi. */
|
|
30
|
+
keyId?: string;
|
|
31
|
+
/** Path pubblico della JWKS. Default `accessi/.well-known/jwks.json` con algoritmi asimmetrici. */
|
|
32
|
+
jwksPath?: string;
|
|
33
|
+
/** Chiavi pubbliche precedenti, esposte in JWKS durante la rotazione. */
|
|
34
|
+
previousPublicKeys?: Array<{
|
|
35
|
+
publicKey: string;
|
|
36
|
+
keyId: string;
|
|
37
|
+
algorithm?: AccessiAccessTokenAlgorithm;
|
|
38
|
+
}>;
|
|
13
39
|
/** Durata compatibile con `jsonwebtoken`, per esempio `24h` o `3600s`. */
|
|
14
40
|
expiresIn: string;
|
|
15
41
|
}
|
|
42
|
+
/** Configurazione dei ticket di ingresso alla console. */
|
|
43
|
+
export interface ConsoleEntryOptions {
|
|
44
|
+
/** Durata del ticket in millisecondi. Default 60000. */
|
|
45
|
+
ttlMs?: number;
|
|
46
|
+
/** Store condiviso (es. Redis) per deployment multi-istanza. Default: memoria. */
|
|
47
|
+
store?: ConsoleEntryStore;
|
|
48
|
+
}
|
|
16
49
|
/** Parametri SMTP usati esclusivamente per impostazione e reset della password. */
|
|
17
50
|
export interface EmailOptions {
|
|
18
51
|
host: string;
|
|
@@ -46,9 +79,11 @@ export interface PublicAuthRateLimitRuleOptions {
|
|
|
46
79
|
windowMs: number;
|
|
47
80
|
maxAttempts: number;
|
|
48
81
|
}
|
|
49
|
-
/** Protezione
|
|
82
|
+
/** Protezione degli endpoint pubblici. Default in memoria; in cluster usare uno store condiviso. */
|
|
50
83
|
export interface PublicAuthRateLimitOptions {
|
|
51
84
|
enabled?: boolean;
|
|
85
|
+
/** Store condiviso (es. Redis). Default: memoria del processo. */
|
|
86
|
+
store?: RateLimitStore;
|
|
52
87
|
login?: PublicAuthRateLimitRuleOptions;
|
|
53
88
|
register?: PublicAuthRateLimitRuleOptions;
|
|
54
89
|
passwordResetEmail?: PublicAuthRateLimitRuleOptions;
|
|
@@ -81,6 +116,8 @@ export interface ServiceTokenOptions {
|
|
|
81
116
|
enabled?: boolean;
|
|
82
117
|
/** Durata predefinita in giorni quando non e indicata una scadenza esplicita. Default: nessuna scadenza. */
|
|
83
118
|
defaultTtlDays?: number;
|
|
119
|
+
/** Store condiviso per il rate limit dei service token. Default: memoria. */
|
|
120
|
+
rateLimitStore?: RateLimitStore;
|
|
84
121
|
}
|
|
85
122
|
/** Cosa fare quando uno script gia applicato presenta un checksum diverso (file modificato). */
|
|
86
123
|
export type CatalogScriptChecksumPolicy = 'error' | 'warn' | 'reapply';
|
|
@@ -178,8 +215,21 @@ export interface AccessiOptions {
|
|
|
178
215
|
systemSeeds?: SystemSeedsOptions;
|
|
179
216
|
/** Bootstrap del primo admin tramite token casuale stampato a ogni avvio. */
|
|
180
217
|
adminBootstrap?: AdminBootstrapOptions;
|
|
181
|
-
/** Base URL pubblica usata solo per loggare gli indirizzi (console,
|
|
218
|
+
/** Base URL pubblica usata solo per loggare gli indirizzi (console, OpenAPI, API). */
|
|
182
219
|
publicBaseUrl?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Documentazione OpenAPI del modulo. Default invariati:
|
|
222
|
+
* UI `accessi/openapi`, JSON `accessi/openapi.json`.
|
|
223
|
+
*/
|
|
224
|
+
openapi?: OpenApiSetupOptions;
|
|
225
|
+
/** Logger Nest usato dal sotto-app Accessi. Se assente Nest usa il proprio logger. */
|
|
226
|
+
logger?: LoggerService;
|
|
227
|
+
/** Buffer dei log di bootstrap del sotto-app. Default `true` (comportamento storico). */
|
|
228
|
+
bufferLogs?: boolean;
|
|
229
|
+
/** Ticket di ingresso console: TTL e store condiviso per deployment multi-istanza. */
|
|
230
|
+
consoleEntry?: ConsoleEntryOptions;
|
|
231
|
+
/** Limite grossolano per IP davanti alle rotte Accessi. Opzionale. */
|
|
232
|
+
edgeRateLimit?: AccessiEdgeRateLimitOptions;
|
|
183
233
|
}
|
|
184
234
|
export declare class AccessiModule {
|
|
185
235
|
/**
|
|
@@ -33,6 +33,7 @@ const ServiceTokenController_1 = require("./Controllers/ServiceTokenController")
|
|
|
33
33
|
const ServiceTokenService_1 = require("./Services/ServiceTokenService/ServiceTokenService");
|
|
34
34
|
const serviceTokenGuard_1 = require("./security/serviceTokenGuard");
|
|
35
35
|
const SchemaController_1 = require("./Controllers/SchemaController");
|
|
36
|
+
const AccessiIntrospectionController_1 = require("./Controllers/AccessiIntrospectionController");
|
|
36
37
|
const SchemaExportService_1 = require("./Services/SchemaExportService/SchemaExportService");
|
|
37
38
|
const AdminBootstrapService_1 = require("./Services/AdminBootstrapService/AdminBootstrapService");
|
|
38
39
|
const emailConfiguration_1 = require("./security/emailConfiguration");
|
|
@@ -101,6 +102,7 @@ exports.AccessiModule = AccessiModule = AccessiModule_1 = __decorate([
|
|
|
101
102
|
ConsoleEntryController_1.ConsoleEntryController,
|
|
102
103
|
ServiceTokenController_1.ServiceTokenController,
|
|
103
104
|
SchemaController_1.SchemaController,
|
|
105
|
+
AccessiIntrospectionController_1.AccessiIntrospectionController,
|
|
104
106
|
],
|
|
105
107
|
providers: [AuthService_1.AuthService, TwoFactorService_1.TwoFactorService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService, ConfiguratorService_1.ConfiguratorService, jwt_strategy_1.JwtSimpleGuard, authenticateGen_1.AuthenticateGenService, AccessiDatabaseUpdater_1.AccessiDatabaseUpdater, FederatedAuthService_1.FederatedAuthService, ServiceTokenService_1.ServiceTokenService, serviceTokenGuard_1.ServiceTokenGuard, SchemaExportService_1.SchemaExportService, AdminBootstrapService_1.AdminBootstrapService],
|
|
106
108
|
exports: [AuthService_1.AuthService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService, ConfiguratorService_1.ConfiguratorService, jwt_strategy_1.JwtSimpleGuard, authenticateGen_1.AuthenticateGenService, FederatedAuthService_1.FederatedAuthService, ServiceTokenService_1.ServiceTokenService, serviceTokenGuard_1.ServiceTokenGuard, SchemaExportService_1.SchemaExportService, AdminBootstrapService_1.AdminBootstrapService],
|