@hemia/jwt-manager 0.0.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 +90 -0
- package/dist/hemia-jwt-manager.esm.js +5845 -0
- package/dist/hemia-jwt-manager.js +5847 -0
- package/dist/types/Enums/Enums.d.ts +1 -0
- package/dist/types/Enums/Operatives.d.ts +3 -0
- package/dist/types/config/jwt.config.d.ts +5 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mixin/jwt.mixin.d.ts +6 -0
- package/dist/types/services/jwt.service.d.ts +13 -0
- package/dist/types/types/jwt-payload.d.ts +9 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @hemia/jwt-manager
|
|
2
|
+
|
|
3
|
+
Una clase sencilla y reutilizable para la generación, validación y decodificación de tokens JWT. Ideal para gestionar autenticación basada en tokens dentro de aplicaciones Node.js.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Características principales
|
|
8
|
+
|
|
9
|
+
* Firma y verificación de tokens JWT
|
|
10
|
+
* Soporte para claves secretas personalizadas o por entorno
|
|
11
|
+
* Control del tiempo de expiración
|
|
12
|
+
* Soporte para distintos tipos de token (como "clean credentials")
|
|
13
|
+
* Decodificación sin validación
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Instalación
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @hemia/jwt-manager
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Uso básico
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { JwtManager } from '@hemia/jwt-manager';
|
|
29
|
+
|
|
30
|
+
const jwt = new JwtManager();
|
|
31
|
+
|
|
32
|
+
const token = jwt.getTokenWithoutKey({ userId: 'abc123' });
|
|
33
|
+
const decoded = jwt.validateToken(token);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### `getTokenWithoutKey(payload, expiresIn?, options?)`
|
|
41
|
+
|
|
42
|
+
Genera un token firmado con la clave definida por entorno (`JWT_SECRET`).
|
|
43
|
+
|
|
44
|
+
### `getTokenWithKey(payload, secretKey, expiresIn?, options?)`
|
|
45
|
+
|
|
46
|
+
Genera un token firmado con una clave personalizada.
|
|
47
|
+
|
|
48
|
+
### `getTokenCleanCredentials(operative, expiresIn?)`
|
|
49
|
+
|
|
50
|
+
Genera un token especial con un `accessType` para operaciones específicas (como `catalog`).
|
|
51
|
+
|
|
52
|
+
### `validateToken(token, secretKey?)`
|
|
53
|
+
|
|
54
|
+
Valida un token JWT. Si no se pasa `secretKey`, usa la interna.
|
|
55
|
+
|
|
56
|
+
### `decode(token)`
|
|
57
|
+
|
|
58
|
+
Decodifica un token sin verificar su firma. Útil para leer datos sin validar.
|
|
59
|
+
|
|
60
|
+
### `getJwtKey()`
|
|
61
|
+
|
|
62
|
+
Devuelve la clave interna usada para firmar los tokens.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Variables de entorno
|
|
67
|
+
|
|
68
|
+
```env
|
|
69
|
+
JWT_SECRET=mi_clave_super_secreta
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> ⚠️ **Importante:** No uses una clave por defecto en producción. Define `JWT_SECRET` siempre en tus entornos seguros.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Ejemplo con expiración y opciones
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const token = jwt.getTokenWithoutKey(
|
|
80
|
+
{ userId: 'abc123' },
|
|
81
|
+
'1h', // expira en 1 hora
|
|
82
|
+
{ issuer: 'hemia' }
|
|
83
|
+
);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Licencia
|
|
89
|
+
|
|
90
|
+
MIT — Desarrollado por [Hemia Technologies](https://hemia.mx)
|