@jmlq/auth-plugin-jose 0.0.1-alpha.6 → 0.0.1-alpha.7
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/application/factories/create-jose-token-service.d.ts +5 -7
- package/dist/application/factories/create-jose-token-service.js +12 -17
- package/dist/application/factories/index.js +0 -1
- package/dist/application/factories/internal/assert.js +0 -1
- package/dist/application/factories/internal/index.d.ts +0 -2
- package/dist/application/factories/internal/index.js +0 -3
- package/dist/application/factories/internal/validate-key-material.d.ts +1 -1
- package/dist/application/factories/internal/validate-key-material.js +6 -7
- package/dist/application/types/index.js +0 -1
- package/dist/application/types/jose-token-service-options.type.d.ts +0 -1
- package/dist/index.js +2 -3
- package/dist/infrastructure/mappers/index.js +0 -1
- package/dist/infrastructure/mappers/jose-error.mapper.d.ts +1 -13
- package/dist/infrastructure/mappers/jose-error.mapper.js +55 -178
- package/dist/infrastructure/mappers/types/index.js +0 -1
- package/dist/infrastructure/mappers/types/jose-error-context.type.d.ts +3 -6
- package/dist/infrastructure/mappers/types/jose-error-context.type.js +0 -1
- package/dist/infrastructure/mappers/types/mapped-auth-error.type.d.ts +2 -1
- package/dist/infrastructure/mappers/types/mapped-auth-error.type.js +0 -1
- package/dist/infrastructure/mappers/types/token-kind.type.js +0 -1
- package/dist/infrastructure/mappers/types/token-operation.type.js +0 -1
- package/dist/infrastructure/services/index.js +0 -1
- package/dist/infrastructure/services/internal/build-jose-ctx.d.ts +0 -1
- package/dist/infrastructure/services/internal/build-jose-ctx.js +0 -3
- package/dist/infrastructure/services/internal/index.d.ts +0 -8
- package/dist/infrastructure/services/internal/index.js +0 -9
- package/dist/infrastructure/services/internal/jwt-expiration-reader.js +2 -2
- package/dist/infrastructure/services/internal/normalize-key-material.js +5 -6
- package/dist/infrastructure/services/jose-token.service.d.ts +8 -30
- package/dist/infrastructure/services/jose-token.service.js +55 -68
- package/dist/infrastructure/services/types/create-auth-error-fn.type.d.ts +10 -3
- package/dist/infrastructure/services/types/create-auth-error-fn.type.js +1 -0
- package/package.json +4 -4
- package/dist/application/factories/internal/normalize-clock-skew-seconds.d.ts +0 -7
- package/dist/application/factories/internal/normalize-clock-skew-seconds.js +0 -17
- package/dist/application/factories/internal/normalize-default-expires-in.d.ts +0 -6
- package/dist/application/factories/internal/normalize-default-expires-in.js +0 -24
- package/dist/infrastructure/services/internal/create-jti.d.ts +0 -6
- package/dist/infrastructure/services/internal/create-jti.js +0 -31
- package/dist/infrastructure/services/internal/is-retryable-mapped-code.d.ts +0 -9
- package/dist/infrastructure/services/internal/is-retryable-mapped-code.js +0 -17
- package/dist/infrastructure/services/internal/normalize-jwt-payload.d.ts +0 -9
- package/dist/infrastructure/services/internal/normalize-jwt-payload.js +0 -59
- package/dist/infrastructure/services/internal/read-custom-claims.d.ts +0 -5
- package/dist/infrastructure/services/internal/read-custom-claims.js +0 -18
- package/dist/infrastructure/services/internal/read-expires-in.d.ts +0 -5
- package/dist/infrastructure/services/internal/read-expires-in.js +0 -16
- package/dist/infrastructure/services/internal/read-session-id.d.ts +0 -5
- package/dist/infrastructure/services/internal/read-session-id.js +0 -19
- package/dist/infrastructure/services/internal/resolve-expires-in.d.ts +0 -11
- package/dist/infrastructure/services/internal/resolve-expires-in.js +0 -24
- package/dist/infrastructure/services/internal/to-date-from-unix-seconds.d.ts +0 -7
- package/dist/infrastructure/services/internal/to-date-from-unix-seconds.js +0 -13
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.js +0 -17
- package/dist/shared/internal/index.d.ts +0 -1
- package/dist/shared/internal/index.js +0 -17
- package/dist/shared/internal/normalize-audience.d.ts +0 -39
- package/dist/shared/internal/normalize-audience.js +0 -79
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ITokenServicePort } from "@jmlq/auth";
|
|
2
2
|
import type { CreateAuthErrorFn } from "../../infrastructure/services/types";
|
|
3
3
|
import { JoseTokenServiceOptions } from "../types";
|
|
4
4
|
/**
|
|
5
5
|
* Factory para construir un `ITokenServicePort` basado en `jose`.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @returns Instancia que cumple `ITokenServicePort`.
|
|
7
|
+
* Clean Architecture (decisión del proyecto):
|
|
8
|
+
* - Esta capa NO debe usar helpers del core (@jmlq/auth) (estandarización).
|
|
9
|
+
* - La normalización estándar se hace en infraestructura (JoseTokenService),
|
|
10
|
+
* usando utilidades compartidas del core.
|
|
13
11
|
*/
|
|
14
12
|
export declare function createJoseTokenService(options: JoseTokenServiceOptions, deps: {
|
|
15
13
|
createAuthError: CreateAuthErrorFn;
|
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//src/application/factories/create-jose-token-service.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.createJoseTokenService = createJoseTokenService;
|
|
4
|
+
const auth_1 = require("@jmlq/auth");
|
|
5
5
|
const services_1 = require("../../infrastructure/services");
|
|
6
6
|
const internal_1 = require("./internal");
|
|
7
7
|
const types_1 = require("../types");
|
|
8
|
-
const internal_2 = require("../../shared/internal");
|
|
9
8
|
/**
|
|
10
9
|
* Factory para construir un `ITokenServicePort` basado en `jose`.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @returns Instancia que cumple `ITokenServicePort`.
|
|
11
|
+
* Clean Architecture (decisión del proyecto):
|
|
12
|
+
* - Esta capa NO debe usar helpers del core (@jmlq/auth) (estandarización).
|
|
13
|
+
* - La normalización estándar se hace en infraestructura (JoseTokenService),
|
|
14
|
+
* usando utilidades compartidas del core.
|
|
18
15
|
*/
|
|
19
16
|
function createJoseTokenService(options, deps) {
|
|
20
|
-
// 1) Validaciones de shape/config mínima
|
|
21
17
|
(0, internal_1.assert)(options, "JoseTokenServiceOptions is required");
|
|
22
18
|
(0, internal_1.assert)(deps?.createAuthError, "createAuthError dependency is required");
|
|
23
|
-
// 2) Validación/normalización de key material
|
|
24
19
|
const keyMaterial = (0, internal_1.validateKeyMaterial)(options.keyMaterial);
|
|
25
|
-
//
|
|
26
|
-
const issuer = (0,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
// Normalización mínima local (string trim -> undefined) OK en application
|
|
21
|
+
const issuer = (0, auth_1.readNonEmptyString)(options.issuer);
|
|
22
|
+
// IMPORTANTE:
|
|
23
|
+
// - clockSkewSeconds y defaultExpiresIn se delegan a infraestructura para
|
|
24
|
+
// aplicar normalización estándar desde @jmlq/auth.
|
|
25
|
+
const clockSkewSeconds = options.clockSkewSeconds;
|
|
26
|
+
const defaultExpiresIn = options.defaultExpiresIn;
|
|
31
27
|
return new services_1.JoseTokenService({
|
|
32
28
|
options: {
|
|
33
29
|
keyMaterial,
|
|
34
30
|
issuer,
|
|
35
|
-
audience,
|
|
36
31
|
clockSkewSeconds,
|
|
37
32
|
defaultExpiresIn,
|
|
38
33
|
getExpirationPolicy: types_1.DEFAULT_GET_EXPIRATION_POLICY,
|
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//src/application/factories/index.ts
|
|
18
17
|
__exportStar(require("./create-jose-token-service"), exports);
|
|
@@ -14,8 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// src/application/factories/internal/index.ts
|
|
18
17
|
__exportStar(require("./assert"), exports);
|
|
19
|
-
__exportStar(require("./normalize-clock-skew-seconds"), exports);
|
|
20
|
-
__exportStar(require("./normalize-default-expires-in"), exports);
|
|
21
18
|
__exportStar(require("./validate-key-material"), exports);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/application/factories/internal/validate-key-material.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.validateKeyMaterial = validateKeyMaterial;
|
|
5
|
-
const
|
|
4
|
+
const auth_1 = require("@jmlq/auth");
|
|
6
5
|
const assert_1 = require("./assert");
|
|
7
6
|
/**
|
|
8
7
|
* Valida y normaliza el key material requerido por el plugin.
|
|
@@ -15,14 +14,14 @@ const assert_1 = require("./assert");
|
|
|
15
14
|
function validateKeyMaterial(value) {
|
|
16
15
|
(0, assert_1.assert)(value, "keyMaterial is required");
|
|
17
16
|
// Normaliza alg (si viene con espacios, evitamos falsos negativos)
|
|
18
|
-
const alg = (0,
|
|
17
|
+
const alg = (0, auth_1.readNonEmptyString)(value.alg);
|
|
19
18
|
(0, assert_1.assert)(alg, "keyMaterial.alg is required");
|
|
20
19
|
// Normaliza campos potenciales
|
|
21
|
-
const secret = (0,
|
|
22
|
-
const privateKey = (0,
|
|
20
|
+
const secret = (0, auth_1.readNonEmptyString)("secret" in value ? value.secret : undefined);
|
|
21
|
+
const privateKey = (0, auth_1.readNonEmptyString)("privateKey" in value
|
|
23
22
|
? value.privateKey
|
|
24
23
|
: undefined);
|
|
25
|
-
const publicKey = (0,
|
|
24
|
+
const publicKey = (0, auth_1.readNonEmptyString)("publicKey" in value
|
|
26
25
|
? value.publicKey
|
|
27
26
|
: undefined);
|
|
28
27
|
// Validación por algoritmo
|
|
@@ -33,7 +32,7 @@ function validateKeyMaterial(value) {
|
|
|
33
32
|
secret,
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
|
-
// RS256 / ES256
|
|
35
|
+
// RS256 / ES256
|
|
37
36
|
(0, assert_1.assert)(privateKey, "keyMaterial.privateKey is required for RS256/ES256");
|
|
38
37
|
(0, assert_1.assert)(publicKey, "keyMaterial.publicKey is required for RS256/ES256");
|
|
39
38
|
return {
|
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.DEFAULT_GET_EXPIRATION_POLICY = void 0;
|
|
18
|
-
//src/application/types/index.ts
|
|
19
18
|
__exportStar(require("./jose-token-service-options.type"), exports);
|
|
20
19
|
__exportStar(require("./jose-key-material.type"), exports);
|
|
21
20
|
__exportStar(require("./default-expires-in.type"), exports);
|
|
@@ -8,7 +8,6 @@ import type { GetExpirationPolicy } from "./get-expiration-policy.type";
|
|
|
8
8
|
export interface JoseTokenServiceOptions {
|
|
9
9
|
keyMaterial: JoseKeyMaterial;
|
|
10
10
|
issuer?: string;
|
|
11
|
-
audience?: string | string[];
|
|
12
11
|
/**
|
|
13
12
|
* Clock skew en segundos para validaciones temporales (iat/nbf/exp).
|
|
14
13
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/index.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createJoseTokenService = void 0;
|
|
5
2
|
/**
|
|
6
3
|
* Public API del plugin `@jmlq/auth-plugin-jose`.
|
|
7
4
|
*
|
|
@@ -10,5 +7,7 @@ exports.createJoseTokenService = void 0;
|
|
|
10
7
|
* desde una configuración neutral.
|
|
11
8
|
* - Exportar SOLO lo necesario (y exportar types con `export type`).
|
|
12
9
|
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createJoseTokenService = void 0;
|
|
13
12
|
var create_jose_token_service_1 = require("./application/factories/create-jose-token-service");
|
|
14
13
|
Object.defineProperty(exports, "createJoseTokenService", { enumerable: true, get: function () { return create_jose_token_service_1.createJoseTokenService; } });
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//src/infrastructure/mappers/index.ts
|
|
18
17
|
__exportStar(require("./jose-error.mapper"), exports);
|
|
19
18
|
__exportStar(require("./types"), exports);
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { JoseErrorContext, MappedAuthError } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Mapea un error técnico a un código estable del core.
|
|
4
|
-
*
|
|
5
|
-
* Estrategia conservadora:
|
|
6
|
-
* - Mapeo por `err.name` (más estable en `jose`)
|
|
7
|
-
* - Heurísticas por `message` como fallback
|
|
8
|
-
* - Catch-all: JWT_ERROR
|
|
9
|
-
*/
|
|
1
|
+
import type { JoseErrorContext, MappedAuthError } from "./types";
|
|
10
2
|
export declare function mapJoseErrorToAuthError(err: unknown, ctx: JoseErrorContext): MappedAuthError;
|
|
11
|
-
/**
|
|
12
|
-
* Convierte un error técnico a un Error del core (AuthDomainError u otro),
|
|
13
|
-
* sin acoplar el plugin a una implementación concreta.
|
|
14
|
-
*/
|
|
15
3
|
export declare function toAuthDomainError<TAuthError extends Error>(createAuthError: (args: {
|
|
16
4
|
code: MappedAuthError["code"];
|
|
17
5
|
message: string;
|
|
@@ -3,211 +3,88 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.mapJoseErrorToAuthError = mapJoseErrorToAuthError;
|
|
5
5
|
exports.toAuthDomainError = toAuthDomainError;
|
|
6
|
+
const auth_1 = require("@jmlq/auth");
|
|
6
7
|
/**
|
|
7
8
|
* Mapper de errores de `jose` → error “entendible” por el core (@jmlq/auth).
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* - Incluye `meta` mínima para troubleshooting (issuer/audience/alg/operación).
|
|
13
|
-
*
|
|
14
|
-
* Objetivo:
|
|
15
|
-
* Evitar acoplamiento de la aplicación al detalle de `jose`.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Extrae el "name" del error de forma segura.
|
|
19
|
-
* En `jose` el `name` suele identificar clases como JWTExpired, JWTInvalid, etc.
|
|
20
|
-
*/
|
|
21
|
-
function getErrorName(err) {
|
|
22
|
-
if (err &&
|
|
23
|
-
typeof err === "object" &&
|
|
24
|
-
"name" in err &&
|
|
25
|
-
typeof err.name === "string") {
|
|
26
|
-
return err.name;
|
|
27
|
-
}
|
|
28
|
-
return "UnknownError";
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Extrae el "message" del error de forma segura.
|
|
10
|
+
* - No usa heurísticas por message.
|
|
11
|
+
* - Mapea por err.name (estable).
|
|
12
|
+
* - Meta mínima (sin audience).
|
|
32
13
|
*/
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
typeof err === "object" &&
|
|
39
|
-
"message" in err &&
|
|
40
|
-
typeof err.message === "string") {
|
|
41
|
-
return err.message;
|
|
42
|
-
}
|
|
43
|
-
return "Unexpected token error";
|
|
14
|
+
function hasStringProp(err, prop) {
|
|
15
|
+
if (!err || typeof err !== "object")
|
|
16
|
+
return false;
|
|
17
|
+
const rec = err;
|
|
18
|
+
return typeof rec[prop] === "string";
|
|
44
19
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* (no provienen de `jose`, sino de validaciones internas).
|
|
48
|
-
*
|
|
49
|
-
* Se usa un set explícito para:
|
|
50
|
-
* - evitar regex frágiles
|
|
51
|
-
* - facilitar mantenimiento
|
|
52
|
-
* - mantenerlo determinista
|
|
53
|
-
*/
|
|
54
|
-
function isInvalidPayloadShapeMessage(lowerMsg) {
|
|
55
|
-
const msg = lowerMsg.trim();
|
|
56
|
-
const known = new Set([
|
|
57
|
-
"sid is required",
|
|
58
|
-
"sub is required",
|
|
59
|
-
"jti is required",
|
|
60
|
-
"iat must be a number",
|
|
61
|
-
"exp must be a number",
|
|
62
|
-
]);
|
|
63
|
-
return known.has(msg);
|
|
20
|
+
function getErrorName(err) {
|
|
21
|
+
return hasStringProp(err, "name") ? err.name : "UnknownError";
|
|
64
22
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Construye metadatos mínimos para debugging.
|
|
67
|
-
* Importante: no se incluyen tokens ni claves.
|
|
68
|
-
*/
|
|
69
23
|
function buildSafeMeta(joseErrorName, ctx) {
|
|
70
24
|
return {
|
|
71
25
|
joseErrorName,
|
|
72
26
|
operation: ctx.operation,
|
|
73
27
|
tokenKind: ctx.tokenKind ?? "unknown",
|
|
74
28
|
issuer: ctx.issuer,
|
|
75
|
-
audience: ctx.audience,
|
|
76
29
|
alg: ctx.alg,
|
|
77
30
|
};
|
|
78
31
|
}
|
|
32
|
+
const JOSE_NAME_TO_AUTH_CODE = {
|
|
33
|
+
JWTExpired: "TOKEN_EXPIRED",
|
|
34
|
+
JWTNotBefore: "TOKEN_NOT_YET_VALID",
|
|
35
|
+
JWTNotYetValid: "TOKEN_NOT_YET_VALID",
|
|
36
|
+
JWSSignatureVerificationFailed: "SIGNATURE_INVALID",
|
|
37
|
+
JWSInvalid: "SIGNATURE_INVALID",
|
|
38
|
+
JWSError: "SIGNATURE_INVALID",
|
|
39
|
+
JWTClaimValidationFailed: "CLAIMS_VALIDATION_ERROR",
|
|
40
|
+
JWTInvalid: "TOKEN_INVALID",
|
|
41
|
+
JWTMalformed: "TOKEN_MALFORMED",
|
|
42
|
+
JWSMalformed: "TOKEN_MALFORMED",
|
|
43
|
+
JOSEError: "TOKEN_MALFORMED",
|
|
44
|
+
JOSENotSupported: "ALGORITHM_UNSUPPORTED",
|
|
45
|
+
JWTAlgorithmNotAllowed: "ALGORITHM_UNSUPPORTED",
|
|
46
|
+
JWKInvalid: "KEY_MISMATCH",
|
|
47
|
+
JWKInvalidFormat: "KEY_MISMATCH",
|
|
48
|
+
};
|
|
79
49
|
/**
|
|
80
|
-
*
|
|
50
|
+
* Mensajes técnicos estables por código.
|
|
81
51
|
*
|
|
82
|
-
*
|
|
83
|
-
* -
|
|
84
|
-
* -
|
|
85
|
-
* - Catch-all: JWT_ERROR
|
|
52
|
+
* Importante:
|
|
53
|
+
* - Este mapper SOLO usa códigos de JWT/keys.
|
|
54
|
+
* - Por eso es Partial<Record<AuthErrorCode, string>> + fallback.
|
|
86
55
|
*/
|
|
56
|
+
const AUTH_CODE_TO_MESSAGE = {
|
|
57
|
+
TOKEN_INVALID: "Token is invalid",
|
|
58
|
+
TOKEN_EXPIRED: "Token has expired",
|
|
59
|
+
TOKEN_MALFORMED: "Token is malformed",
|
|
60
|
+
SIGNATURE_INVALID: "Token signature is invalid",
|
|
61
|
+
CLAIMS_VALIDATION_ERROR: "Token claims validation failed",
|
|
62
|
+
TOKEN_NOT_YET_VALID: "Token is not yet valid",
|
|
63
|
+
ALGORITHM_UNSUPPORTED: "Token algorithm is not supported",
|
|
64
|
+
KEY_MISMATCH: "Key material is invalid or does not match the algorithm",
|
|
65
|
+
KEY_NOT_FOUND: "Key not found for token verification",
|
|
66
|
+
JWT_ERROR: "JWT operation failed",
|
|
67
|
+
AUTHENTICATION_FAILED: "Authentication failed",
|
|
68
|
+
JWT_PAYLOAD_INVALID: "Invalid JWT payload",
|
|
69
|
+
};
|
|
87
70
|
function mapJoseErrorToAuthError(err, ctx) {
|
|
88
71
|
const name = getErrorName(err);
|
|
89
|
-
const msg = getErrorMessage(err);
|
|
90
72
|
const meta = buildSafeMeta(name, ctx);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (isInvalidPayloadShapeMessage(lowerMsg)) {
|
|
96
|
-
return {
|
|
97
|
-
code: "TOKEN_INVALID",
|
|
98
|
-
message: "Token is invalid",
|
|
99
|
-
meta: { ...meta, reason: msg },
|
|
100
|
-
cause: err,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
// Mapeos preferentes por "name"
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
if (name === "JWTExpired") {
|
|
107
|
-
return {
|
|
108
|
-
code: "TOKEN_EXPIRED",
|
|
109
|
-
message: "Token has expired",
|
|
110
|
-
meta,
|
|
111
|
-
cause: err,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
if (name === "JWTNotBefore" || name === "JWTNotYetValid") {
|
|
115
|
-
return {
|
|
116
|
-
code: "TOKEN_NOT_YET_VALID",
|
|
117
|
-
message: "Token is not yet valid",
|
|
118
|
-
meta,
|
|
119
|
-
cause: err,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
if (name === "JWSSignatureVerificationFailed" ||
|
|
123
|
-
name === "JWSInvalid" ||
|
|
124
|
-
name === "JWSError") {
|
|
125
|
-
return {
|
|
126
|
-
code: "SIGNATURE_INVALID",
|
|
127
|
-
message: "Token signature is invalid",
|
|
128
|
-
meta,
|
|
129
|
-
cause: err,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
if (name === "JWTClaimValidationFailed") {
|
|
133
|
-
return {
|
|
134
|
-
code: "CLAIMS_VALIDATION_ERROR",
|
|
135
|
-
message: "Token claims validation failed",
|
|
136
|
-
meta,
|
|
137
|
-
cause: err,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
if (name === "JWTInvalid") {
|
|
141
|
-
return {
|
|
142
|
-
code: "TOKEN_INVALID",
|
|
143
|
-
message: "Token is invalid",
|
|
144
|
-
meta,
|
|
145
|
-
cause: err,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (name === "JWTMalformed" ||
|
|
149
|
-
name === "JWSMalformed" ||
|
|
150
|
-
name === "JOSEError") {
|
|
151
|
-
return {
|
|
152
|
-
code: "TOKEN_MALFORMED",
|
|
153
|
-
message: "Token is malformed",
|
|
154
|
-
meta,
|
|
155
|
-
cause: err,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (name === "JOSENotSupported" || name === "JWTAlgorithmNotAllowed") {
|
|
159
|
-
return {
|
|
160
|
-
code: "ALGORITHM_UNSUPPORTED",
|
|
161
|
-
message: "Token algorithm is not supported",
|
|
162
|
-
meta,
|
|
163
|
-
cause: err,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (name === "JWKInvalid" || name === "JWKInvalidFormat") {
|
|
167
|
-
return {
|
|
168
|
-
code: "KEY_MISMATCH",
|
|
169
|
-
message: "Key material is invalid or does not match the algorithm",
|
|
170
|
-
meta,
|
|
171
|
-
cause: err,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// ---------------------------------------------------------------------------
|
|
175
|
-
// Fallbacks por mensaje (heurísticas conservadoras)
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
const lower = lowerMsg;
|
|
178
|
-
if (lower.includes("key") &&
|
|
179
|
-
(lower.includes("not found") || lower.includes("missing"))) {
|
|
180
|
-
return {
|
|
181
|
-
code: "KEY_NOT_FOUND",
|
|
182
|
-
message: "Key not found for token verification",
|
|
183
|
-
meta,
|
|
184
|
-
cause: err,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
if (lower.includes("key") &&
|
|
188
|
-
(lower.includes("mismatch") || lower.includes("invalid"))) {
|
|
189
|
-
return {
|
|
190
|
-
code: "KEY_MISMATCH",
|
|
191
|
-
message: "Key does not match token requirements",
|
|
192
|
-
meta,
|
|
193
|
-
cause: err,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
// ---------------------------------------------------------------------------
|
|
197
|
-
// Catch-all
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
73
|
+
const code = JOSE_NAME_TO_AUTH_CODE[name] ?? "JWT_ERROR";
|
|
74
|
+
const message = AUTH_CODE_TO_MESSAGE[code] ??
|
|
75
|
+
// fallback defensivo (no dependemos de message de jose)
|
|
76
|
+
"JWT operation failed";
|
|
199
77
|
return {
|
|
200
|
-
code
|
|
201
|
-
message
|
|
78
|
+
code,
|
|
79
|
+
message,
|
|
202
80
|
meta,
|
|
203
81
|
cause: err,
|
|
204
82
|
};
|
|
205
83
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Convierte un error técnico a un Error del core (AuthDomainError u otro),
|
|
208
|
-
* sin acoplar el plugin a una implementación concreta.
|
|
209
|
-
*/
|
|
210
84
|
function toAuthDomainError(createAuthError, err, ctx) {
|
|
85
|
+
if (auth_1.AuthDomainError.isAuthError(err)) {
|
|
86
|
+
return err;
|
|
87
|
+
}
|
|
211
88
|
const mapped = mapJoseErrorToAuthError(err, ctx);
|
|
212
89
|
return createAuthError({
|
|
213
90
|
code: mapped.code,
|
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//src/infrastructure/mappers/types/index.ts
|
|
18
17
|
__exportStar(require("./jose-error-context.type"), exports);
|
|
19
18
|
__exportStar(require("./mapped-auth-error.type"), exports);
|
|
20
19
|
__exportStar(require("./token-kind.type"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TokenKind
|
|
1
|
+
import { TokenKind } from "./token-kind.type";
|
|
2
|
+
import { TokenOperation } from "./token-operation.type";
|
|
2
3
|
/**
|
|
3
4
|
* Contexto técnico mínimo para mapear errores de `jose` a errores del core.
|
|
4
5
|
*
|
|
@@ -18,13 +19,9 @@ export interface JoseErrorContext {
|
|
|
18
19
|
tokenKind?: TokenKind;
|
|
19
20
|
/**
|
|
20
21
|
* Issuer esperado/configurado (si aplica).
|
|
21
|
-
* Sirve para entender fallos de validación de claims.
|
|
22
|
+
* Sirve para entender fallos de validación de claims (issuer).
|
|
22
23
|
*/
|
|
23
24
|
issuer?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Audience esperada/configurada (si aplica).
|
|
26
|
-
*/
|
|
27
|
-
audience?: string;
|
|
28
25
|
/**
|
|
29
26
|
* Algoritmo configurado/esperado (HS256/RS256/ES256...).
|
|
30
27
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AuthErrorCode } from "@jmlq/auth";
|
|
1
2
|
/**
|
|
2
3
|
* Resultado agnóstico del mapper.
|
|
3
4
|
* Representa “la forma” del error que entiende el core (por código),
|
|
@@ -7,7 +8,7 @@ export interface MappedAuthError {
|
|
|
7
8
|
/**
|
|
8
9
|
* Código de error compatible con el core (@jmlq/auth).
|
|
9
10
|
*/
|
|
10
|
-
code:
|
|
11
|
+
code: AuthErrorCode;
|
|
11
12
|
/**
|
|
12
13
|
* Mensaje técnico simple (orientado a debugging).
|
|
13
14
|
* No debe incluir datos sensibles.
|
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//src/infrastructure/services/index.ts
|
|
18
17
|
__exportStar(require("./jose-token.service"), exports);
|
|
@@ -10,6 +10,5 @@ import type { JoseErrorContext, TokenOperation } from "../../mappers/types";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function buildJoseCtx(operation: TokenOperation, tokenKind: JoseErrorContext["tokenKind"], eff: {
|
|
12
12
|
issuer?: string;
|
|
13
|
-
audience?: string | string[];
|
|
14
13
|
alg?: string;
|
|
15
14
|
}): JoseErrorContext;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildJoseCtx = buildJoseCtx;
|
|
4
|
-
//src/infrastructure/services/internal/build-jose-ctx.ts
|
|
5
|
-
const internal_1 = require("../../../shared/internal");
|
|
6
4
|
/**
|
|
7
5
|
* Construye contexto técnico para el mapper de errores.
|
|
8
6
|
*
|
|
@@ -17,7 +15,6 @@ function buildJoseCtx(operation, tokenKind, eff) {
|
|
|
17
15
|
operation,
|
|
18
16
|
tokenKind,
|
|
19
17
|
issuer: eff.issuer,
|
|
20
|
-
audience: (0, internal_1.normalizeAudienceForMeta)(eff.audience),
|
|
21
18
|
alg: eff.alg,
|
|
22
19
|
};
|
|
23
20
|
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
export * from "./to-date-from-unix-seconds";
|
|
2
1
|
export * from "./normalize-key-material";
|
|
3
|
-
export * from "./create-jti";
|
|
4
2
|
export * from "./jwt-expiration-reader";
|
|
5
|
-
export * from "./read-expires-in";
|
|
6
|
-
export * from "./read-custom-claims";
|
|
7
|
-
export * from "./read-session-id";
|
|
8
3
|
export * from "./get-alg-from-key-material";
|
|
9
|
-
export * from "./normalize-jwt-payload";
|
|
10
|
-
export * from "./resolve-expires-in";
|
|
11
4
|
export * from "./build-jose-ctx";
|
|
12
|
-
export * from "./is-retryable-mapped-code";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//src/infrastructure/services/internal/index.ts
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
5
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,15 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
15
|
};
|
|
17
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./to-date-from-unix-seconds"), exports);
|
|
19
17
|
__exportStar(require("./normalize-key-material"), exports);
|
|
20
|
-
__exportStar(require("./create-jti"), exports);
|
|
21
18
|
__exportStar(require("./jwt-expiration-reader"), exports);
|
|
22
|
-
__exportStar(require("./read-expires-in"), exports);
|
|
23
|
-
__exportStar(require("./read-custom-claims"), exports);
|
|
24
|
-
__exportStar(require("./read-session-id"), exports);
|
|
25
19
|
__exportStar(require("./get-alg-from-key-material"), exports);
|
|
26
|
-
__exportStar(require("./normalize-jwt-payload"), exports);
|
|
27
|
-
__exportStar(require("./resolve-expires-in"), exports);
|
|
28
20
|
__exportStar(require("./build-jose-ctx"), exports);
|
|
29
|
-
__exportStar(require("./is-retryable-mapped-code"), exports);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//src/infrastructure/services/internal/jwt-expiration-reader.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.tryReadExpByDecode = tryReadExpByDecode;
|
|
5
4
|
const jose_1 = require("jose");
|
|
@@ -14,7 +13,8 @@ const jose_1 = require("jose");
|
|
|
14
13
|
function tryReadExpByDecode(token) {
|
|
15
14
|
try {
|
|
16
15
|
const decoded = (0, jose_1.decodeJwt)(token);
|
|
17
|
-
const
|
|
16
|
+
const rec = decoded;
|
|
17
|
+
const exp = rec.exp;
|
|
18
18
|
return typeof exp === "number" ? exp : null;
|
|
19
19
|
}
|
|
20
20
|
catch {
|