@jmlq/auth 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +259 -306
- package/dist/application/dtos/index.d.ts +3 -0
- package/dist/application/dtos/index.js +19 -0
- package/dist/application/dtos/request/index.d.ts +4 -0
- package/dist/{src/application/dtos → application/dtos/request}/index.js +4 -4
- package/dist/{src/application/dtos/login.dto.d.ts → application/dtos/request/login.request.d.ts} +0 -4
- package/dist/application/dtos/request/logout.request.d.ts +3 -0
- package/dist/application/dtos/request/refresh-token.request.d.ts +3 -0
- package/dist/application/dtos/request/register-user.request.d.ts +6 -0
- package/dist/application/dtos/response/index.d.ts +4 -0
- package/dist/application/dtos/response/index.js +20 -0
- package/dist/application/dtos/response/login.response.d.ts +4 -0
- package/dist/{src/application/dtos/logout.dto.d.ts → application/dtos/response/logout.response.d.ts} +0 -3
- package/dist/{src/application/dtos/refresh-token.dto.d.ts → application/dtos/response/refresh-token.response.d.ts} +0 -3
- package/dist/application/dtos/response/register-user.response.d.ts +7 -0
- package/dist/application/dtos/type/index.d.ts +1 -0
- package/dist/{src/shared/constants → application/dtos/type}/index.js +1 -1
- package/dist/application/dtos/type/user-role.type.d.ts +4 -0
- package/dist/application/factories/auth-service.factory.d.ts +11 -0
- package/dist/application/factories/auth-service.factory.js +40 -0
- package/dist/{src/application → application}/index.d.ts +1 -0
- package/dist/{src/application → application}/index.js +1 -0
- package/dist/application/types/auth-service-factory-options.type.d.ts +5 -0
- package/dist/application/types/index.d.ts +1 -0
- package/dist/{src/infrastructure/jwt/factory → application/types}/index.js +1 -1
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.js +6 -5
- package/dist/{src/application → application}/use-cases/logout.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/logout.use-case.js +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.js +2 -2
- package/dist/application/use-cases/register-user.use-case.d.ts +12 -0
- package/dist/{src/application → application}/use-cases/register-user.use-case.js +27 -1
- package/dist/{src/domain → domain}/errors/auth.errors.d.ts +1 -14
- package/dist/{src/domain → domain}/errors/auth.errors.js +1 -15
- package/dist/{src/domain → domain}/index.d.ts +0 -1
- package/dist/{src/domain → domain}/index.js +0 -1
- package/dist/domain/ports/auth/index.d.ts +2 -0
- package/dist/domain/ports/auth/index.js +18 -0
- package/dist/{src/domain/ports/auth/password-hasher.d.ts → domain/ports/auth/password-hasher.port.d.ts} +1 -1
- package/dist/{src/domain → domain}/ports/auth/password-policy.port.d.ts +1 -1
- package/dist/domain/ports/index.d.ts +4 -0
- package/dist/{src/infrastructure/jwt → domain/ports}/index.js +3 -2
- package/dist/domain/ports/jwt/index.d.ts +1 -0
- package/dist/{src/shared/types → domain/ports/jwt}/index.js +1 -1
- package/dist/domain/ports/jwt/payload/index.d.ts +1 -0
- package/dist/domain/ports/jwt/payload/index.js +17 -0
- package/dist/{src/domain → domain}/ports/repository/credential.repository.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.js +1 -1
- package/dist/{src/domain/ports/repository/user.repository.d.ts → domain/ports/repository/user-repository.port.d.ts} +1 -1
- package/dist/domain/ports/token/index.d.ts +2 -0
- package/dist/domain/ports/token/index.js +18 -0
- package/dist/{src/domain → domain}/ports/token/token-session.port.d.ts +2 -2
- package/dist/{src/domain → domain}/ports/token/token.service.port.d.ts +2 -2
- package/dist/{src/domain → domain}/props/jwt/generate-access-token.props.d.ts +0 -2
- package/dist/{src/domain → domain}/props/jwt/generate-refresh-token.props.d.ts +0 -2
- package/dist/{src/domain/props/services → domain/props/jwt}/index.d.ts +1 -0
- package/dist/{src/domain/props/services → domain/props/jwt}/index.js +1 -0
- package/dist/{src/domain → domain}/services/password-policy.service.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.js +12 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts +2 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.js +13 -1
- package/dist/infrastructure/index.js +1 -0
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.d.ts +7 -2
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.js +7 -2
- package/dist/{src/infrastructure → infrastructure}/services/index.d.ts +0 -1
- package/dist/{src/infrastructure → infrastructure}/services/index.js +0 -1
- package/dist/infrastructure/services/token-session.service.d.ts +22 -0
- package/dist/{src/infrastructure/services/default-token-session.service.js → infrastructure/services/token-session.service.js} +30 -31
- package/dist/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/{src/infrastructure/repositories → shared}/index.js +1 -1
- package/package.json +5 -8
- package/dist/examples/bcrypt-password-hasher.example.d.ts +0 -3
- package/dist/examples/bcrypt-password-hasher.example.js +0 -78
- package/dist/examples/entity-object.example.d.ts +0 -39
- package/dist/examples/entity-object.example.js +0 -411
- package/dist/examples/factory-auth-service-example.d.ts +0 -3
- package/dist/examples/factory-auth-service-example.js +0 -84
- package/dist/examples/index.example.d.ts +0 -12
- package/dist/examples/index.example.js +0 -171
- package/dist/examples/jwt-algoritm.example.d.ts +0 -47
- package/dist/examples/jwt-algoritm.example.js +0 -447
- package/dist/examples/jwt-token-generator.example.d.ts +0 -6
- package/dist/examples/jwt-token-generator.example.js +0 -49
- package/dist/examples/jwt-verifier.example.d.ts +0 -3
- package/dist/examples/jwt-verifier.example.js +0 -80
- package/dist/examples/password-policy.example.d.ts +0 -7
- package/dist/examples/password-policy.example.js +0 -57
- package/dist/examples/service-jwt-token.example.d.ts +0 -3
- package/dist/examples/service-jwt-token.example.js +0 -154
- package/dist/examples/service-token-session.example.d.ts +0 -3
- package/dist/examples/service-token-session.example.js +0 -139
- package/dist/examples/use-case-login-with-password.example.d.ts +0 -6
- package/dist/examples/use-case-login-with-password.example.js +0 -105
- package/dist/examples/use-case-logout.example.d.ts +0 -7
- package/dist/examples/use-case-logout.example.js +0 -134
- package/dist/examples/use-case-refresh-token.example.d.ts +0 -11
- package/dist/examples/use-case-refresh-token.example.js +0 -164
- package/dist/examples/use-case-register-user.example.d.ts +0 -9
- package/dist/examples/use-case-register-user.example.js +0 -110
- package/dist/src/application/dtos/index.d.ts +0 -4
- package/dist/src/application/dtos/register-user.dto.d.ts +0 -16
- package/dist/src/application/factories/auth-service.factory.d.ts +0 -5
- package/dist/src/application/factories/auth-service.factory.js +0 -51
- package/dist/src/application/use-cases/register-user.use-case.d.ts +0 -10
- package/dist/src/domain/errors/auth-domain-error.d.ts +0 -82
- package/dist/src/domain/errors/auth-domain-error.js +0 -112
- package/dist/src/domain/ports/auth/password-policy-config.port.js +0 -10
- package/dist/src/domain/ports/config/auth-config.port.d.ts +0 -19
- package/dist/src/domain/ports/config/auth-config.port.js +0 -3
- package/dist/src/domain/ports/index.d.ts +0 -9
- package/dist/src/domain/ports/index.js +0 -25
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +0 -30
- package/dist/src/domain/ports/jwt/signature-strategy.js +0 -4
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +0 -4
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +0 -4
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +0 -8
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +0 -9
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +0 -10
- package/dist/src/domain/props/jwt/generate-token.props.js +0 -2
- package/dist/src/domain/props/jwt/index.d.ts +0 -5
- package/dist/src/domain/props/jwt/index.js +0 -21
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +0 -7
- package/dist/src/domain/props/jwt/jwt-subject.js +0 -2
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +0 -8
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +0 -8
- package/dist/src/domain/services/token.service.port.d.ts +0 -9
- package/dist/src/index.d.ts +0 -78
- package/dist/src/index.js +0 -94
- package/dist/src/infrastructure/index.d.ts +0 -5
- package/dist/src/infrastructure/index.js +0 -21
- package/dist/src/infrastructure/jwt/factory/index.d.ts +0 -1
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/strategies/index.js +0 -19
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +0 -57
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +0 -123
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +0 -59
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +0 -100
- package/dist/src/infrastructure/jwt/token/index.d.ts +0 -5
- package/dist/src/infrastructure/jwt/token/index.js +0 -21
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +0 -29
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +0 -30
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/repositories/index.d.ts +0 -1
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +0 -67
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +0 -128
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +0 -18
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/jwt-token.service.js +0 -44
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +0 -46
- package/dist/src/infrastructure/services/token-session.service.d.ts +0 -24
- package/dist/src/infrastructure/services/token-session.service.js +0 -131
- package/dist/src/infrastructure/types/auth-service-container.d.ts +0 -14
- package/dist/src/shared/constants/index.d.ts +0 -1
- package/dist/src/shared/constants/jwt-algorithms.d.ts +0 -17
- package/dist/src/shared/constants/jwt-algorithms.js +0 -23
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +0 -29
- package/dist/src/shared/encoders/base64-url-encoder.js +0 -45
- package/dist/src/shared/encoders/index.d.ts +0 -1
- package/dist/src/shared/encoders/index.js +0 -17
- package/dist/src/shared/index.d.ts +0 -4
- package/dist/src/shared/index.js +0 -20
- package/dist/src/shared/types/index.d.ts +0 -1
- package/dist/src/shared/types/jwt.d.ts +0 -25
- package/dist/src/shared/types/jwt.js +0 -2
- package/dist/src/shared/types/jwt.types.d.ts +0 -39
- package/dist/src/shared/types/jwt.types.js +0 -2
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +0 -1
- package/dist/tests/application/factory/auth-service-factory.spec.js +0 -97
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +0 -140
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/logout-use-case.spec.js +0 -40
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +0 -116
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +0 -151
- package/dist/tests/domain/entities/credential.spec.d.ts +0 -1
- package/dist/tests/domain/entities/credential.spec.js +0 -93
- package/dist/tests/domain/entities/user.spec.d.ts +0 -1
- package/dist/tests/domain/entities/user.spec.js +0 -93
- package/dist/tests/domain/object-values/email.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/email.spec.js +0 -77
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/domain/object-values/id.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/id.spec.js +0 -48
- package/dist/tests/domain/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/permission.spec.js +0 -75
- package/dist/tests/domain/object-values/role.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/role.spec.js +0 -139
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +0 -1
- package/dist/tests/domain/services/default-password-policy.spec.js +0 -69
- package/dist/tests/doman/entities/credential.spec.d.ts +0 -1
- package/dist/tests/doman/entities/credential.spec.js +0 -93
- package/dist/tests/doman/entities/user.spec.d.ts +0 -1
- package/dist/tests/doman/entities/user.spec.js +0 -93
- package/dist/tests/doman/object-values/email.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/email.spec.js +0 -77
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/doman/object-values/id.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/id.spec.js +0 -48
- package/dist/tests/doman/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/permission.spec.js +0 -75
- package/dist/tests/doman/object-values/role.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/role.spec.js +0 -139
- package/dist/tests/helpers/make-jwt-subject.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-subject.js +0 -16
- package/dist/tests/helpers/make-jwt-user.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-user.js +0 -16
- package/dist/tests/helpers/make-user.d.ts +0 -2
- package/dist/tests/helpers/make-user.js +0 -15
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +0 -127
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +0 -157
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +0 -150
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +0 -156
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +0 -179
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +0 -142
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +0 -125
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +0 -126
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +0 -1
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +0 -37
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +0 -145
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/token-session.service.spec.js +0 -269
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +0 -1
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +0 -27
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +0 -1
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +0 -70
- package/dist/tests/shared/utils/time-parser.spec.d.ts +0 -1
- package/dist/tests/shared/utils/time-parser.spec.js +0 -80
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -17
- package/dist/utils/time-parser.d.ts +0 -28
- package/dist/utils/time-parser.js +0 -76
- /package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js} +0 -0
- /package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js} +0 -0
- /package/dist/{src/application/dtos/refresh-token.dto.js → application/dtos/request/refresh-token.request.js} +0 -0
- /package/dist/{src/application/dtos/register-user.dto.js → application/dtos/request/register-user.request.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-hasher.js → application/dtos/response/login.response.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-policy.port.js → application/dtos/response/logout.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/factory/signature-strategy-factory.port.js → application/dtos/response/refresh-token.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/payload/jwt-payload.port.js → application/dtos/response/register-user.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/signature-strategy-factory.port.js → application/dtos/type/user-role.type.js} +0 -0
- /package/dist/{src/application → application}/factories/index.d.ts +0 -0
- /package/dist/{src/application → application}/factories/index.js +0 -0
- /package/dist/{src/domain/ports/repository/credential.repository.js → application/types/auth-service-factory-options.type.js} +0 -0
- /package/dist/{src/application → application}/use-cases/index.d.ts +0 -0
- /package/dist/{src/application → application}/use-cases/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.js +0 -0
- /package/dist/{src/domain → domain}/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.js +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.js +0 -0
- /package/dist/{src/domain → domain}/errors/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/email.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/email.js +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.js +0 -0
- /package/dist/{src/domain → domain}/object-values/id.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/id.js +0 -0
- /package/dist/{src/domain → domain}/object-values/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.js +0 -0
- /package/dist/{src/domain → domain}/object-values/role.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/role.js +0 -0
- /package/dist/{src/domain/ports/repository/user.repository.js → domain/ports/auth/password-hasher.port.js} +0 -0
- /package/dist/{src/domain/ports/token/token-session.port.js → domain/ports/auth/password-policy.port.js} +0 -0
- /package/dist/{src/domain → domain}/ports/jwt/payload/jwt-payload.port.d.ts +0 -0
- /package/dist/{src/domain/ports/token/token.service.port.js → domain/ports/jwt/payload/jwt-payload.port.js} +0 -0
- /package/dist/{src/domain/props/entities/credential.props.js → domain/ports/repository/credential.repository.js} +0 -0
- /package/dist/{src/domain/props/entities/user.props.js → domain/ports/repository/user-repository.port.js} +0 -0
- /package/dist/{src/domain/props/jwt/create-payload.props.js → domain/ports/token/token-session.port.js} +0 -0
- /package/dist/{src/domain/services → domain/ports/token}/token.service.port.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/credential.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-access-token.props.js → domain/props/entities/credential.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/user.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-refresh-token.props.js → domain/props/entities/user.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/index.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-access-token.props.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-refresh-token.props.js +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.js +0 -0
- /package/dist/{src/domain → domain}/services/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/services/index.js +0 -0
- /package/dist/{src/domain → domain}/services/password-policy.service.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.d.ts +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.js +0 -0
- /package/dist/{src/domain/ports/auth/password-policy-config.port.d.ts → infrastructure/index.d.ts} +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/auth-service-container.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/index.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.js +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JwtTokenGeneratorExample = void 0;
|
|
4
|
-
const jwt_1 = require("../src/infrastructure/jwt");
|
|
5
|
-
const shared_1 = require("../src/shared");
|
|
6
|
-
/**
|
|
7
|
-
* Ejemplo demostrativo del uso de JwtTokenGenerator
|
|
8
|
-
*/
|
|
9
|
-
class JwtTokenGeneratorExample {
|
|
10
|
-
static async Main() {
|
|
11
|
-
console.log("=== 🔐 Ejemplo de uso: JwtTokenGenerator ===\n");
|
|
12
|
-
// 1️⃣ Configuración del servicio JWT
|
|
13
|
-
const jwtConfig = {
|
|
14
|
-
accessTokenSecret: "ACCESS_SECRET_ABC",
|
|
15
|
-
refreshTokenSecret: "REFRESH_SECRET_DEF",
|
|
16
|
-
accessTokenExpirationMs: shared_1.TimeParser.parseToMilliseconds("15m"), // 15 minutos
|
|
17
|
-
refreshTokenExpirationMs: shared_1.TimeParser.parseToMilliseconds("7d"), // 7 días
|
|
18
|
-
issuer: "my-api",
|
|
19
|
-
audience: "my-clients",
|
|
20
|
-
algorithm: "HS256",
|
|
21
|
-
};
|
|
22
|
-
// 2️⃣ Creamos un sujeto JWT (lo que se inyecta al token)
|
|
23
|
-
const user = {
|
|
24
|
-
id: "user-123",
|
|
25
|
-
email: "john.doe@example.com",
|
|
26
|
-
roles: [{ role: "admin" }, { role: "user" }],
|
|
27
|
-
};
|
|
28
|
-
// 3️⃣ Instanciamos los componentes requeridos
|
|
29
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
30
|
-
const signer = new jwt_1.JwtSigner(encoder);
|
|
31
|
-
const generator = new jwt_1.JwtTokenGenerator(encoder, signer);
|
|
32
|
-
// 4️⃣ Generamos un access token
|
|
33
|
-
const accessToken = generator.generateAccessToken({
|
|
34
|
-
user,
|
|
35
|
-
config: jwtConfig,
|
|
36
|
-
expiresIn: "15m", // opcional, puede omitirse para usar el default del config
|
|
37
|
-
customClaims: { plan: "pro", featureFlags: ["feature1", "feature2"] },
|
|
38
|
-
});
|
|
39
|
-
// 5️⃣ Generamos un refresh token
|
|
40
|
-
const refreshToken = generator.generateRefreshToken({
|
|
41
|
-
user,
|
|
42
|
-
config: jwtConfig,
|
|
43
|
-
});
|
|
44
|
-
// 6️⃣ Mostramos los resultados
|
|
45
|
-
console.log("Access Token:\n", accessToken, "\n");
|
|
46
|
-
console.log("Refresh Token:\n", refreshToken, "\n");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.JwtTokenGeneratorExample = JwtTokenGeneratorExample;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JwtVerifierExample = void 0;
|
|
4
|
-
// example-jwt-verifier.ts
|
|
5
|
-
const errors_1 = require("../src/domain/errors");
|
|
6
|
-
const jwt_1 = require("../src/infrastructure/jwt");
|
|
7
|
-
const shared_1 = require("../src/shared");
|
|
8
|
-
class JwtVerifierExample {
|
|
9
|
-
static async Main() {
|
|
10
|
-
console.log("=== 🔍 Ejemplo de verificación de token JWT ===\n");
|
|
11
|
-
// 1️⃣ Configuración del servicio JWT
|
|
12
|
-
const config = {
|
|
13
|
-
accessTokenSecret: "super_secret_key_123",
|
|
14
|
-
refreshTokenSecret: "refresh_secret_key_456",
|
|
15
|
-
accessTokenExpirationMs: 1000 * 60 * 15, // 15 minutos
|
|
16
|
-
refreshTokenExpirationMs: 1000 * 60 * 60 * 24 * 7, // 7 días
|
|
17
|
-
accessTokenExpiration: "15m",
|
|
18
|
-
refreshTokenExpiration: "7d",
|
|
19
|
-
algorithm: "HS256",
|
|
20
|
-
issuer: "auth-service",
|
|
21
|
-
audience: "example-client",
|
|
22
|
-
};
|
|
23
|
-
// 2️⃣ Instancias necesarias
|
|
24
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
25
|
-
const signer = new jwt_1.JwtSigner(encoder);
|
|
26
|
-
const parser = new jwt_1.JwtTokenParser(encoder);
|
|
27
|
-
const verifier = new jwt_1.JwtTokenVerifier(signer, parser, config.algorithm);
|
|
28
|
-
// 3️⃣ Simular generación de token manualmente (en tu caso sería con JwtTokenGenerator)
|
|
29
|
-
const payload = {
|
|
30
|
-
sub: "user_001",
|
|
31
|
-
roles: [{ role: "user" }],
|
|
32
|
-
customClaims: { plan: "basic" },
|
|
33
|
-
iat: Math.floor(Date.now() / 1000),
|
|
34
|
-
exp: Math.floor(Date.now() / 1000) + 60, // expira en 1 min
|
|
35
|
-
jti: "token-123",
|
|
36
|
-
iss: config.issuer,
|
|
37
|
-
aud: config.audience,
|
|
38
|
-
};
|
|
39
|
-
// Generar un token JWT básico (header + payload + firma)
|
|
40
|
-
const header = { alg: config.algorithm, typ: "JWT" };
|
|
41
|
-
const encode = (obj) => Buffer.from(JSON.stringify(obj)).toString("base64url");
|
|
42
|
-
const headerPart = encode(header);
|
|
43
|
-
const payloadPart = encode(payload);
|
|
44
|
-
const signature = signer.sign(`${headerPart}.${payloadPart}`, config.accessTokenSecret, config.algorithm);
|
|
45
|
-
const token = `${headerPart}.${payloadPart}.${signature}`;
|
|
46
|
-
console.log("🪶 Token generado:");
|
|
47
|
-
console.log(token, "\n");
|
|
48
|
-
// 4️⃣ Verificar token válido
|
|
49
|
-
try {
|
|
50
|
-
const verifiedPayload = verifier.verifyAccessToken(token, config);
|
|
51
|
-
console.log("✅ Token válido. Payload decodificado:");
|
|
52
|
-
console.log(verifiedPayload);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (error instanceof errors_1.InvalidSignatureError) {
|
|
56
|
-
console.error("❌ Firma inválida:", error.message);
|
|
57
|
-
}
|
|
58
|
-
else if (error instanceof errors_1.TokenExpiredError) {
|
|
59
|
-
console.error("⏰ Token expirado:", error.message);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
console.error("⚠️ Error desconocido:", error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// 5️⃣ Simular token alterado (firma modificada)
|
|
66
|
-
const tamperedToken = token.replace(/.$/, "X"); // altera un carácter
|
|
67
|
-
try {
|
|
68
|
-
verifier.verifyAccessToken(tamperedToken, config);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (error instanceof errors_1.InvalidSignatureError) {
|
|
72
|
-
console.log("🚫 Token manipulado detectado correctamente.");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// 6️⃣ Verificar expiración manual
|
|
76
|
-
const expirationDate = verifier.getTokenExpiration(token);
|
|
77
|
-
console.log(`📅 El token expira en: ${expirationDate.toISOString()}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.JwtVerifierExample = JwtVerifierExample;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PasswordPolicyExample = void 0;
|
|
4
|
-
const domain_1 = require("../src/domain");
|
|
5
|
-
/**
|
|
6
|
-
* Ejemplo demostrativo del uso de DefaultPasswordPolicy
|
|
7
|
-
* Muestra cómo validar contraseñas según las reglas por defecto.
|
|
8
|
-
*/
|
|
9
|
-
class PasswordPolicyExample {
|
|
10
|
-
static async Main() {
|
|
11
|
-
console.log("=== 🔐 Ejemplo: DefaultPasswordPolicy ===\n");
|
|
12
|
-
// 1️⃣ Instancia de la política
|
|
13
|
-
const policy = new domain_1.DefaultPasswordPolicy();
|
|
14
|
-
// 2️⃣ Mostrar requisitos definidos
|
|
15
|
-
console.log("📋 Requisitos de la política de contraseñas:\n");
|
|
16
|
-
policy.getRequirements().forEach((req, i) => {
|
|
17
|
-
console.log(` ${i + 1}. ${req}`);
|
|
18
|
-
});
|
|
19
|
-
console.log("");
|
|
20
|
-
// 3️⃣ Lista de contraseñas de ejemplo a validar
|
|
21
|
-
const passwords = [
|
|
22
|
-
"Str0ng!Pass", // válida
|
|
23
|
-
"weakpass", // corta, sin mayúsculas, sin número, sin especial
|
|
24
|
-
"Strongpass", // sin número, sin especial
|
|
25
|
-
"STRONG!123", // sin minúscula
|
|
26
|
-
"Str0ngPass", // sin especial
|
|
27
|
-
"Str!12", // demasiado corta
|
|
28
|
-
];
|
|
29
|
-
console.log("🔎 Validando contraseñas...\n");
|
|
30
|
-
// 4️⃣ Validar cada contraseña e imprimir resultados
|
|
31
|
-
for (const pwd of passwords) {
|
|
32
|
-
const result = policy.validateStrength(pwd);
|
|
33
|
-
const status = result.isValid ? "✅ Válida" : "❌ Inválida";
|
|
34
|
-
console.log(`🧩 Contraseña: "${pwd}" → ${status}`);
|
|
35
|
-
if (!result.isValid) {
|
|
36
|
-
console.log(" Motivos:");
|
|
37
|
-
result.errors.forEach((err) => console.log(" - " + err));
|
|
38
|
-
}
|
|
39
|
-
console.log(""); // línea en blanco
|
|
40
|
-
}
|
|
41
|
-
// 5️⃣ Mostrar un ejemplo de uso en una validación de registro
|
|
42
|
-
const newUserPassword = "UserPass1";
|
|
43
|
-
console.log("=== 🧠 Ejemplo de validación en un flujo de registro ===\n");
|
|
44
|
-
console.log(`Intentando registrar usuario con contraseña: "${newUserPassword}"`);
|
|
45
|
-
const validation = policy.validateStrength(newUserPassword);
|
|
46
|
-
if (!validation.isValid) {
|
|
47
|
-
console.log("⚠️ La contraseña no cumple los requisitos:");
|
|
48
|
-
validation.errors.forEach((err) => console.log(" - " + err));
|
|
49
|
-
console.log("\n❌ Registro rechazado.");
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
console.log("✅ Contraseña válida. Registro permitido.");
|
|
53
|
-
}
|
|
54
|
-
console.log("\n=== Fin del ejemplo ===");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.PasswordPolicyExample = PasswordPolicyExample;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// examples/example-jwt-token-service.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.JwtTokenServiceExample = void 0;
|
|
5
|
-
const domain_1 = require("../src/domain");
|
|
6
|
-
const errors_1 = require("../src/domain/errors");
|
|
7
|
-
const jwt_1 = require("../src/infrastructure/jwt");
|
|
8
|
-
const test_1 = require("../src/infrastructure/repositories/test");
|
|
9
|
-
const jwt_token_service_1 = require("../src/infrastructure/services/jwt-token.service");
|
|
10
|
-
const shared_1 = require("../src/shared");
|
|
11
|
-
class JwtTokenServiceExample {
|
|
12
|
-
static async Main() {
|
|
13
|
-
console.log("=== 🧩 Ejemplo de uso de JwtTokenService con revocación ===\n");
|
|
14
|
-
// 1️⃣ Configuración central del servicio JWT
|
|
15
|
-
const config = {
|
|
16
|
-
accessTokenSecret: "super_secret_key_123",
|
|
17
|
-
refreshTokenSecret: "refresh_secret_key_456",
|
|
18
|
-
accessTokenExpirationMs: 1000 * 60 * 15, // 15 minutos
|
|
19
|
-
refreshTokenExpirationMs: 1000 * 60 * 60 * 24 * 7, // 7 días
|
|
20
|
-
accessTokenExpiration: "15m",
|
|
21
|
-
refreshTokenExpiration: "7d",
|
|
22
|
-
algorithm: "HS256",
|
|
23
|
-
issuer: "auth-service",
|
|
24
|
-
audience: "example-client",
|
|
25
|
-
};
|
|
26
|
-
// 2️⃣ Instanciar componentes de infraestructura
|
|
27
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
28
|
-
const signer = new jwt_1.JwtSigner(encoder);
|
|
29
|
-
const parser = new jwt_1.JwtTokenParser(encoder);
|
|
30
|
-
const verifier = new jwt_1.JwtTokenVerifier(signer, parser, config.algorithm);
|
|
31
|
-
const validator = new jwt_1.JwtTokenValidator();
|
|
32
|
-
const generator = new jwt_1.JwtTokenGenerator(encoder, signer);
|
|
33
|
-
const tokenService = new jwt_token_service_1.JwtTokenService(config, generator, verifier, validator);
|
|
34
|
-
// 3️⃣ Repositorios en memoria (usuarios y credenciales)
|
|
35
|
-
const userRepo = new test_1.InMemoryUserRepository();
|
|
36
|
-
const credentialRepo = new test_1.InMemoryCredentialRepository();
|
|
37
|
-
// 4️⃣ Definir datos de ejemplo del usuario
|
|
38
|
-
const rawId = "user_001";
|
|
39
|
-
const rawEmail = "user@email.com";
|
|
40
|
-
const roles = [{ role: "user" }];
|
|
41
|
-
const customClaims = { plan: "basic", featureFlags: ["beta-dashboard"] };
|
|
42
|
-
// ⚠️ Ajusta estas construcciones a tus VO reales (Email / Id / User)
|
|
43
|
-
const userId = new domain_1.Id(rawId);
|
|
44
|
-
const email = new domain_1.Email(rawEmail);
|
|
45
|
-
const user = new domain_1.User({
|
|
46
|
-
id: userId,
|
|
47
|
-
email,
|
|
48
|
-
roles,
|
|
49
|
-
// Añade aquí cualquier otro campo requerido por tu constructor de User
|
|
50
|
-
// password, createdAt, updatedAt, etc.
|
|
51
|
-
}); // Usa 'as any' solo si tu constructor requiere más campos
|
|
52
|
-
await userRepo.save(user);
|
|
53
|
-
const accessProps = {
|
|
54
|
-
user: {
|
|
55
|
-
id: rawId,
|
|
56
|
-
email: rawEmail,
|
|
57
|
-
roles,
|
|
58
|
-
},
|
|
59
|
-
config,
|
|
60
|
-
expiresIn: config.accessTokenExpiration,
|
|
61
|
-
customClaims,
|
|
62
|
-
};
|
|
63
|
-
const refreshProps = {
|
|
64
|
-
user: {
|
|
65
|
-
id: rawId,
|
|
66
|
-
email: rawEmail,
|
|
67
|
-
roles,
|
|
68
|
-
},
|
|
69
|
-
config,
|
|
70
|
-
expiresIn: config.refreshTokenExpiration,
|
|
71
|
-
customClaims,
|
|
72
|
-
};
|
|
73
|
-
// 5️⃣ Generar tokens
|
|
74
|
-
console.log("→ Generando access token y refresh token...\n");
|
|
75
|
-
const accessToken = await tokenService.generateAccessToken(accessProps);
|
|
76
|
-
const refreshToken = await tokenService.generateRefreshToken(refreshProps);
|
|
77
|
-
console.log("🔑 Access token:");
|
|
78
|
-
console.log(accessToken, "\n");
|
|
79
|
-
console.log("🔁 Refresh token:");
|
|
80
|
-
console.log(refreshToken, "\n");
|
|
81
|
-
// 6️⃣ Guardar credenciales en el repositorio (simula creación de sesión)
|
|
82
|
-
const expiresAt = await tokenService.getTokenExpiration(accessToken);
|
|
83
|
-
const credential = new domain_1.Credential({
|
|
84
|
-
userId,
|
|
85
|
-
accessToken,
|
|
86
|
-
refreshToken,
|
|
87
|
-
expiresAt,
|
|
88
|
-
createdAt: new Date(),
|
|
89
|
-
});
|
|
90
|
-
await credentialRepo.save(credential);
|
|
91
|
-
console.log("💾 Credenciales guardadas en InMemoryCredentialRepository.\n");
|
|
92
|
-
// 7️⃣ Verificar tokens y obtener payloads
|
|
93
|
-
console.log("→ Verificando tokens...\n");
|
|
94
|
-
try {
|
|
95
|
-
const accessPayload = await tokenService.verifyAccessToken(accessToken);
|
|
96
|
-
console.log("✅ Access token válido. Payload:");
|
|
97
|
-
console.log(accessPayload, "\n");
|
|
98
|
-
const refreshPayload = await tokenService.verifyRefreshToken(refreshToken);
|
|
99
|
-
console.log("✅ Refresh token válido. Payload:");
|
|
100
|
-
console.log(refreshPayload, "\n");
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (error instanceof errors_1.InvalidSignatureError) {
|
|
104
|
-
console.error("❌ Firma inválida:", error.message);
|
|
105
|
-
}
|
|
106
|
-
else if (error instanceof errors_1.TokenExpiredError) {
|
|
107
|
-
console.error("⏰ Token expirado:", error.message);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
console.error("⚠️ Error verificando tokens:", error);
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// 8️⃣ Simular token manipulado (detección de firma inválida)
|
|
115
|
-
console.log("→ Probando detección de token manipulado...\n");
|
|
116
|
-
const tamperedAccessToken = accessToken.replace(/.$/, "X"); // altera 1 carácter
|
|
117
|
-
try {
|
|
118
|
-
await tokenService.verifyAccessToken(tamperedAccessToken);
|
|
119
|
-
console.log("⚠️ Esto no debería ocurrir, token manipulado aceptado.");
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
if (error instanceof errors_1.InvalidSignatureError) {
|
|
123
|
-
console.log("🚫 Token manipulado detectado correctamente.\n");
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
console.error("⚠️ Error distinto al esperado:", error, "\n");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// 9️⃣ Revocación de token: eliminar credencial por refresh token (logout)
|
|
130
|
-
console.log("→ Simulando logout: revocando refresh token...\n");
|
|
131
|
-
await credentialRepo.deleteByRefreshToken(refreshToken);
|
|
132
|
-
console.log("🚪 Refresh token revocado (credencial eliminada).\n");
|
|
133
|
-
// 🔟 Intentar usar un refresh token revocado
|
|
134
|
-
console.log("→ Intentando verificar un refresh token revocado...\n");
|
|
135
|
-
// Paso típico en un use case de refresh:
|
|
136
|
-
// 1) Buscar credencial por refresh token
|
|
137
|
-
const storedCredential = await credentialRepo.findByRefreshToken(refreshToken);
|
|
138
|
-
if (!storedCredential) {
|
|
139
|
-
console.log("✅ Refresh token no tiene credencial asociada: se considera revocado.\n");
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// Si existiera, recién aquí permitirías verificarlo:
|
|
143
|
-
try {
|
|
144
|
-
const payload = await tokenService.verifyRefreshToken(refreshToken);
|
|
145
|
-
console.log("⚠️ Esto no debería ocurrir (token debería estar revocado). Payload:", payload);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
console.error("⚠️ Error inesperado al verificar refresh token tras revocación:", error);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
console.log("=== 🧩 Fin del ejemplo JwtTokenService con revocación ===");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.JwtTokenServiceExample = JwtTokenServiceExample;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// examples/example-token-session-service.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TokenSessionServiceExample = void 0;
|
|
5
|
-
const domain_1 = require("../src/domain");
|
|
6
|
-
const errors_1 = require("../src/domain/errors");
|
|
7
|
-
const jwt_1 = require("../src/infrastructure/jwt");
|
|
8
|
-
const repositories_1 = require("../src/infrastructure/repositories");
|
|
9
|
-
const services_1 = require("../src/infrastructure/services");
|
|
10
|
-
const shared_1 = require("../src/shared");
|
|
11
|
-
class TokenSessionServiceExample {
|
|
12
|
-
static async Main() {
|
|
13
|
-
console.log("=== 🔐 Ejemplo de uso de TokenSessionService ===\n");
|
|
14
|
-
// 1️⃣ Configuración central del servicio JWT
|
|
15
|
-
const accessTokenSecret = "super_secret_key_123";
|
|
16
|
-
const refreshTokenSecret = "refresh_secret_key_456";
|
|
17
|
-
const accessTokenExpiration = "15m";
|
|
18
|
-
const refreshTokenExpiration = "7d";
|
|
19
|
-
const jwtConfig = {
|
|
20
|
-
accessTokenSecret,
|
|
21
|
-
refreshTokenSecret,
|
|
22
|
-
accessTokenExpirationMs: 1000 * 60 * 15, // 15 minutos
|
|
23
|
-
refreshTokenExpirationMs: 1000 * 60 * 60 * 24 * 7, // 7 días
|
|
24
|
-
accessTokenExpiration,
|
|
25
|
-
refreshTokenExpiration,
|
|
26
|
-
algorithm: "HS256",
|
|
27
|
-
issuer: "auth-service",
|
|
28
|
-
audience: "example-client",
|
|
29
|
-
// appName u otros campos si tu tipo los requiere
|
|
30
|
-
};
|
|
31
|
-
// 2️⃣ Instanciar componentes de infraestructura JWT
|
|
32
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
33
|
-
const signer = new jwt_1.JwtSigner(encoder);
|
|
34
|
-
const parser = new jwt_1.JwtTokenParser(encoder);
|
|
35
|
-
const verifier = new jwt_1.JwtTokenVerifier(signer, parser, jwtConfig.algorithm);
|
|
36
|
-
const validator = new jwt_1.JwtTokenValidator();
|
|
37
|
-
const generator = new jwt_1.JwtTokenGenerator(encoder, signer);
|
|
38
|
-
const tokenService = new services_1.JwtTokenService(jwtConfig, generator, verifier, validator);
|
|
39
|
-
// 3️⃣ Repositorios en memoria
|
|
40
|
-
const userRepo = new repositories_1.InMemoryUserRepository();
|
|
41
|
-
const credentialRepo = new repositories_1.InMemoryCredentialRepository();
|
|
42
|
-
// 4️⃣ Servicio de sesiones basado en JWT
|
|
43
|
-
const sessionService = new services_1.TokenSessionService(tokenService, userRepo, credentialRepo, jwtConfig.algorithm, accessTokenExpiration, refreshTokenExpiration, accessTokenSecret, refreshTokenSecret);
|
|
44
|
-
// 5️⃣ Crear un usuario de ejemplo y guardarlo en el repositorio
|
|
45
|
-
const rawUserId = "user_001";
|
|
46
|
-
const rawEmail = "user@example.com";
|
|
47
|
-
const id = new domain_1.Id(rawUserId);
|
|
48
|
-
const email = new domain_1.Email(rawEmail);
|
|
49
|
-
// ⚠️ Ajusta esta construcción según el constructor real de tu entidad User
|
|
50
|
-
const user = new domain_1.User({
|
|
51
|
-
id,
|
|
52
|
-
email,
|
|
53
|
-
roles: [], // o [Role.create('USER')] según tu modelo
|
|
54
|
-
isActive: true,
|
|
55
|
-
createdAt: new Date(),
|
|
56
|
-
updatedAt: new Date(),
|
|
57
|
-
});
|
|
58
|
-
await userRepo.save(user);
|
|
59
|
-
console.log("👤 Usuario creado y guardado en InMemoryUserRepository.\n");
|
|
60
|
-
// 6️⃣ Crear una sesión (equivalente a login)
|
|
61
|
-
console.log("→ Creando sesión (login)...\n");
|
|
62
|
-
const credential = await sessionService.createSession(user);
|
|
63
|
-
console.log("✅ Sesión creada. Credential:");
|
|
64
|
-
console.log({
|
|
65
|
-
userId: credential.userId.toString(),
|
|
66
|
-
accessToken: credential.accessToken,
|
|
67
|
-
refreshToken: credential.refreshToken,
|
|
68
|
-
expiresAt: credential.expiresAt,
|
|
69
|
-
});
|
|
70
|
-
console.log();
|
|
71
|
-
const accessToken = credential.accessToken;
|
|
72
|
-
const refreshToken = credential.refreshToken;
|
|
73
|
-
// 7️⃣ Validar sesión (access token)
|
|
74
|
-
console.log("→ Validando sesión con access token...\n");
|
|
75
|
-
const validatedUser = await sessionService.validateSession(accessToken);
|
|
76
|
-
if (validatedUser) {
|
|
77
|
-
console.log("✅ Sesión válida. Usuario:");
|
|
78
|
-
console.log({
|
|
79
|
-
id: validatedUser.id.toString(),
|
|
80
|
-
email: validatedUser.email.toString(),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
console.log("❌ Sesión inválida o usuario no puede iniciar sesión.");
|
|
85
|
-
}
|
|
86
|
-
console.log();
|
|
87
|
-
// 8️⃣ Refrescar sesión (rotación de tokens)
|
|
88
|
-
console.log("→ Refrescando sesión con refresh token...\n");
|
|
89
|
-
try {
|
|
90
|
-
const newCredential = await sessionService.refreshSession(refreshToken);
|
|
91
|
-
console.log("✅ Sesión refrescada. Nueva Credential:");
|
|
92
|
-
console.log({
|
|
93
|
-
userId: newCredential.userId.toString(),
|
|
94
|
-
accessToken: newCredential.accessToken,
|
|
95
|
-
refreshToken: newCredential.refreshToken,
|
|
96
|
-
expiresAt: newCredential.expiresAt,
|
|
97
|
-
});
|
|
98
|
-
console.log("\n📌 Nota: la credencial antigua asociada al refresh token anterior fue eliminada (rotación).");
|
|
99
|
-
// Opcional: comprobar que la credencial vieja ya no existe
|
|
100
|
-
const oldCredential = await credentialRepo.findByRefreshToken(refreshToken);
|
|
101
|
-
console.log("\n🔍 ¿Existe aún la credencial con el refresh token antiguo?", oldCredential ? "Sí (algo va mal)" : "No (rotación correcta)");
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (error instanceof errors_1.InvalidOrExpiredRefreshTokenError) {
|
|
105
|
-
console.error("❌ Refresh token inválido o expirado.");
|
|
106
|
-
}
|
|
107
|
-
else if (error instanceof errors_1.UserNotFoundError) {
|
|
108
|
-
console.error("❌ Usuario no encontrado al refrescar la sesión.");
|
|
109
|
-
}
|
|
110
|
-
else if (error instanceof errors_1.UserDisabledError) {
|
|
111
|
-
console.error("❌ Usuario deshabilitado, no se puede refrescar la sesión.");
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
console.error("⚠️ Error inesperado al refrescar sesión:", error);
|
|
115
|
-
}
|
|
116
|
-
console.log();
|
|
117
|
-
}
|
|
118
|
-
// 9️⃣ Revocar sesión (logout)
|
|
119
|
-
console.log("\n→ Revocando sesión (logout) usando el refresh token...\n");
|
|
120
|
-
await sessionService.revokeSession(refreshToken);
|
|
121
|
-
console.log("🚪 Sesión revocada: se eliminó la credencial asociada a ese refresh token.\n");
|
|
122
|
-
// 🔟 Intentar refrescar sesión con un refresh token revocado
|
|
123
|
-
console.log("→ Intentando refrescar sesión con un refresh token revocado...\n");
|
|
124
|
-
try {
|
|
125
|
-
await sessionService.refreshSession(refreshToken);
|
|
126
|
-
console.log("⚠️ Esto no debería ocurrir: se aceptó un refresh token revocado.");
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
if (error instanceof errors_1.InvalidOrExpiredRefreshTokenError) {
|
|
130
|
-
console.log("✅ Refresh token revocado o inválido detectado correctamente.");
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
console.error("⚠️ Error inesperado al refrescar con token revocado:", error);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
console.log("\n=== 🔐 Fin del ejemplo TokenSessionService ===");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.TokenSessionServiceExample = TokenSessionServiceExample;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UseCaseLoginWithPasswordExample = void 0;
|
|
4
|
-
// src/examples/login-with-password.example.ts
|
|
5
|
-
const application_1 = require("../src/application");
|
|
6
|
-
const domain_1 = require("../src/domain");
|
|
7
|
-
const infrastructure_1 = require("../src/infrastructure");
|
|
8
|
-
/**
|
|
9
|
-
* FakeTokenSession usa InMemoryCredentialRepository para simular
|
|
10
|
-
* la creación y persistencia de una sesión JWT.
|
|
11
|
-
*/
|
|
12
|
-
class FakeTokenSession {
|
|
13
|
-
constructor(credentialRepo) {
|
|
14
|
-
this.credentialRepo = credentialRepo;
|
|
15
|
-
}
|
|
16
|
-
async createSession(user) {
|
|
17
|
-
const credential = new domain_1.Credential({
|
|
18
|
-
userId: user.id,
|
|
19
|
-
accessToken: `access-${user.id.getValue()}`,
|
|
20
|
-
refreshToken: `refresh-${user.id.getValue()}`,
|
|
21
|
-
expiresAt: new Date(Date.now() + 15 * 60 * 1000), // 15 min
|
|
22
|
-
createdAt: new Date(),
|
|
23
|
-
});
|
|
24
|
-
await this.credentialRepo.save(credential);
|
|
25
|
-
return credential;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Clase demostrativa del flujo completo de Login con password.
|
|
30
|
-
*/
|
|
31
|
-
class UseCaseLoginWithPasswordExample {
|
|
32
|
-
static async Main() {
|
|
33
|
-
console.log("=== 🔐 Ejemplo: Login con contraseña ===\n");
|
|
34
|
-
// Dependencias
|
|
35
|
-
const userRepo = new infrastructure_1.InMemoryUserRepository();
|
|
36
|
-
const credentialRepo = new infrastructure_1.InMemoryCredentialRepository();
|
|
37
|
-
const passwordHasher = new infrastructure_1.BcryptPasswordHasher();
|
|
38
|
-
const tokenSession = new FakeTokenSession(credentialRepo);
|
|
39
|
-
// Caso de uso principal
|
|
40
|
-
const loginUseCase = new application_1.LoginWithPasswordUseCase(userRepo, passwordHasher, tokenSession);
|
|
41
|
-
// 1️⃣ Registramos un usuario simulado
|
|
42
|
-
const email = new domain_1.Email("demo@example.com");
|
|
43
|
-
const plainPassword = "MySecret123!";
|
|
44
|
-
const hashedPassword = await passwordHasher.hash(plainPassword);
|
|
45
|
-
const user = new domain_1.User({
|
|
46
|
-
id: new domain_1.Id("user-001"),
|
|
47
|
-
email,
|
|
48
|
-
password: new domain_1.HashedPassword(hashedPassword),
|
|
49
|
-
isActive: true,
|
|
50
|
-
roles: [new domain_1.Role("user")],
|
|
51
|
-
createdAt: new Date(),
|
|
52
|
-
updatedAt: new Date(),
|
|
53
|
-
});
|
|
54
|
-
await userRepo.save(user);
|
|
55
|
-
console.log("→ Usuario registrado:", user.email.toString());
|
|
56
|
-
// 2️⃣ Preparamos la solicitud de login
|
|
57
|
-
const request = {
|
|
58
|
-
email: "demo@example.com",
|
|
59
|
-
password: plainPassword,
|
|
60
|
-
};
|
|
61
|
-
// 3️⃣ Ejecutamos el caso de uso
|
|
62
|
-
const response = await loginUseCase.execute(request);
|
|
63
|
-
console.log("\n✅ Login exitoso:");
|
|
64
|
-
console.log("Access Token:", response.accessToken);
|
|
65
|
-
console.log("Refresh Token:", response.refreshToken);
|
|
66
|
-
// 4️⃣ Verificamos que la sesión se guardó en memoria
|
|
67
|
-
const stored = await credentialRepo.findByUserId(user.id);
|
|
68
|
-
console.log("\n🗝️ Sesión almacenada en memoria:", stored);
|
|
69
|
-
// 5️⃣ Intento de login con usuario no existente
|
|
70
|
-
const nonExistentRequest = {
|
|
71
|
-
email: "unknown@example.com",
|
|
72
|
-
password: "Whatever123!",
|
|
73
|
-
};
|
|
74
|
-
try {
|
|
75
|
-
console.log("\n🚫 Intentando login con usuario no existente...");
|
|
76
|
-
await loginUseCase.execute(nonExistentRequest);
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (error instanceof domain_1.UserNotFoundError) {
|
|
80
|
-
console.error("❌ Error esperado:", error.message);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
console.error("⚠️ Error inesperado:", error);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// 6 Intento de login con contraseña incorrecta
|
|
87
|
-
const wrongPasswordRequest = {
|
|
88
|
-
email: "demo@example.com",
|
|
89
|
-
password: "WrongPassword!",
|
|
90
|
-
};
|
|
91
|
-
try {
|
|
92
|
-
console.log("\n🚫 Intentando login con contraseña incorrecta...");
|
|
93
|
-
await loginUseCase.execute(wrongPasswordRequest);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
if (error instanceof domain_1.PasswordMismatchError) {
|
|
97
|
-
console.error("❌ Error esperado:", error.message);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
console.error("⚠️ Error inesperado:", error);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.UseCaseLoginWithPasswordExample = UseCaseLoginWithPasswordExample;
|