@lykosjs/jwt 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +332 -3
- package/dist/extract-bearer.d.ts +5 -0
- package/dist/extract-bearer.js +13 -0
- package/dist/extract-bearer.js.map +1 -0
- package/dist/extract-cookie.d.ts +5 -0
- package/dist/extract-cookie.js +26 -0
- package/dist/extract-cookie.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt-manager.d.ts +27 -0
- package/dist/jwt-manager.js +123 -0
- package/dist/jwt-manager.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zen Allaham - LykosJS - @lykosjs/jwt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO ELYKOS SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,332 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# 🔑 @lykosjs/jwt
|
|
2
|
+
|
|
3
|
+
**A secure, lightweight, and TypeScript-first JWT manager for Bun and modern JavaScript runtimes.**
|
|
4
|
+
|
|
5
|
+
`@lykosjs/jwt` provides a simple API for signing and verifying access and refresh tokens, rotating refresh tokens, and extracting tokens from `Authorization` and `Cookie` headers.
|
|
6
|
+
|
|
7
|
+
Designed with security-conscious defaults and predictable behavior, it can be used independently or alongside the LykosJS framework.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@lykosjs/jwt)
|
|
10
|
+
[](https://www.npmjs.com/package/@lykosjs/jwt)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## ✨ Features
|
|
17
|
+
|
|
18
|
+
- **Access and refresh tokens** — Separate secrets and lifetimes for each token type.
|
|
19
|
+
- **Token type protection** — A refresh token can never be accepted as an access token, and vice versa.
|
|
20
|
+
- **Refresh token rotation** — Verify a refresh token and issue a brand new pair in one call.
|
|
21
|
+
- **Algorithm pinning** — Only the configured algorithm is accepted on verification.
|
|
22
|
+
- **Issuer and audience** — Optionally added on signing and required on verification.
|
|
23
|
+
- **Strict secret validation** — Secrets must be different and at least 32 characters by default.
|
|
24
|
+
- **Two verification styles** — `verify*` returns `null`, `assert*` throws `HttpError(401)`.
|
|
25
|
+
- **Header helpers** — Extract tokens from `Authorization: Bearer` and `Cookie` headers.
|
|
26
|
+
- **TypeScript support** — Generic payload typing and exported configuration types.
|
|
27
|
+
|
|
28
|
+
## 📦 Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bun add @lykosjs/jwt
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with npm:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @lykosjs/jwt
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`lykosjs` is a peer dependency and must be installed in your project.
|
|
41
|
+
|
|
42
|
+
## 🚀 Quick start
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { JwtManager } from '@lykosjs/jwt'
|
|
46
|
+
|
|
47
|
+
interface AuthPayload extends Record<string, unknown> {
|
|
48
|
+
id: number
|
|
49
|
+
role: 'user' | 'admin'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const jwt = new JwtManager<AuthPayload>({
|
|
53
|
+
accessToken: { secret: process.env.ACCESS_SECRET!, expiresIn: '15m' },
|
|
54
|
+
refreshToken: { secret: process.env.REFRESH_SECRET!, expiresIn: '30d' },
|
|
55
|
+
issuer: 'my-app',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Login: issue a token pair
|
|
59
|
+
const { accessToken, refreshToken } = jwt.signPair({ id: 1, role: 'user' })
|
|
60
|
+
|
|
61
|
+
// Protect a route: returns the payload or throws HttpError(401)
|
|
62
|
+
const user = jwt.assertAccessToken(accessToken)
|
|
63
|
+
|
|
64
|
+
// Refresh: returns a brand new pair
|
|
65
|
+
const next = jwt.refresh(refreshToken)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 📖 API reference
|
|
69
|
+
|
|
70
|
+
### `JwtManager`
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
new JwtManager<TPayload>(config: JwtConfig)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The constructor throws `HttpError(500)` when a secret is missing, when both secrets are identical, or when a secret is shorter than `minSecretLength`.
|
|
77
|
+
|
|
78
|
+
### `signAccessToken()` / `signRefreshToken()`
|
|
79
|
+
|
|
80
|
+
Sign a single token of the given type.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const accessToken = jwt.signAccessToken({ id: 1, role: 'user' })
|
|
84
|
+
const refreshToken = jwt.signRefreshToken({ id: 1, role: 'user' })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Reserved claims (`iat`, `exp`, `nbf`, `iss`, `aud`) in the payload are ignored, so they cannot conflict with the configured options.
|
|
88
|
+
|
|
89
|
+
### `signPair()`
|
|
90
|
+
|
|
91
|
+
Signs an access token and a refresh token for the same payload.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const { accessToken, refreshToken } = jwt.signPair({ id: 1, role: 'user' })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `verifyAccessToken()` / `verifyRefreshToken()`
|
|
98
|
+
|
|
99
|
+
Return the payload, or `null` if the token is invalid, expired, tampered with, or of the wrong type. They never throw.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const payload = jwt.verifyAccessToken(token)
|
|
103
|
+
|
|
104
|
+
if (payload === null) {
|
|
105
|
+
// Invalid or expired token.
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `assertAccessToken()` / `assertRefreshToken()`
|
|
110
|
+
|
|
111
|
+
Like the `verify*` methods, but throw `HttpError(401)` on failure. They also accept `null` and `undefined`, which makes them convenient to combine with the header helpers.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const user = jwt.assertAccessToken(extractBearerToken(header))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `refresh()`
|
|
118
|
+
|
|
119
|
+
Verifies a refresh token and issues a new access and refresh token pair (refresh token rotation). Throws `HttpError(401)` if the refresh token is invalid.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const { accessToken, refreshToken } = jwt.refresh(oldRefreshToken)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `decode()`
|
|
126
|
+
|
|
127
|
+
Decodes a token **without verifying it**.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const payload = jwt.decode(token)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Security note:** Never use the result of `decode()` for authentication or authorization. Use it only for non-sensitive purposes, such as reading an expiry time on the client side.
|
|
134
|
+
|
|
135
|
+
### `extractBearerToken()`
|
|
136
|
+
|
|
137
|
+
Extracts the token from an `Authorization: Bearer <token>` header value. Returns `null` when the header is missing or malformed.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { extractBearerToken } from '@lykosjs/jwt'
|
|
141
|
+
|
|
142
|
+
const token = extractBearerToken(request.headers.get('authorization'))
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### `extractCookieToken()`
|
|
146
|
+
|
|
147
|
+
Extracts a token from a `Cookie` header by cookie name. Returns `null` when the cookie is missing, empty, or malformed.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { extractCookieToken } from '@lykosjs/jwt'
|
|
151
|
+
|
|
152
|
+
const token = extractCookieToken(request.headers.get('cookie'), 'refreshToken')
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This function reads a cookie value only. It does not verify anything, so pass the result to `assertRefreshToken()` or `verifyRefreshToken()`.
|
|
156
|
+
|
|
157
|
+
## ⚙️ Configuration
|
|
158
|
+
|
|
159
|
+
### `JwtConfig`
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
export interface JwtConfig {
|
|
163
|
+
accessToken: TokenConfig
|
|
164
|
+
refreshToken: TokenConfig
|
|
165
|
+
issuer?: string
|
|
166
|
+
audience?: string
|
|
167
|
+
algorithm?:
|
|
168
|
+
| 'HS256'
|
|
169
|
+
| 'HS384'
|
|
170
|
+
| 'HS512'
|
|
171
|
+
| 'RS256'
|
|
172
|
+
| 'RS384'
|
|
173
|
+
| 'RS512'
|
|
174
|
+
| 'ES256'
|
|
175
|
+
| 'ES384'
|
|
176
|
+
| 'ES512'
|
|
177
|
+
| 'EdDSA'
|
|
178
|
+
minSecretLength?: number
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface TokenConfig {
|
|
182
|
+
secret: string
|
|
183
|
+
expiresIn?: string | number
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| Option | Default | Description |
|
|
188
|
+
| ------------------------ | --------- | ------------------------------------------------------ |
|
|
189
|
+
| `accessToken.secret` | required | Secret used to sign and verify access tokens |
|
|
190
|
+
| `accessToken.expiresIn` | `'15m'` | Access token lifetime |
|
|
191
|
+
| `refreshToken.secret` | required | Secret used to sign and verify refresh tokens |
|
|
192
|
+
| `refreshToken.expiresIn` | `'30d'` | Refresh token lifetime |
|
|
193
|
+
| `issuer` | none | Added as `iss` and required on verification |
|
|
194
|
+
| `audience` | none | Added as `aud` and required on verification |
|
|
195
|
+
| `algorithm` | `'HS256'` | The only algorithm accepted on verification |
|
|
196
|
+
| `minSecretLength` | `32` | Minimum secret length. Set to `0` to disable the check |
|
|
197
|
+
|
|
198
|
+
`expiresIn` accepts a duration string such as `'15m'` or `'30d'`, or a number of seconds.
|
|
199
|
+
|
|
200
|
+
## 🔐 Security best practices
|
|
201
|
+
|
|
202
|
+
### 1. Use strong, separate secrets
|
|
203
|
+
|
|
204
|
+
Generate a random secret for each token type:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
bun -e "console.log(crypto.randomBytes(32).toString('base64url'))"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```env
|
|
211
|
+
ACCESS_SECRET=your_generated_access_secret
|
|
212
|
+
REFRESH_SECRET=your_generated_refresh_secret
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Never commit real secrets to version control.
|
|
216
|
+
|
|
217
|
+
### 2. Keep access tokens short-lived
|
|
218
|
+
|
|
219
|
+
A short access token lifetime limits the damage of a leaked token. Use the refresh token to obtain new access tokens.
|
|
220
|
+
|
|
221
|
+
### 3. Store refresh tokens in HttpOnly cookies
|
|
222
|
+
|
|
223
|
+
For browser applications, keep the refresh token in an `HttpOnly`, `Secure` cookie so JavaScript cannot read it. See the example below using `@lykosjs/cookie`.
|
|
224
|
+
|
|
225
|
+
### 4. Rotation does not revoke old tokens
|
|
226
|
+
|
|
227
|
+
`refresh()` issues a new pair, but the previous refresh token stays valid until it expires. For full revocation, store token or session identifiers on the server and check them on every refresh.
|
|
228
|
+
|
|
229
|
+
### 5. Do not put sensitive data in the payload
|
|
230
|
+
|
|
231
|
+
JWTs are signed, not encrypted. Their contents are readable by anyone who holds the token.
|
|
232
|
+
|
|
233
|
+
## 🧩 Integration with LykosJS
|
|
234
|
+
|
|
235
|
+
Use the JWT manager together with `@lykosjs/cookie` to keep the refresh token in an `HttpOnly` cookie:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { JwtManager, extractBearerToken, extractCookieToken } from '@lykosjs/jwt'
|
|
239
|
+
import { CookieManager } from '@lykosjs/cookie'
|
|
240
|
+
|
|
241
|
+
const jwt = new JwtManager<{ id: number }>({
|
|
242
|
+
accessToken: { secret: process.env.ACCESS_SECRET! },
|
|
243
|
+
refreshToken: { secret: process.env.REFRESH_SECRET! },
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
// Login: access token in the body, refresh token in a cookie
|
|
247
|
+
app.POST('/auth/login', (ctx, reply) => {
|
|
248
|
+
const { accessToken, refreshToken } = jwt.signPair({ id: 1 })
|
|
249
|
+
|
|
250
|
+
const cookies = new CookieManager()
|
|
251
|
+
cookies.set('refreshToken', refreshToken, {
|
|
252
|
+
httpOnly: true,
|
|
253
|
+
secure: true,
|
|
254
|
+
sameSite: 'lax',
|
|
255
|
+
path: '/auth',
|
|
256
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
return cookies.applyTo(reply.OK({ accessToken }))
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Protected route
|
|
263
|
+
app.GET('/me', (ctx, reply) => {
|
|
264
|
+
const token = extractBearerToken(ctx.request.headers.get('authorization'))
|
|
265
|
+
const user = jwt.assertAccessToken(token)
|
|
266
|
+
|
|
267
|
+
return reply.OK({ id: user.id })
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
// Refresh
|
|
271
|
+
app.POST('/auth/refresh', (ctx, reply) => {
|
|
272
|
+
const token = extractCookieToken(ctx.request.headers.get('cookie'), 'refreshToken')
|
|
273
|
+
// A missing or invalid token makes refresh() throw HttpError(401).
|
|
274
|
+
const { accessToken, refreshToken } = jwt.refresh(token ?? '')
|
|
275
|
+
|
|
276
|
+
const cookies = new CookieManager()
|
|
277
|
+
cookies.set('refreshToken', refreshToken, {
|
|
278
|
+
httpOnly: true,
|
|
279
|
+
secure: true,
|
|
280
|
+
sameSite: 'lax',
|
|
281
|
+
path: '/auth',
|
|
282
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
return cookies.applyTo(reply.OK({ accessToken }))
|
|
286
|
+
})
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Integration note:** The examples assume that `HttpError` thrown by the manager is converted into an HTTP response by your LykosJS error handling, and that the response helpers return a standard `Response`. Adapt them if your application behaves differently.
|
|
290
|
+
|
|
291
|
+
## 🧪 Testing
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
bun test
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
The test suite covers:
|
|
298
|
+
|
|
299
|
+
- Constructor validation and secret rules.
|
|
300
|
+
- Sign and verify round trips for both token types.
|
|
301
|
+
- Token type separation, algorithm pinning, and tamper detection.
|
|
302
|
+
- Expiry, issuer, and audience checks.
|
|
303
|
+
- Refresh token rotation.
|
|
304
|
+
- Header extraction helpers.
|
|
305
|
+
|
|
306
|
+
Always run the full test suite before publishing a new release.
|
|
307
|
+
|
|
308
|
+
## 📚 Dependencies
|
|
309
|
+
|
|
310
|
+
- [`jsonwebtoken`](https://www.npmjs.com/package/jsonwebtoken) for signing and verifying tokens.
|
|
311
|
+
- `lykosjs` (peer dependency) for `HttpError`.
|
|
312
|
+
|
|
313
|
+
## 🤝 Contributing
|
|
314
|
+
|
|
315
|
+
Contributions, bug reports, and suggestions are welcome.
|
|
316
|
+
|
|
317
|
+
1. Reproduce the issue or describe the proposed improvement.
|
|
318
|
+
2. Add or update tests.
|
|
319
|
+
3. Run the full test suite.
|
|
320
|
+
4. Update documentation when the public API changes.
|
|
321
|
+
|
|
322
|
+
Please ensure security-related changes preserve token verification guarantees.
|
|
323
|
+
|
|
324
|
+
## 📄 License
|
|
325
|
+
|
|
326
|
+
See the [`LICENSE`](LICENSE) file in this repository.
|
|
327
|
+
|
|
328
|
+
## Part of the LykosJS ecosystem
|
|
329
|
+
|
|
330
|
+
`@lykosjs/jwt` provides focused token management that can be used independently or integrated into LykosJS applications.
|
|
331
|
+
|
|
332
|
+
**Simple API. Explicit security. Predictable behavior.**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the token from an `Authorization: Bearer <token>` header value.
|
|
3
|
+
* Returns null when the header is missing or malformed.
|
|
4
|
+
*/
|
|
5
|
+
export function extractBearerToken(header) {
|
|
6
|
+
if (!header)
|
|
7
|
+
return null;
|
|
8
|
+
const [scheme, token, ...rest] = header.trim().split(/\s+/);
|
|
9
|
+
if (rest.length > 0 || !token || scheme?.toLowerCase() !== 'bearer')
|
|
10
|
+
return null;
|
|
11
|
+
return token;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=extract-bearer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-bearer.js","sourceRoot":"","sources":["../src/extract-bearer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAiC;IAEjC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5D,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,EAAE,WAAW,EAAE,KAAK,QAAQ;QACjE,OAAO,IAAI,CAAC;IAEd,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a token from a Cookie header.
|
|
3
|
+
* Returns null when the cookie is missing or malformed.
|
|
4
|
+
*/
|
|
5
|
+
export function extractCookieToken(cookieHeader, cookieName) {
|
|
6
|
+
if (!cookieHeader || !cookieName)
|
|
7
|
+
return null;
|
|
8
|
+
const cookies = cookieHeader.split(';');
|
|
9
|
+
for (const cookie of cookies) {
|
|
10
|
+
const separatorIndex = cookie.indexOf('=');
|
|
11
|
+
if (separatorIndex === -1)
|
|
12
|
+
continue;
|
|
13
|
+
const name = cookie.slice(0, separatorIndex).trim();
|
|
14
|
+
const value = cookie.slice(separatorIndex + 1).trim();
|
|
15
|
+
if (name !== cookieName || !value)
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
return decodeURIComponent(value);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=extract-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-cookie.js","sourceRoot":"","sources":["../src/extract-cookie.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,YAAuC,EACvC,UAAkB;IAElB,IAAI,CAAC,YAAY,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAE9C,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAExC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE3C,IAAI,cAAc,KAAK,CAAC,CAAC;YAAE,SAAS;QAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtD,IAAI,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK;YAAE,SAAS;QAE5C,IAAI,CAAC;YACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JwtConfig, JwtPayload, TokenPair } from './types';
|
|
2
|
+
export declare class JwtManager<TPayload extends JwtPayload = JwtPayload> {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly algorithm;
|
|
5
|
+
constructor(config: JwtConfig);
|
|
6
|
+
signAccessToken(payload: TPayload): string;
|
|
7
|
+
signRefreshToken(payload: TPayload): string;
|
|
8
|
+
/** Signs an access + refresh token pair for the same payload. */
|
|
9
|
+
signPair(payload: TPayload): TokenPair;
|
|
10
|
+
/** Returns the payload, or null if the token is invalid or expired. */
|
|
11
|
+
verifyAccessToken(token: string): TPayload | null;
|
|
12
|
+
/** Returns the payload, or null if the token is invalid or expired. */
|
|
13
|
+
verifyRefreshToken(token: string): TPayload | null;
|
|
14
|
+
/** Like verifyAccessToken but throws HttpError(401) on failure. */
|
|
15
|
+
assertAccessToken(token: string | null | undefined): TPayload;
|
|
16
|
+
/** Like verifyRefreshToken but throws HttpError(401) on failure. */
|
|
17
|
+
assertRefreshToken(token: string | null | undefined): TPayload;
|
|
18
|
+
/**
|
|
19
|
+
* Verifies a refresh token and issues a brand new pair (refresh token rotation).
|
|
20
|
+
* Throws HttpError(401) if the refresh token is invalid.
|
|
21
|
+
*/
|
|
22
|
+
refresh(refreshToken: string): TokenPair;
|
|
23
|
+
/** Decodes a token WITHOUT verifying it. Never trust the result for authorization. */
|
|
24
|
+
decode(token: string): TPayload | null;
|
|
25
|
+
private sign;
|
|
26
|
+
private verify;
|
|
27
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { HttpError } from 'lykosjs';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
|
+
const TOKEN_TYPE_CLAIM = 'tokenType';
|
|
4
|
+
const RESERVED_CLAIMS = new Set(['iat', 'exp', 'nbf', 'iss', 'aud', TOKEN_TYPE_CLAIM]);
|
|
5
|
+
// iat : the time at which the JWT was issued. Can be used to determine age of the JWT.
|
|
6
|
+
// exp : the time at which the JWT expires.
|
|
7
|
+
// nbf : the time at which the JWT becomes valid.
|
|
8
|
+
// iss : the issuer of the JWT.
|
|
9
|
+
// aud : the audience of the JWT.
|
|
10
|
+
const DEFAULT_ACCESS_TTL = '15m'; // 15 minutes
|
|
11
|
+
const DEFAULT_REFRESH_TTL = '30d'; // 30 days
|
|
12
|
+
const DEFAULT_MIN_SECRET_LENGTH = 32; // 32 characters
|
|
13
|
+
function stripReserved(payload) {
|
|
14
|
+
const clean = {};
|
|
15
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
16
|
+
if (!RESERVED_CLAIMS.has(key))
|
|
17
|
+
clean[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return clean;
|
|
20
|
+
}
|
|
21
|
+
export class JwtManager {
|
|
22
|
+
config;
|
|
23
|
+
algorithm; // Algorithm used for signing and verifying tokens. Defaults to HS256.
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
const accessSecret = config.accessToken?.secret;
|
|
27
|
+
const refreshSecret = config.refreshToken?.secret;
|
|
28
|
+
if (!accessSecret) {
|
|
29
|
+
throw new HttpError(500, 'Access token secret is required');
|
|
30
|
+
}
|
|
31
|
+
if (!refreshSecret) {
|
|
32
|
+
throw new HttpError(500, 'Refresh token secret is required');
|
|
33
|
+
}
|
|
34
|
+
if (accessSecret === refreshSecret) {
|
|
35
|
+
throw new HttpError(500, 'Access and refresh token secrets must be different');
|
|
36
|
+
}
|
|
37
|
+
const minLength = config.minSecretLength ?? DEFAULT_MIN_SECRET_LENGTH;
|
|
38
|
+
if (accessSecret.length < minLength || refreshSecret.length < minLength) {
|
|
39
|
+
throw new HttpError(500, `Token secrets must be at least ${minLength} characters`);
|
|
40
|
+
}
|
|
41
|
+
this.algorithm = config.algorithm ?? 'HS256';
|
|
42
|
+
}
|
|
43
|
+
signAccessToken(payload) {
|
|
44
|
+
return this.sign(payload, 'access');
|
|
45
|
+
}
|
|
46
|
+
signRefreshToken(payload) {
|
|
47
|
+
return this.sign(payload, 'refresh');
|
|
48
|
+
}
|
|
49
|
+
/** Signs an access + refresh token pair for the same payload. */
|
|
50
|
+
signPair(payload) {
|
|
51
|
+
return {
|
|
52
|
+
accessToken: this.signAccessToken(payload),
|
|
53
|
+
refreshToken: this.signRefreshToken(payload),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Returns the payload, or null if the token is invalid or expired. */
|
|
57
|
+
verifyAccessToken(token) {
|
|
58
|
+
return this.verify(token, 'access');
|
|
59
|
+
}
|
|
60
|
+
/** Returns the payload, or null if the token is invalid or expired. */
|
|
61
|
+
verifyRefreshToken(token) {
|
|
62
|
+
return this.verify(token, 'refresh');
|
|
63
|
+
}
|
|
64
|
+
/** Like verifyAccessToken but throws HttpError(401) on failure. */
|
|
65
|
+
assertAccessToken(token) {
|
|
66
|
+
const payload = token ? this.verifyAccessToken(token) : null;
|
|
67
|
+
if (!payload)
|
|
68
|
+
throw new HttpError(401, 'Invalid or expired access token');
|
|
69
|
+
return payload;
|
|
70
|
+
}
|
|
71
|
+
/** Like verifyRefreshToken but throws HttpError(401) on failure. */
|
|
72
|
+
assertRefreshToken(token) {
|
|
73
|
+
const payload = token ? this.verifyRefreshToken(token) : null;
|
|
74
|
+
if (!payload)
|
|
75
|
+
throw new HttpError(401, 'Invalid or expired refresh token');
|
|
76
|
+
return payload;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Verifies a refresh token and issues a brand new pair (refresh token rotation).
|
|
80
|
+
* Throws HttpError(401) if the refresh token is invalid.
|
|
81
|
+
*/
|
|
82
|
+
refresh(refreshToken) {
|
|
83
|
+
const payload = this.assertRefreshToken(refreshToken);
|
|
84
|
+
return this.signPair(stripReserved(payload));
|
|
85
|
+
}
|
|
86
|
+
/** Decodes a token WITHOUT verifying it. Never trust the result for authorization. */
|
|
87
|
+
decode(token) {
|
|
88
|
+
const decoded = jwt.decode(token);
|
|
89
|
+
if (!decoded || typeof decoded === 'string')
|
|
90
|
+
return null;
|
|
91
|
+
return decoded;
|
|
92
|
+
}
|
|
93
|
+
sign(payload, type) {
|
|
94
|
+
const tokenConfig = type === 'access' ? this.config.accessToken : this.config.refreshToken;
|
|
95
|
+
const fallbackTtl = type === 'access' ? DEFAULT_ACCESS_TTL : DEFAULT_REFRESH_TTL;
|
|
96
|
+
return jwt.sign({ ...stripReserved(payload), [TOKEN_TYPE_CLAIM]: type }, tokenConfig.secret, {
|
|
97
|
+
algorithm: this.algorithm,
|
|
98
|
+
expiresIn: tokenConfig.expiresIn ?? fallbackTtl,
|
|
99
|
+
...(this.config.issuer ? { issuer: this.config.issuer } : {}),
|
|
100
|
+
...(this.config.audience ? { audience: this.config.audience } : {}),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
verify(token, type) {
|
|
104
|
+
const tokenConfig = type === 'access' ? this.config.accessToken : this.config.refreshToken;
|
|
105
|
+
try {
|
|
106
|
+
const payload = jwt.verify(token, tokenConfig.secret, {
|
|
107
|
+
algorithms: [this.algorithm],
|
|
108
|
+
...(this.config.issuer ? { issuer: this.config.issuer } : {}),
|
|
109
|
+
...(this.config.audience ? { audience: this.config.audience } : {}),
|
|
110
|
+
});
|
|
111
|
+
if (typeof payload === 'string')
|
|
112
|
+
return null;
|
|
113
|
+
if (payload[TOKEN_TYPE_CLAIM] !== type)
|
|
114
|
+
return null;
|
|
115
|
+
const { [TOKEN_TYPE_CLAIM]: _type, ...rest } = payload;
|
|
116
|
+
return rest;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=jwt-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-manager.js","sourceRoot":"","sources":["../src/jwt-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,GAAG,MAAM,cAAc,CAAA;AAG9B,MAAM,gBAAgB,GAAG,WAAW,CAAA;AACpC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAA;AACtF,uFAAuF;AACvF,2CAA2C;AAC3C,iDAAiD;AACjD,+BAA+B;AAC/B,iCAAiC;AAEjC,MAAM,kBAAkB,GAAG,KAAK,CAAA,CAAC,aAAa;AAC9C,MAAM,mBAAmB,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'HS512' | 'RS256' | 'RS384' | 'RS512' | 'ES256' | 'ES384' | 'ES512';
|
|
4
|
+
export interface TokenConfig {
|
|
5
|
+
/** Secret used to sign and verify this token type. */
|
|
6
|
+
secret: string;
|
|
7
|
+
/** Lifetime, e.g. '15m', '30d' or seconds as a number. */
|
|
8
|
+
expiresIn?: SignOptions['expiresIn'];
|
|
9
|
+
}
|
|
10
|
+
export interface JwtConfig {
|
|
11
|
+
accessToken: TokenConfig;
|
|
12
|
+
refreshToken: TokenConfig;
|
|
13
|
+
/** Added as `iss` and required on verification. */
|
|
14
|
+
issuer?: string;
|
|
15
|
+
/** Added as `aud` and required on verification. */
|
|
16
|
+
audience?: string;
|
|
17
|
+
/** Signing algorithm. Defaults to HS256. Only this algorithm is accepted on verify. */
|
|
18
|
+
algorithm?: JwtAlgorithm;
|
|
19
|
+
/** Minimum secret length. Defaults to 32. Set to 0 to disable the check. */
|
|
20
|
+
minSecretLength?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TokenPair {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
refreshToken: string;
|
|
25
|
+
}
|
|
26
|
+
export type TokenType = 'access' | 'refresh';
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lykosjs/jwt",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@lykosjs/jwt",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Type-safe JWT access/refresh token manager for the LykosJS framework",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Zen Allaham <zenallaham09@gmail.com> (https://zenallaham.com)",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.build.json",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "bun test",
|
|
26
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"lykosjs",
|
|
30
|
+
"jwt",
|
|
31
|
+
"auth",
|
|
32
|
+
"access-token",
|
|
33
|
+
"refresh-token"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"jsonwebtoken": "^9.0.3"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"lykosjs": "^0.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/bun": "latest",
|
|
46
|
+
"@types/jsonwebtoken": "^9.0.7",
|
|
47
|
+
"typescript": "^7.0.2"
|
|
48
|
+
}
|
|
49
|
+
}
|