@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
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# @ml-dev-core/jwt.auth
|
|
2
|
+
|
|
3
|
+
🔐 **Paquete de autenticación JWT** con **Arquitectura Limpia** para aplicaciones TypeScript.
|
|
4
|
+
|
|
5
|
+
## 🚀 Instalación Rápida
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ml-dev-core/jwt.auth bcryptjs
|
|
9
|
+
npm install --save-dev @types/bcryptjs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 📖 Documentación
|
|
13
|
+
|
|
14
|
+
- **[📋 Instalación y Configuración](./install.md)** - Guías detalladas para Express.js, NestJS y más
|
|
15
|
+
- **[🏗️ Documentación de Arquitectura](./architecture.md)** - Clean Architecture, capas y patrones
|
|
16
|
+
- **[📚 Ejemplos de Código](./examples/)** - Casos de uso reales y implementaciones
|
|
17
|
+
|
|
18
|
+
## ✨ Características Principales
|
|
19
|
+
|
|
20
|
+
- ✅ **Clean Architecture**: Separación clara de responsabilidades
|
|
21
|
+
- ✅ **Framework Agnostic**: Compatible con Express, NestJS, Fastify, etc.
|
|
22
|
+
- ✅ **Database Independent**: Repositorios como interfaces
|
|
23
|
+
- ✅ **TypeScript Native**: Tipado fuerte y autocompletado
|
|
24
|
+
- ✅ **JWT Completo**: Access + Refresh tokens con rotación
|
|
25
|
+
- ✅ **Multi-Algorithm**: HS256, RS256, ES256 y más
|
|
26
|
+
- ✅ **Password Security**: Bcrypt con políticas configurables
|
|
27
|
+
- ✅ **Testing Ready**: Repositorios in-memory incluidos
|
|
28
|
+
- ✅ **Production Ready**: Manejo de errores y validaciones
|
|
29
|
+
|
|
30
|
+
## 🏃♂️ Inicio Rápido
|
|
31
|
+
|
|
32
|
+
### 1. Configuración Básica
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import {
|
|
36
|
+
AuthServiceFactory,
|
|
37
|
+
IAuthConfig,
|
|
38
|
+
InMemoryUserRepository,
|
|
39
|
+
InMemoryCredentialRepository,
|
|
40
|
+
} from "@ml-dev-core/jwt.auth";
|
|
41
|
+
|
|
42
|
+
const config: IAuthConfig = {
|
|
43
|
+
jwt: {
|
|
44
|
+
accessTokenSecret: process.env.JWT_ACCESS_SECRET!,
|
|
45
|
+
refreshTokenSecret: process.env.JWT_REFRESH_SECRET!,
|
|
46
|
+
accessTokenExpirationMs: 15 * 60 * 1000, // 15 minutos
|
|
47
|
+
refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000, // 7 días
|
|
48
|
+
accessTokenExpiration: "15m",
|
|
49
|
+
refreshTokenExpiration: "7d",
|
|
50
|
+
},
|
|
51
|
+
bcrypt: { saltRounds: 12 },
|
|
52
|
+
algorithm: "HS256",
|
|
53
|
+
info: {
|
|
54
|
+
issuer: "your-app",
|
|
55
|
+
audience: "your-client",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const authServices = AuthServiceFactory.create(
|
|
60
|
+
config,
|
|
61
|
+
new InMemoryUserRepository(),
|
|
62
|
+
new InMemoryCredentialRepository()
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Casos de Uso
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Registro
|
|
70
|
+
const registerResult = await authServices.registerUserUseCase.execute({
|
|
71
|
+
email: "user@example.com",
|
|
72
|
+
password: "SecurePassword123!",
|
|
73
|
+
confirmPassword: "SecurePassword123!",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Login
|
|
77
|
+
const loginResult = await authServices.loginWithPasswordUseCase.execute({
|
|
78
|
+
email: "user@example.com",
|
|
79
|
+
password: "SecurePassword123!",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
console.log("Access Token:", loginResult.accessToken);
|
|
83
|
+
console.log("Refresh Token:", loginResult.refreshToken);
|
|
84
|
+
|
|
85
|
+
// Refresh
|
|
86
|
+
const refreshResult = await authServices.refreshTokenUseCase.execute({
|
|
87
|
+
refreshToken: loginResult.refreshToken,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Logout
|
|
91
|
+
await authServices.logoutUseCase.execute({
|
|
92
|
+
refreshToken: refreshResult.refreshToken,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 3. Middleware (Express)
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { JwtTokenVerifier } from "@ml-dev-core/jwt.auth";
|
|
100
|
+
|
|
101
|
+
export const authMiddleware = async (req, res, next) => {
|
|
102
|
+
try {
|
|
103
|
+
const token = req.headers.authorization?.substring(7);
|
|
104
|
+
const verifier = new JwtTokenVerifier();
|
|
105
|
+
|
|
106
|
+
const isValid = await verifier.verify(
|
|
107
|
+
token,
|
|
108
|
+
config.jwt.accessTokenSecret,
|
|
109
|
+
config.algorithm
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (!isValid) {
|
|
113
|
+
return res.status(401).json({ error: "Token inválido" });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const payload = await verifier.parsePayload(token);
|
|
117
|
+
req.user = payload;
|
|
118
|
+
next();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
res.status(401).json({ error: "Error de autenticación" });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 🏗️ Arquitectura
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
┌─────────────────────────────────────────┐
|
|
129
|
+
│ APPLICATION LAYER │
|
|
130
|
+
│ (Use Cases, DTOs, Factories) │
|
|
131
|
+
├─────────────────────────────────────────┤
|
|
132
|
+
│ DOMAIN LAYER │
|
|
133
|
+
│ (Entities, Value Objects, Ports) │
|
|
134
|
+
├─────────────────────────────────────────┤
|
|
135
|
+
│ INFRASTRUCTURE LAYER │
|
|
136
|
+
│ (JWT, Repositories, Security) │
|
|
137
|
+
├─────────────────────────────────────────┤
|
|
138
|
+
│ SHARED LAYER │
|
|
139
|
+
│ (Types, Constants, Utils) │
|
|
140
|
+
└─────────────────────────────────────────┘
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Capas y Responsabilidades
|
|
144
|
+
|
|
145
|
+
- **Domain**: Lógica de negocio pura (entities, value objects, interfaces)
|
|
146
|
+
- **Application**: Orquestación de casos de uso y DTOs
|
|
147
|
+
- **Infrastructure**: Implementaciones concretas (JWT, bcrypt, repositorios)
|
|
148
|
+
- **Shared**: Utilidades y tipos compartidos
|
|
149
|
+
|
|
150
|
+
## 📦 Exports Principales
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Factory principal
|
|
154
|
+
import { AuthServiceFactory } from "@ml-dev-core/jwt.auth";
|
|
155
|
+
|
|
156
|
+
// Casos de uso
|
|
157
|
+
import {
|
|
158
|
+
LoginWithPasswordUseCase,
|
|
159
|
+
RegisterUserUseCase,
|
|
160
|
+
RefreshTokenUseCase,
|
|
161
|
+
LogoutUseCase,
|
|
162
|
+
} from "@ml-dev-core/jwt.auth";
|
|
163
|
+
|
|
164
|
+
// DTOs
|
|
165
|
+
import {
|
|
166
|
+
LoginRequest,
|
|
167
|
+
LoginResponse,
|
|
168
|
+
RegisterUserRequest,
|
|
169
|
+
RefreshTokenRequest,
|
|
170
|
+
} from "@ml-dev-core/jwt.auth";
|
|
171
|
+
|
|
172
|
+
// Entidades del dominio
|
|
173
|
+
import { User, Credential } from "@ml-dev-core/jwt.auth";
|
|
174
|
+
|
|
175
|
+
// Value Objects
|
|
176
|
+
import { Email, HashedPassword, Role, Id } from "@ml-dev-core/jwt.auth";
|
|
177
|
+
|
|
178
|
+
// Componentes JWT
|
|
179
|
+
import { JwtTokenGenerator, JwtTokenVerifier } from "@ml-dev-core/jwt.auth";
|
|
180
|
+
|
|
181
|
+
// Implementaciones de seguridad
|
|
182
|
+
import { BcryptPasswordHasher } from "@ml-dev-core/jwt.auth";
|
|
183
|
+
|
|
184
|
+
// Repositorios in-memory (testing)
|
|
185
|
+
import {
|
|
186
|
+
InMemoryUserRepository,
|
|
187
|
+
InMemoryCredentialRepository,
|
|
188
|
+
} from "@ml-dev-core/jwt.auth";
|
|
189
|
+
|
|
190
|
+
// Interfaces
|
|
191
|
+
import {
|
|
192
|
+
IUserRepository,
|
|
193
|
+
ICredentialRepository,
|
|
194
|
+
IAuthConfig,
|
|
195
|
+
} from "@ml-dev-core/jwt.auth";
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 🔧 Configuración de Variables de Entorno
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# JWT Secrets
|
|
202
|
+
JWT_ACCESS_SECRET=your_super_secret_access_key_here
|
|
203
|
+
JWT_REFRESH_SECRET=your_super_secret_refresh_key_here
|
|
204
|
+
|
|
205
|
+
# JWT Timing
|
|
206
|
+
JWT_ACCESS_EXPIRATION=15m
|
|
207
|
+
JWT_REFRESH_EXPIRATION=7d
|
|
208
|
+
|
|
209
|
+
# JWT Info
|
|
210
|
+
JWT_ISSUER=your-app-name
|
|
211
|
+
JWT_AUDIENCE=your-client-app
|
|
212
|
+
JWT_ALGORITHM=HS256
|
|
213
|
+
|
|
214
|
+
# Security
|
|
215
|
+
BCRYPT_SALT_ROUNDS=12
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 🧪 Testing
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import {
|
|
222
|
+
AuthServiceFactory,
|
|
223
|
+
InMemoryUserRepository,
|
|
224
|
+
InMemoryCredentialRepository,
|
|
225
|
+
} from "@ml-dev-core/jwt.auth";
|
|
226
|
+
|
|
227
|
+
describe("Auth Tests", () => {
|
|
228
|
+
let authServices;
|
|
229
|
+
|
|
230
|
+
beforeEach(() => {
|
|
231
|
+
authServices = AuthServiceFactory.create(
|
|
232
|
+
testConfig,
|
|
233
|
+
new InMemoryUserRepository(),
|
|
234
|
+
new InMemoryCredentialRepository()
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("should register and login user", async () => {
|
|
239
|
+
// Test implementation
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## 📱 Frameworks Soportados
|
|
245
|
+
|
|
246
|
+
### Express.js
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
app.use("/auth", authRoutes);
|
|
250
|
+
app.use("/api", authMiddleware);
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### NestJS
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
@UseGuards(JwtAuthGuard)
|
|
257
|
+
@Controller("protected")
|
|
258
|
+
export class ProtectedController {}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Fastify
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
fastify.addHook("onRequest", authMiddleware);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## 🔐 Algoritmos JWT Soportados
|
|
268
|
+
|
|
269
|
+
- **HMAC**: HS256, HS384, HS512 (clave simétrica)
|
|
270
|
+
- **RSA**: RS256, RS384, RS512 (clave asimétrica)
|
|
271
|
+
- **ECDSA**: ES256, ES384, ES512 (curva elíptica)
|
|
272
|
+
|
|
273
|
+
## 📄 Scripts Disponibles
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Construcción
|
|
277
|
+
npm run build
|
|
278
|
+
|
|
279
|
+
# Testing
|
|
280
|
+
npm test
|
|
281
|
+
npm run test:coverage
|
|
282
|
+
npm run test:watch
|
|
283
|
+
|
|
284
|
+
# Ejemplos
|
|
285
|
+
npm run example:help # Ver todos los comandos
|
|
286
|
+
npm run example:all # Ejecutar todos los ejemplos
|
|
287
|
+
npm run example:use-cases # Ejemplos de casos de uso
|
|
288
|
+
npm run example:jwt # Ejemplos de JWT
|
|
289
|
+
npm run example:factories # Ejemplos de factories
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 📋 Roadmap
|
|
293
|
+
|
|
294
|
+
- [ ] Integración con Prisma ORM
|
|
295
|
+
- [ ] Soporte para OAuth2
|
|
296
|
+
- [ ] Rate limiting integrado
|
|
297
|
+
- [ ] Audit logging
|
|
298
|
+
- [ ] Multi-tenancy support
|
|
299
|
+
|
|
300
|
+
## 📜 Licencia
|
|
301
|
+
|
|
302
|
+
MIT © MLahuasi
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
**¿Necesitas ayuda?** Consulta la [documentación completa](./install.md) o revisa los [ejemplos](./examples/).
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BcryptPasswordHasherExample = void 0;
|
|
4
|
+
const bcrypt_password_hasher_1 = require("../src/infrastructure/security/bcrypt-password-hasher");
|
|
5
|
+
class BcryptPasswordHasherExample {
|
|
6
|
+
static async Main() {
|
|
7
|
+
console.log("=== 🔐 Ejemplo de uso: BcryptPasswordHasher ===\n");
|
|
8
|
+
// 1️⃣ Contraseñas de prueba
|
|
9
|
+
const realPassword = "MyStrongPass#123";
|
|
10
|
+
const wrongPassword = "NotTheRightPass!";
|
|
11
|
+
const anotherWrong = "123456";
|
|
12
|
+
console.log("🧾 Password real de prueba:", realPassword);
|
|
13
|
+
console.log("🧾 Password equivocada 1:", wrongPassword);
|
|
14
|
+
console.log("🧾 Password equivocada 2:", anotherWrong, "\n");
|
|
15
|
+
// 2️⃣ Instanciamos el hasher
|
|
16
|
+
const hasher = new bcrypt_password_hasher_1.BcryptPasswordHasher();
|
|
17
|
+
// 3️⃣ Generar hash bcrypt desde el password real
|
|
18
|
+
const hash = await hasher.hash(realPassword);
|
|
19
|
+
console.log("🔑 Hash generado (bcrypt):");
|
|
20
|
+
console.log(hash, "\n");
|
|
21
|
+
// 4️⃣ Verificar el hash con la contraseña correcta
|
|
22
|
+
const isValid = await hasher.compare(realPassword, hash);
|
|
23
|
+
console.log("✅ ¿La contraseña REAL coincide con el hash?");
|
|
24
|
+
console.log(" Resultado:", isValid, "\n");
|
|
25
|
+
// 5️⃣ Verificar el hash con contraseñas incorrectas
|
|
26
|
+
const isValidWrong1 = await hasher.compare(wrongPassword, hash);
|
|
27
|
+
const isValidWrong2 = await hasher.compare(anotherWrong, hash);
|
|
28
|
+
console.log("❌ ¿Una contraseña equivocada coincide con el hash?");
|
|
29
|
+
console.log(` "${wrongPassword}" ->`, isValidWrong1);
|
|
30
|
+
console.log(` "${anotherWrong}" ->`, isValidWrong2, "\n");
|
|
31
|
+
// 6️⃣ Demostrar que NO se puede obtener el password original desde el hash
|
|
32
|
+
console.log("=== 🔒 Demostración: el hash es unidireccional ===");
|
|
33
|
+
console.log("Intentando 'recuperar' la contraseña solo a partir del hash...\n");
|
|
34
|
+
console.log("⚠️ Importante: no existe ninguna función como hasher.reverse(hash).");
|
|
35
|
+
console.log("Solo podemos PROBAR contraseñas candidatas y comparar.\n");
|
|
36
|
+
// Simulamos un pequeño ataque por diccionario
|
|
37
|
+
const candidatePasswords = [
|
|
38
|
+
"password",
|
|
39
|
+
"admin",
|
|
40
|
+
"qwerty",
|
|
41
|
+
"123456",
|
|
42
|
+
wrongPassword,
|
|
43
|
+
anotherWrong,
|
|
44
|
+
// Nota: aquí a propósito NO incluimos realPassword
|
|
45
|
+
];
|
|
46
|
+
console.log("📚 Diccionario de prueba:");
|
|
47
|
+
console.log(candidatePasswords, "\n");
|
|
48
|
+
let recovered = null;
|
|
49
|
+
let attempts = 0;
|
|
50
|
+
for (const candidate of candidatePasswords) {
|
|
51
|
+
attempts++;
|
|
52
|
+
const matches = await hasher.compare(candidate, hash);
|
|
53
|
+
console.log(` 🔎 Probando candidato #${attempts}: "${candidate}" -> ${matches ? "COINCIDE" : "no coincide"}`);
|
|
54
|
+
if (matches) {
|
|
55
|
+
recovered = candidate;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
console.log("");
|
|
60
|
+
if (recovered) {
|
|
61
|
+
console.log("⚠️ El diccionario CONTENÍA la contraseña real.");
|
|
62
|
+
console.log("Se pudo descubrir porque estaba en la lista de candidatos.\n");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.log("✅ El diccionario NO contenía la contraseña real.");
|
|
66
|
+
console.log("No fue posible recuperar el valor original solo con el hash y este conjunto de candidatos.\n");
|
|
67
|
+
}
|
|
68
|
+
console.log("💡 Conclusión:");
|
|
69
|
+
console.log("- Bcrypt es una función de hash unidireccional: no se puede 'deshashear' para obtener el texto plano.");
|
|
70
|
+
console.log("- Lo único que se puede hacer es probar contraseñas candidatas con compare(password, hash).");
|
|
71
|
+
console.log("- Si la contraseña no está en el conjunto que pruebas (diccionario/fuerza bruta), no hay forma práctica de conocerla.");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.BcryptPasswordHasherExample = BcryptPasswordHasherExample;
|
|
75
|
+
// Para ejecutar este ejemplo directamente con Node (compilado a JS):
|
|
76
|
+
// (async () => {
|
|
77
|
+
// await BcryptPasswordHasherExample.Main();
|
|
78
|
+
// })();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class EntityObjectExamples {
|
|
2
|
+
static Main(): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Ejemplo demostrativo de uso de la clase Email.
|
|
5
|
+
* Muestra validaciones, comparaciones y manejo de errores.
|
|
6
|
+
*/
|
|
7
|
+
static RunEmailExample(): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Ejemplo demostrativo de uso de la clase HashedPassword.
|
|
10
|
+
* Muestra validación de formato, comparación de hashes y manejo de errores.
|
|
11
|
+
*/
|
|
12
|
+
static RunHashedPasswordExample(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Ejemplo demostrativo de uso de la clase Id.
|
|
15
|
+
* Muestra generación, comparación e instanciación manual de identificadores.
|
|
16
|
+
*/
|
|
17
|
+
static RunIdExample(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Ejemplo demostrativo de uso de la clase Permission.
|
|
20
|
+
* Muestra creación, comparación, coincidencias y manejo de errores.
|
|
21
|
+
*/
|
|
22
|
+
static RunPermissionExample(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Ejemplo demostrativo de uso de la clase Role.
|
|
25
|
+
* Muestra creación de roles, validación de roles permitidos, manejo de permisos,
|
|
26
|
+
* uso de comodines, y verificación de acciones específicas.
|
|
27
|
+
*/
|
|
28
|
+
static RunRoleExample(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Ejemplo demostrativo de uso de la entidad User.
|
|
31
|
+
* Muestra la creación, activación, desactivación y verificación de login.
|
|
32
|
+
*/
|
|
33
|
+
static RunUserExample(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Ejemplo demostrativo de uso de la entidad Credential.
|
|
36
|
+
* Muestra cómo crear, validar y reconstruir credenciales dentro del dominio.
|
|
37
|
+
*/
|
|
38
|
+
static RunCredentialExample(): Promise<void>;
|
|
39
|
+
}
|