@jmlq/auth 0.0.1-alpha.1
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/README.md +306 -0
- package/dist/examples/bcrypt-password-hasher.example.d.ts +3 -0
- package/dist/examples/bcrypt-password-hasher.example.js +78 -0
- package/dist/examples/entity-object.example.d.ts +39 -0
- package/dist/examples/entity-object.example.js +411 -0
- package/dist/examples/factory-auth-service-example.d.ts +3 -0
- package/dist/examples/factory-auth-service-example.js +84 -0
- package/dist/examples/index.example.d.ts +12 -0
- package/dist/examples/index.example.js +171 -0
- package/dist/examples/jwt-algoritm.example.d.ts +47 -0
- package/dist/examples/jwt-algoritm.example.js +447 -0
- package/dist/examples/jwt-token-generator.example.d.ts +6 -0
- package/dist/examples/jwt-token-generator.example.js +49 -0
- package/dist/examples/jwt-verifier.example.d.ts +3 -0
- package/dist/examples/jwt-verifier.example.js +80 -0
- package/dist/examples/password-policy.example.d.ts +7 -0
- package/dist/examples/password-policy.example.js +57 -0
- package/dist/examples/service-jwt-token.example.d.ts +3 -0
- package/dist/examples/service-jwt-token.example.js +154 -0
- package/dist/examples/service-token-session.example.d.ts +3 -0
- package/dist/examples/service-token-session.example.js +139 -0
- package/dist/examples/use-case-login-with-password.example.d.ts +6 -0
- package/dist/examples/use-case-login-with-password.example.js +105 -0
- package/dist/examples/use-case-logout.example.d.ts +7 -0
- package/dist/examples/use-case-logout.example.js +134 -0
- package/dist/examples/use-case-refresh-token.example.d.ts +11 -0
- package/dist/examples/use-case-refresh-token.example.js +164 -0
- package/dist/examples/use-case-register-user.example.d.ts +9 -0
- package/dist/examples/use-case-register-user.example.js +110 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/application/dtos/index.d.ts +4 -0
- package/dist/src/application/dtos/index.js +20 -0
- package/dist/src/application/dtos/login.dto.d.ts +9 -0
- package/dist/src/application/dtos/login.dto.js +2 -0
- package/dist/src/application/dtos/logout.dto.d.ts +7 -0
- package/dist/src/application/dtos/logout.dto.js +2 -0
- package/dist/src/application/dtos/refresh-token.dto.d.ts +7 -0
- package/dist/src/application/dtos/refresh-token.dto.js +2 -0
- package/dist/src/application/dtos/register-user.dto.d.ts +16 -0
- package/dist/src/application/dtos/register-user.dto.js +2 -0
- package/dist/src/application/factories/auth-service.factory.d.ts +5 -0
- package/dist/src/application/factories/auth-service.factory.js +51 -0
- package/dist/src/application/factories/index.d.ts +1 -0
- package/dist/src/application/factories/index.js +17 -0
- package/dist/src/application/index.d.ts +3 -0
- package/dist/src/application/index.js +19 -0
- package/dist/src/application/use-cases/index.d.ts +4 -0
- package/dist/src/application/use-cases/index.js +20 -0
- package/dist/src/application/use-cases/login-with-password.use-case.d.ts +9 -0
- package/dist/src/application/use-cases/login-with-password.use-case.js +36 -0
- package/dist/src/application/use-cases/logout.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/logout.use-case.js +22 -0
- package/dist/src/application/use-cases/refresh-token.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/refresh-token.use-case.js +23 -0
- package/dist/src/application/use-cases/register-user.use-case.d.ts +10 -0
- package/dist/src/application/use-cases/register-user.use-case.js +37 -0
- package/dist/src/domain/entities/credential.entity.d.ts +78 -0
- package/dist/src/domain/entities/credential.entity.js +92 -0
- package/dist/src/domain/entities/index.d.ts +2 -0
- package/dist/src/domain/entities/index.js +18 -0
- package/dist/src/domain/entities/user.entity.d.ts +97 -0
- package/dist/src/domain/entities/user.entity.js +116 -0
- package/dist/src/domain/errors/auth-domain-error.d.ts +82 -0
- package/dist/src/domain/errors/auth-domain-error.js +112 -0
- package/dist/src/domain/errors/auth.errors.d.ts +56 -0
- package/dist/src/domain/errors/auth.errors.js +76 -0
- package/dist/src/domain/errors/identity.errors.d.ts +34 -0
- package/dist/src/domain/errors/identity.errors.js +82 -0
- package/dist/src/domain/errors/index.d.ts +2 -0
- package/dist/src/domain/errors/index.js +18 -0
- package/dist/src/domain/index.d.ts +6 -0
- package/dist/src/domain/index.js +22 -0
- package/dist/src/domain/object-values/email.d.ts +37 -0
- package/dist/src/domain/object-values/email.js +56 -0
- package/dist/src/domain/object-values/hashed-password.d.ts +28 -0
- package/dist/src/domain/object-values/hashed-password.js +73 -0
- package/dist/src/domain/object-values/id.d.ts +8 -0
- package/dist/src/domain/object-values/id.js +28 -0
- package/dist/src/domain/object-values/index.d.ts +5 -0
- package/dist/src/domain/object-values/index.js +13 -0
- package/dist/src/domain/object-values/permission.d.ts +15 -0
- package/dist/src/domain/object-values/permission.js +57 -0
- package/dist/src/domain/object-values/role.d.ts +25 -0
- package/dist/src/domain/object-values/role.js +108 -0
- package/dist/src/domain/ports/auth/password-hasher.d.ts +7 -0
- package/dist/src/domain/ports/auth/password-hasher.js +2 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.d.ts +0 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.js +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.d.ts +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.js +2 -0
- package/dist/src/domain/ports/config/auth-config.port.d.ts +19 -0
- package/dist/src/domain/ports/config/auth-config.port.js +3 -0
- package/dist/src/domain/ports/index.d.ts +9 -0
- package/dist/src/domain/ports/index.js +25 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.d.ts +12 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +30 -0
- package/dist/src/domain/ports/jwt/signature-strategy.js +4 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/repository/credential.repository.d.ts +10 -0
- package/dist/src/domain/ports/repository/credential.repository.js +2 -0
- package/dist/src/domain/ports/repository/index.d.ts +2 -0
- package/dist/src/domain/ports/repository/index.js +18 -0
- package/dist/src/domain/ports/repository/user.repository.d.ts +13 -0
- package/dist/src/domain/ports/repository/user.repository.js +2 -0
- package/dist/src/domain/ports/token/token-session.port.d.ts +7 -0
- package/dist/src/domain/ports/token/token-session.port.js +2 -0
- package/dist/src/domain/ports/token/token.service.port.d.ts +9 -0
- package/dist/src/domain/ports/token/token.service.port.js +2 -0
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +8 -0
- package/dist/src/domain/props/entities/credential.props.d.ts +8 -0
- package/dist/src/domain/props/entities/credential.props.js +2 -0
- package/dist/src/domain/props/entities/index.d.ts +2 -0
- package/dist/src/domain/props/entities/index.js +18 -0
- package/dist/src/domain/props/entities/user.props.d.ts +10 -0
- package/dist/src/domain/props/entities/user.props.js +2 -0
- package/dist/src/domain/props/index.d.ts +2 -0
- package/dist/src/domain/props/index.js +18 -0
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +9 -0
- package/dist/src/domain/props/jwt/create-payload.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +10 -0
- package/dist/src/domain/props/jwt/generate-token.props.js +2 -0
- package/dist/src/domain/props/jwt/index.d.ts +5 -0
- package/dist/src/domain/props/jwt/index.js +21 -0
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-subject.js +2 -0
- package/dist/src/domain/props/jwt/jwt-user.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-user.js +2 -0
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/services/index.d.ts +2 -0
- package/dist/src/domain/props/services/index.js +18 -0
- package/dist/src/domain/services/index.d.ts +1 -0
- package/dist/src/domain/services/index.js +17 -0
- package/dist/src/domain/services/password-policy.service.d.ts +8 -0
- package/dist/src/domain/services/password-policy.service.js +29 -0
- package/dist/src/domain/services/token.service.port.d.ts +9 -0
- package/dist/src/domain/services/token.service.port.js +2 -0
- package/dist/src/index.d.ts +78 -0
- package/dist/src/index.js +94 -0
- package/dist/src/infrastructure/index.d.ts +5 -0
- package/dist/src/infrastructure/index.js +21 -0
- package/dist/src/infrastructure/jwt/factory/index.d.ts +1 -0
- package/dist/src/infrastructure/jwt/factory/index.js +17 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/index.js +19 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/strategies/index.js +19 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +57 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +123 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +59 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +100 -0
- package/dist/src/infrastructure/jwt/token/index.d.ts +5 -0
- package/dist/src/infrastructure/jwt/token/index.js +21 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +29 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +30 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/repositories/index.d.ts +1 -0
- package/dist/src/infrastructure/repositories/index.js +17 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.d.ts +12 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.js +68 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +67 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +128 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.d.ts +11 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.js +49 -0
- package/dist/src/infrastructure/repositories/test/index.d.ts +2 -0
- package/dist/src/infrastructure/repositories/test/index.js +18 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.d.ts +6 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.js +19 -0
- package/dist/src/infrastructure/security/index.d.ts +1 -0
- package/dist/src/infrastructure/security/index.js +17 -0
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +18 -0
- package/dist/src/infrastructure/services/default-token-session.service.js +88 -0
- package/dist/src/infrastructure/services/index.d.ts +2 -0
- package/dist/src/infrastructure/services/index.js +18 -0
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/jwt-token.service.js +44 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +46 -0
- package/dist/src/infrastructure/services/token-session.service.d.ts +24 -0
- package/dist/src/infrastructure/services/token-session.service.js +131 -0
- package/dist/src/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/src/infrastructure/types/auth-service-container.js +2 -0
- package/dist/src/infrastructure/types/index.d.ts +1 -0
- package/dist/src/infrastructure/types/index.js +17 -0
- package/dist/src/shared/constants/index.d.ts +1 -0
- package/dist/src/shared/constants/index.js +17 -0
- package/dist/src/shared/constants/jwt-algorithms.d.ts +17 -0
- package/dist/src/shared/constants/jwt-algorithms.js +23 -0
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +29 -0
- package/dist/src/shared/encoders/base64-url-encoder.js +45 -0
- package/dist/src/shared/encoders/index.d.ts +1 -0
- package/dist/src/shared/encoders/index.js +17 -0
- package/dist/src/shared/index.d.ts +4 -0
- package/dist/src/shared/index.js +20 -0
- package/dist/src/shared/types/index.d.ts +1 -0
- package/dist/src/shared/types/index.js +17 -0
- package/dist/src/shared/types/jwt.d.ts +25 -0
- package/dist/src/shared/types/jwt.js +2 -0
- package/dist/src/shared/types/jwt.types.d.ts +39 -0
- package/dist/src/shared/types/jwt.types.js +2 -0
- package/dist/src/shared/utils/index.d.ts +1 -0
- package/dist/src/shared/utils/index.js +17 -0
- package/dist/src/shared/utils/time-parser.d.ts +28 -0
- package/dist/src/shared/utils/time-parser.js +76 -0
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +1 -0
- package/dist/tests/application/factory/auth-service-factory.spec.js +97 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +140 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.js +40 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +116 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +151 -0
- package/dist/tests/domain/entities/credential.spec.d.ts +1 -0
- package/dist/tests/domain/entities/credential.spec.js +93 -0
- package/dist/tests/domain/entities/user.spec.d.ts +1 -0
- package/dist/tests/domain/entities/user.spec.js +93 -0
- package/dist/tests/domain/object-values/email.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/email.spec.js +77 -0
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/domain/object-values/id.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/id.spec.js +48 -0
- package/dist/tests/domain/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/permission.spec.js +75 -0
- package/dist/tests/domain/object-values/role.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/role.spec.js +139 -0
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +1 -0
- package/dist/tests/domain/services/default-password-policy.spec.js +69 -0
- package/dist/tests/doman/entities/credential.spec.d.ts +1 -0
- package/dist/tests/doman/entities/credential.spec.js +93 -0
- package/dist/tests/doman/entities/user.spec.d.ts +1 -0
- package/dist/tests/doman/entities/user.spec.js +93 -0
- package/dist/tests/doman/object-values/email.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/email.spec.js +77 -0
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/doman/object-values/id.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/id.spec.js +48 -0
- package/dist/tests/doman/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/permission.spec.js +75 -0
- package/dist/tests/doman/object-values/role.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/role.spec.js +139 -0
- package/dist/tests/helpers/make-jwt-subject.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-subject.js +16 -0
- package/dist/tests/helpers/make-jwt-user.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-user.js +16 -0
- package/dist/tests/helpers/make-user.d.ts +2 -0
- package/dist/tests/helpers/make-user.js +15 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +127 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +157 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +150 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +156 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +179 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +142 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +125 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +126 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +1 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +37 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +145 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.js +269 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +1 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +27 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +1 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +70 -0
- package/dist/tests/shared/utils/time-parser.spec.d.ts +1 -0
- package/dist/tests/shared/utils/time-parser.spec.js +80 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/time-parser.d.ts +28 -0
- package/dist/utils/time-parser.js +76 -0
- package/package.json +48 -0
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
__exportStar(require("./token-session.service"), exports);
|
|
18
|
+
__exportStar(require("./jwt-token.service"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IGenerateAccessTokenProps, IGenerateRefreshTokenProps, IJWTPayload, ITokenService } from "../../domain";
|
|
2
|
+
import { JwtTokenServiceConfig } from "../../shared";
|
|
3
|
+
import { JwtTokenGenerator, JwtTokenValidator, JwtTokenVerifier } from "../jwt";
|
|
4
|
+
export declare class JwtTokenService implements ITokenService {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly jwtGenerator;
|
|
7
|
+
private readonly jwtVerifier;
|
|
8
|
+
private readonly jwtValidator;
|
|
9
|
+
constructor(config: JwtTokenServiceConfig, jwtGenerator: JwtTokenGenerator, jwtVerifier: JwtTokenVerifier, jwtValidator: JwtTokenValidator);
|
|
10
|
+
generateAccessToken(props: IGenerateAccessTokenProps): Promise<string>;
|
|
11
|
+
generateRefreshToken(props: IGenerateRefreshTokenProps): Promise<string>;
|
|
12
|
+
verifyAccessToken(token: string): Promise<IJWTPayload>;
|
|
13
|
+
verifyRefreshToken(token: string): Promise<IJWTPayload>;
|
|
14
|
+
getTokenExpiration(token: string): Promise<Date>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtTokenService = void 0;
|
|
4
|
+
// Servicio de tokens JWT que implementa ITokenService
|
|
5
|
+
class JwtTokenService {
|
|
6
|
+
constructor(
|
|
7
|
+
// config → secretos, tiempos de expiración y algoritmo.
|
|
8
|
+
config,
|
|
9
|
+
// jwtGenerator → crea y firma los tokens.
|
|
10
|
+
jwtGenerator,
|
|
11
|
+
// jwtVerifier → comprueba firmas y expiraciones.
|
|
12
|
+
jwtVerifier,
|
|
13
|
+
// jwtValidator → revisa formato y estructura
|
|
14
|
+
jwtValidator) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.jwtGenerator = jwtGenerator;
|
|
17
|
+
this.jwtVerifier = jwtVerifier;
|
|
18
|
+
this.jwtValidator = jwtValidator;
|
|
19
|
+
}
|
|
20
|
+
// Genera un access token
|
|
21
|
+
async generateAccessToken(props) {
|
|
22
|
+
return this.jwtGenerator.generateAccessToken(props);
|
|
23
|
+
}
|
|
24
|
+
// Genera un refresh token
|
|
25
|
+
async generateRefreshToken(props) {
|
|
26
|
+
return this.jwtGenerator.generateRefreshToken(props);
|
|
27
|
+
}
|
|
28
|
+
// verifica si el token es válido y retorna el payload
|
|
29
|
+
async verifyAccessToken(token) {
|
|
30
|
+
this.jwtValidator.validateTokenInput(token);
|
|
31
|
+
return this.jwtVerifier.verifyAccessToken(token, this.config);
|
|
32
|
+
}
|
|
33
|
+
// verifica si el refresh token es válido y retorna el payload
|
|
34
|
+
async verifyRefreshToken(token) {
|
|
35
|
+
this.jwtValidator.validateTokenInput(token);
|
|
36
|
+
return this.jwtVerifier.verifyRefreshToken(token, this.config);
|
|
37
|
+
}
|
|
38
|
+
// Obtiene la fecha de expiración del token
|
|
39
|
+
async getTokenExpiration(token) {
|
|
40
|
+
this.jwtValidator.validateTokenInput(token);
|
|
41
|
+
return this.jwtVerifier.getTokenExpiration(token);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.JwtTokenService = JwtTokenService;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IGenerateAccessTokenProps, IGenerateRefreshTokenProps, IJWTPayload, ITokenService } from "../../domain";
|
|
2
|
+
import { JwtTokenServiceConfig } from "../../shared";
|
|
3
|
+
import { JwtTokenGenerator, JwtTokenValidator, JwtTokenVerifier } from "../jwt";
|
|
4
|
+
export declare class SimpleJwtTokenService implements ITokenService {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly jwtGenerator;
|
|
7
|
+
private readonly jwtVerifier;
|
|
8
|
+
private readonly jwtValidator;
|
|
9
|
+
constructor(config: JwtTokenServiceConfig, jwtGenerator: JwtTokenGenerator, jwtVerifier: JwtTokenVerifier, jwtValidator: JwtTokenValidator);
|
|
10
|
+
generateAccessToken(props: IGenerateAccessTokenProps): Promise<string>;
|
|
11
|
+
generateRefreshToken(props: IGenerateRefreshTokenProps): Promise<string>;
|
|
12
|
+
verifyAccessToken(token: string): Promise<IJWTPayload>;
|
|
13
|
+
verifyRefreshToken(token: string): Promise<IJWTPayload>;
|
|
14
|
+
getTokenExpiration(token: string): Promise<Date>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleJwtTokenService = void 0;
|
|
4
|
+
// Fachada principal del sistema de tokens JWT.
|
|
5
|
+
// Servicio de alto nivel que orquesta las operaciones de generación, validación y verificación de tokens,
|
|
6
|
+
// ocultando los detalles internos de las clases más técnicas (JwtTokenGenerator, JwtTokenVerifier, JwtTokenValidator).
|
|
7
|
+
class SimpleJwtTokenService {
|
|
8
|
+
constructor(
|
|
9
|
+
// config → secretos, tiempos de expiración y algoritmo.
|
|
10
|
+
config,
|
|
11
|
+
// jwtGenerator → crea y firma los tokens.
|
|
12
|
+
jwtGenerator,
|
|
13
|
+
// jwtVerifier → comprueba firmas y expiraciones.
|
|
14
|
+
jwtVerifier,
|
|
15
|
+
// jwtValidator → revisa formato y estructura
|
|
16
|
+
jwtValidator) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.jwtGenerator = jwtGenerator;
|
|
19
|
+
this.jwtVerifier = jwtVerifier;
|
|
20
|
+
this.jwtValidator = jwtValidator;
|
|
21
|
+
}
|
|
22
|
+
// Genera un access token
|
|
23
|
+
async generateAccessToken(props) {
|
|
24
|
+
return this.jwtGenerator.generateAccessToken(props);
|
|
25
|
+
}
|
|
26
|
+
// Genera un refresh token
|
|
27
|
+
async generateRefreshToken(props) {
|
|
28
|
+
return this.jwtGenerator.generateRefreshToken(props);
|
|
29
|
+
}
|
|
30
|
+
// verifica si el token es válido y retorna el payload
|
|
31
|
+
async verifyAccessToken(token) {
|
|
32
|
+
this.jwtValidator.validateTokenInput(token);
|
|
33
|
+
return this.jwtVerifier.verifyAccessToken(token, this.config);
|
|
34
|
+
}
|
|
35
|
+
// verifica si el refresh token es válido y retorna el payload
|
|
36
|
+
async verifyRefreshToken(token) {
|
|
37
|
+
this.jwtValidator.validateTokenInput(token);
|
|
38
|
+
return this.jwtVerifier.verifyRefreshToken(token, this.config);
|
|
39
|
+
}
|
|
40
|
+
// Obtiene la fecha de expiración del token
|
|
41
|
+
async getTokenExpiration(token) {
|
|
42
|
+
this.jwtValidator.validateTokenInput(token);
|
|
43
|
+
return this.jwtVerifier.getTokenExpiration(token);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.SimpleJwtTokenService = SimpleJwtTokenService;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Credential, ICredentialRepository, ITokenService, ITokenSession, IUserRepository, User } from "../../domain";
|
|
2
|
+
import { AnyAlgorithm } from "../../shared";
|
|
3
|
+
/**
|
|
4
|
+
* Servicio de gestión de sesiones de usuario mediante tokens JWT.
|
|
5
|
+
* Proporciona métodos para crear, refrescar, validar y revocar sesiones.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TokenSessionService implements ITokenSession {
|
|
8
|
+
private readonly tokenService;
|
|
9
|
+
private readonly userRepository;
|
|
10
|
+
private readonly credentialRepository;
|
|
11
|
+
private readonly algorithm;
|
|
12
|
+
private readonly accessTokenExpiration;
|
|
13
|
+
private readonly refreshTokenExpiration;
|
|
14
|
+
private readonly accessTokenSecret?;
|
|
15
|
+
private readonly refreshTokenSecret?;
|
|
16
|
+
private readonly accessMs;
|
|
17
|
+
private readonly refreshMs;
|
|
18
|
+
constructor(tokenService: ITokenService, userRepository: IUserRepository, credentialRepository: ICredentialRepository, algorithm: AnyAlgorithm, accessTokenExpiration?: string, refreshTokenExpiration?: string, accessTokenSecret?: string | undefined, refreshTokenSecret?: string | undefined);
|
|
19
|
+
private buildJwtConfig;
|
|
20
|
+
createSession(user: User): Promise<Credential>;
|
|
21
|
+
refreshSession(refreshToken: string): Promise<Credential>;
|
|
22
|
+
validateSession(accessToken: string): Promise<User | null>;
|
|
23
|
+
revokeSession(refreshToken: string): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenSessionService = void 0;
|
|
4
|
+
const domain_1 = require("../../domain");
|
|
5
|
+
const shared_1 = require("../../shared");
|
|
6
|
+
/**
|
|
7
|
+
* Servicio de gestión de sesiones de usuario mediante tokens JWT.
|
|
8
|
+
* Proporciona métodos para crear, refrescar, validar y revocar sesiones.
|
|
9
|
+
*/
|
|
10
|
+
class TokenSessionService {
|
|
11
|
+
constructor(
|
|
12
|
+
// Servicio de tokens JWT
|
|
13
|
+
tokenService,
|
|
14
|
+
// Repositorio de usuarios
|
|
15
|
+
userRepository,
|
|
16
|
+
// Repositorio de credenciales
|
|
17
|
+
credentialRepository,
|
|
18
|
+
// Algoritmo JWT a usar
|
|
19
|
+
algorithm,
|
|
20
|
+
// Configuración de expiraciones y secretos
|
|
21
|
+
accessTokenExpiration = "15m", refreshTokenExpiration = "7d", accessTokenSecret, refreshTokenSecret) {
|
|
22
|
+
this.tokenService = tokenService;
|
|
23
|
+
this.userRepository = userRepository;
|
|
24
|
+
this.credentialRepository = credentialRepository;
|
|
25
|
+
this.algorithm = algorithm;
|
|
26
|
+
this.accessTokenExpiration = accessTokenExpiration;
|
|
27
|
+
this.refreshTokenExpiration = refreshTokenExpiration;
|
|
28
|
+
this.accessTokenSecret = accessTokenSecret;
|
|
29
|
+
this.refreshTokenSecret = refreshTokenSecret;
|
|
30
|
+
// Validar que los secretos estén presentes
|
|
31
|
+
if (!accessTokenSecret || !refreshTokenSecret)
|
|
32
|
+
throw new domain_1.JwtSecretError("Missing JWT secrets");
|
|
33
|
+
// Parsear las expiraciones a milisegundos
|
|
34
|
+
try {
|
|
35
|
+
this.accessMs = shared_1.TimeParser.parseToMilliseconds(accessTokenExpiration);
|
|
36
|
+
this.refreshMs = shared_1.TimeParser.parseToMilliseconds(refreshTokenExpiration);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new Error(`Invalid token expiration configuration: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Construir configuración JWT para generación de tokens
|
|
43
|
+
buildJwtConfig() {
|
|
44
|
+
return {
|
|
45
|
+
accessTokenExpirationMs: this.accessMs,
|
|
46
|
+
refreshTokenExpirationMs: this.refreshMs,
|
|
47
|
+
accessTokenSecret: this.accessTokenSecret,
|
|
48
|
+
refreshTokenSecret: this.refreshTokenSecret,
|
|
49
|
+
algorithm: this.algorithm,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Crear una nueva sesión de usuario
|
|
53
|
+
async createSession(user) {
|
|
54
|
+
const config = this.buildJwtConfig();
|
|
55
|
+
// Generar tokens
|
|
56
|
+
const accessToken = await this.tokenService.generateAccessToken({
|
|
57
|
+
user: {
|
|
58
|
+
id: user.id.toString(),
|
|
59
|
+
email: user.email.toString(),
|
|
60
|
+
roles: user.roles.map((role) => role.getValuePublic()),
|
|
61
|
+
},
|
|
62
|
+
expiresIn: this.accessTokenExpiration,
|
|
63
|
+
config,
|
|
64
|
+
});
|
|
65
|
+
// Generar refresh token
|
|
66
|
+
const refreshToken = await this.tokenService.generateRefreshToken({
|
|
67
|
+
user: {
|
|
68
|
+
id: user.id.toString(),
|
|
69
|
+
email: user.email.toString(),
|
|
70
|
+
roles: user.roles.map((role) => role.getValuePublic()),
|
|
71
|
+
},
|
|
72
|
+
expiresIn: this.refreshTokenExpiration,
|
|
73
|
+
config,
|
|
74
|
+
});
|
|
75
|
+
// Crear y guardar la credencial
|
|
76
|
+
const credential = domain_1.Credential.create(user.id, accessToken, refreshToken, new Date(Date.now() + this.accessMs));
|
|
77
|
+
// Guardar la credencial en el repositorio
|
|
78
|
+
await this.credentialRepository.save(credential);
|
|
79
|
+
// Retornar la credencial creada
|
|
80
|
+
return credential;
|
|
81
|
+
}
|
|
82
|
+
// Refrescar una sesión existente usando el refresh token
|
|
83
|
+
async refreshSession(refreshToken) {
|
|
84
|
+
// Verificar si la credencial con el refresh token existe
|
|
85
|
+
const existing = await this.credentialRepository.findByRefreshToken(refreshToken);
|
|
86
|
+
// Si no existe, lanzar error
|
|
87
|
+
if (!existing) {
|
|
88
|
+
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
89
|
+
}
|
|
90
|
+
// Verificar y obtener el payload del refresh token
|
|
91
|
+
const payload = await this.tokenService
|
|
92
|
+
.verifyRefreshToken(refreshToken)
|
|
93
|
+
.catch(() => {
|
|
94
|
+
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
95
|
+
});
|
|
96
|
+
// Obtener el usuario asociado al payload
|
|
97
|
+
const user = await this.userRepository.findById(new domain_1.Id(payload.sub));
|
|
98
|
+
// Validar que el usuario exista y pueda iniciar sesión
|
|
99
|
+
if (!user)
|
|
100
|
+
throw new domain_1.UserNotFoundError();
|
|
101
|
+
// Validar que el usuario no esté deshabilitado
|
|
102
|
+
if (!user.canLogin())
|
|
103
|
+
throw new domain_1.UserDisabledError();
|
|
104
|
+
// Crear una nueva sesión para el usuario
|
|
105
|
+
const newCredential = await this.createSession(user);
|
|
106
|
+
// Eliminar la credencial antigua asociada al refresh token
|
|
107
|
+
await this.credentialRepository.deleteByRefreshToken(refreshToken); // rotación
|
|
108
|
+
// Retornar la nueva credencial
|
|
109
|
+
return newCredential;
|
|
110
|
+
}
|
|
111
|
+
// Validar una sesión usando el access token
|
|
112
|
+
async validateSession(accessToken) {
|
|
113
|
+
try {
|
|
114
|
+
// Verificar y obtener el payload del access token
|
|
115
|
+
const payload = await this.tokenService.verifyAccessToken(accessToken);
|
|
116
|
+
// Obtener el usuario asociado al payload
|
|
117
|
+
const user = await this.userRepository.findById(new domain_1.Id(payload.sub));
|
|
118
|
+
// Retornar el usuario si existe y puede iniciar sesión, sino retornar null
|
|
119
|
+
return user && user.canLogin() ? user : null;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Revocar una sesión usando el refresh token
|
|
126
|
+
async revokeSession(refreshToken) {
|
|
127
|
+
// Eliminar la credencial asociada al refresh token
|
|
128
|
+
await this.credentialRepository.deleteByRefreshToken(refreshToken);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.TokenSessionService = TokenSessionService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LoginWithPasswordUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUserUseCase } from "../../application";
|
|
2
|
+
import { ICredentialRepository, IPasswordHasher, IPasswordPolicy, ITokenService, ITokenSession, IUserRepository } from "../../domain";
|
|
3
|
+
export interface IAuthServiceContainer {
|
|
4
|
+
userRepository: IUserRepository;
|
|
5
|
+
credentialRepository: ICredentialRepository;
|
|
6
|
+
passwordHasher: IPasswordHasher;
|
|
7
|
+
tokenService: ITokenService;
|
|
8
|
+
passwordPolicy: IPasswordPolicy;
|
|
9
|
+
tokenSession: ITokenSession;
|
|
10
|
+
registerUserUseCase: RegisterUserUseCase;
|
|
11
|
+
loginWithPasswordUseCase: LoginWithPasswordUseCase;
|
|
12
|
+
refreshTokenUseCase: RefreshTokenUseCase;
|
|
13
|
+
logoutUseCase: LogoutUseCase;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./auth-service-container";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./auth-service-container"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jwt-algorithms";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./jwt-algorithms"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const algorithms: {
|
|
2
|
+
readonly hmac: {
|
|
3
|
+
readonly HS256: "HS256";
|
|
4
|
+
readonly HS384: "HS384";
|
|
5
|
+
readonly HS512: "HS512";
|
|
6
|
+
};
|
|
7
|
+
readonly rsa: {
|
|
8
|
+
readonly RS256: "RS256";
|
|
9
|
+
readonly RS384: "RS384";
|
|
10
|
+
readonly RS512: "RS512";
|
|
11
|
+
};
|
|
12
|
+
readonly ecdsa: {
|
|
13
|
+
readonly ES256: "ES256";
|
|
14
|
+
readonly ES384: "ES384";
|
|
15
|
+
readonly ES512: "ES512";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.algorithms = void 0;
|
|
4
|
+
exports.algorithms = {
|
|
5
|
+
// simétrica (una sola clave)
|
|
6
|
+
hmac: {
|
|
7
|
+
HS256: "HS256",
|
|
8
|
+
HS384: "HS384",
|
|
9
|
+
HS512: "HS512",
|
|
10
|
+
},
|
|
11
|
+
// asimétrica (clave pública/privada)
|
|
12
|
+
rsa: {
|
|
13
|
+
RS256: "RS256",
|
|
14
|
+
RS384: "RS384",
|
|
15
|
+
RS512: "RS512",
|
|
16
|
+
},
|
|
17
|
+
// curvas elípticas
|
|
18
|
+
ecdsa: {
|
|
19
|
+
ES256: "ES256",
|
|
20
|
+
ES384: "ES384",
|
|
21
|
+
ES512: "ES512",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*Esta clase implementa la codificación y decodificación Base64 URL-safe,
|
|
3
|
+
*que es una variante del estándar Base64 diseñada para ser segura en URLs.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Base64UrlEncoder {
|
|
6
|
+
/**
|
|
7
|
+
* Convierte una cadena de texto a formato Base64 URL-safe
|
|
8
|
+
* @param str La cadena a codificar
|
|
9
|
+
* @returns La cadena codificada en Base64 URL-safe
|
|
10
|
+
*/
|
|
11
|
+
encode(str: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Convierte de Base64 URL-safe de vuelta a texto original
|
|
14
|
+
* @param str La cadena codificada en Base64 URL-safe
|
|
15
|
+
* @returns La cadena decodificada
|
|
16
|
+
*/
|
|
17
|
+
decode(str: string): string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* El Base64 estándar usa caracteres (+, /, =) que tienen significado especial en URLs.
|
|
21
|
+
* Base64 URL-safe los reemplaza para evitar problemas cuando se usan en:
|
|
22
|
+
*
|
|
23
|
+
* - Parámetros de URL
|
|
24
|
+
* - Tokens JWT (muy común)
|
|
25
|
+
* - Headers HTTP
|
|
26
|
+
* - Rutas de API
|
|
27
|
+
*
|
|
28
|
+
* Esta implementación es típicamente usada para codificar/decodificar las partes de un JWT (header y payload) de forma segura para transmisión web.
|
|
29
|
+
*/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base64UrlEncoder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*Esta clase implementa la codificación y decodificación Base64 URL-safe,
|
|
6
|
+
*que es una variante del estándar Base64 diseñada para ser segura en URLs.
|
|
7
|
+
*/
|
|
8
|
+
class Base64UrlEncoder {
|
|
9
|
+
/**
|
|
10
|
+
* Convierte una cadena de texto a formato Base64 URL-safe
|
|
11
|
+
* @param str La cadena a codificar
|
|
12
|
+
* @returns La cadena codificada en Base64 URL-safe
|
|
13
|
+
*/
|
|
14
|
+
encode(str) {
|
|
15
|
+
return Buffer.from(str)
|
|
16
|
+
.toString("base64")
|
|
17
|
+
.replace(/\+/g, "-")
|
|
18
|
+
.replace(/\//g, "_")
|
|
19
|
+
.replace(/=/g, "");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convierte de Base64 URL-safe de vuelta a texto original
|
|
23
|
+
* @param str La cadena codificada en Base64 URL-safe
|
|
24
|
+
* @returns La cadena decodificada
|
|
25
|
+
*/
|
|
26
|
+
decode(str) {
|
|
27
|
+
const padding = 4 - (str.length % 4);
|
|
28
|
+
if (padding !== 4) {
|
|
29
|
+
str += "=".repeat(padding);
|
|
30
|
+
}
|
|
31
|
+
return Buffer.from(str.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Base64UrlEncoder = Base64UrlEncoder;
|
|
35
|
+
/**
|
|
36
|
+
* El Base64 estándar usa caracteres (+, /, =) que tienen significado especial en URLs.
|
|
37
|
+
* Base64 URL-safe los reemplaza para evitar problemas cuando se usan en:
|
|
38
|
+
*
|
|
39
|
+
* - Parámetros de URL
|
|
40
|
+
* - Tokens JWT (muy común)
|
|
41
|
+
* - Headers HTTP
|
|
42
|
+
* - Rutas de API
|
|
43
|
+
*
|
|
44
|
+
* Esta implementación es típicamente usada para codificar/decodificar las partes de un JWT (header y payload) de forma segura para transmisión web.
|
|
45
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./base64-url-encoder";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./base64-url-encoder"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
__exportStar(require("./utils"), exports);
|
|
18
|
+
__exportStar(require("./encoders"), exports);
|
|
19
|
+
__exportStar(require("./constants"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jwt.types";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./jwt.types"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { algorithms } from "../constants";
|
|
2
|
+
/**
|
|
3
|
+
* Tipos de algoritmos JWT soportados.
|
|
4
|
+
*/
|
|
5
|
+
export type AlgorithmCategory = keyof typeof algorithms;
|
|
6
|
+
/**
|
|
7
|
+
* Nombres de todos los algoritmos soportados.
|
|
8
|
+
*/
|
|
9
|
+
export type AlgorithmName = (typeof algorithms.hmac)[keyof typeof algorithms.hmac] | (typeof algorithms.rsa)[keyof typeof algorithms.rsa] | (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
10
|
+
/**
|
|
11
|
+
* Tipos específicos de algoritmos por categoría.
|
|
12
|
+
*/
|
|
13
|
+
export type HmacAlgorithm = (typeof algorithms.hmac)[keyof typeof algorithms.hmac];
|
|
14
|
+
/**
|
|
15
|
+
* Tipos específicos de algoritmos por categoría.
|
|
16
|
+
*/
|
|
17
|
+
export type RsaAlgorithm = (typeof algorithms.rsa)[keyof typeof algorithms.rsa];
|
|
18
|
+
/**
|
|
19
|
+
* Tipos específicos de algoritmos por categoría.
|
|
20
|
+
*/
|
|
21
|
+
export type EcdsaAlgorithm = (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
22
|
+
/**
|
|
23
|
+
* Tipo que agrupa todos los algoritmos posibles.
|
|
24
|
+
*/
|
|
25
|
+
export type AnyAlgorithm = HmacAlgorithm | RsaAlgorithm | EcdsaAlgorithm;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IAuthConfig } from "../../domain/ports";
|
|
2
|
+
import { algorithms } from "../constants";
|
|
3
|
+
/**
|
|
4
|
+
* Tipos de algoritmos JWT soportados.
|
|
5
|
+
*/
|
|
6
|
+
export type AlgorithmCategory = keyof typeof algorithms;
|
|
7
|
+
/**
|
|
8
|
+
* Nombres de todos los algoritmos soportados.
|
|
9
|
+
*/
|
|
10
|
+
export type AlgorithmName = (typeof algorithms.hmac)[keyof typeof algorithms.hmac] | (typeof algorithms.rsa)[keyof typeof algorithms.rsa] | (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
11
|
+
/**
|
|
12
|
+
* Tipos específicos de algoritmos por categoría.
|
|
13
|
+
*/
|
|
14
|
+
export type HmacAlgorithm = (typeof algorithms.hmac)[keyof typeof algorithms.hmac];
|
|
15
|
+
/**
|
|
16
|
+
* Tipos específicos de algoritmos por categoría.
|
|
17
|
+
*/
|
|
18
|
+
export type RsaAlgorithm = (typeof algorithms.rsa)[keyof typeof algorithms.rsa];
|
|
19
|
+
/**
|
|
20
|
+
* Tipos específicos de algoritmos por categoría.
|
|
21
|
+
*/
|
|
22
|
+
export type EcdsaAlgorithm = (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
23
|
+
/**
|
|
24
|
+
* Tipo que agrupa todos los algoritmos posibles.
|
|
25
|
+
*/
|
|
26
|
+
export type AnyAlgorithm = HmacAlgorithm | RsaAlgorithm | EcdsaAlgorithm;
|
|
27
|
+
/**
|
|
28
|
+
* Configuración necesaria para los servicios de tokens JWT.
|
|
29
|
+
* Esto lo usan clases como JwtTokenGenerator o JwtTokenVerifier paara saber cómo firmar y con qué tipo de clave.
|
|
30
|
+
* Incluye opciones de JWT e información adicional.
|
|
31
|
+
* @param algorithm Algoritmo de firma (opcional).
|
|
32
|
+
* @param privateKey Clave privada para algoritmos RSA/ECDSA (opcional).
|
|
33
|
+
* @param publicKey Clave pública para algoritmos RSA/ECDSA (opcional).
|
|
34
|
+
*/
|
|
35
|
+
export type JwtTokenServiceConfig = IAuthConfig["jwt"] & IAuthConfig["info"] & {
|
|
36
|
+
algorithm: AnyAlgorithm;
|
|
37
|
+
privateKey?: string;
|
|
38
|
+
publicKey?: string;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./time-parser";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./time-parser"), exports);
|