@twasik4/pocket-service 1.0.0 → 1.0.2

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 CHANGED
@@ -222,6 +222,62 @@ addRoute(
222
222
  export { router as AuthRouter, routes as AuthRoutes };
223
223
  ```
224
224
 
225
+ 6. withAuthStrategy() / withAuthStrategies()
226
+
227
+ Use these hooks to plug in JWT, mTLS, or custom auth behavior while keeping route-level `requireAuth` unchanged.
228
+
229
+ ```ts
230
+ import {
231
+ Service,
232
+ createJoseJwtVerifier,
233
+ createJwtAuthStrategy,
234
+ createMtlsAuthStrategy,
235
+ } from "@twasik4/pocket-service";
236
+
237
+ const mtlsStrategy = createMtlsAuthStrategy({
238
+ requireAuthorized: true,
239
+ });
240
+
241
+ const jwtStrategy = createJwtAuthStrategy({
242
+ verifyToken: createJoseJwtVerifier({
243
+ jwksUri: "http://auth-service:3101/.well-known/jwks.json",
244
+ issuer: "auth-service",
245
+ audience: "gateway-service",
246
+ }),
247
+ });
248
+
249
+ const service = new Service()
250
+ .withAuthStrategies([mtlsStrategy, jwtStrategy])
251
+ .withoutDefaultHeaderAuthFallback()
252
+ .build();
253
+ ```
254
+
255
+ If you use HMAC-signed tokens instead of JWKS:
256
+
257
+ ```ts
258
+ import {
259
+ Service,
260
+ createJoseJwtVerifier,
261
+ createJwtAuthStrategy,
262
+ } from "@twasik4/pocket-service";
263
+
264
+ const jwtStrategy = createJwtAuthStrategy({
265
+ verifyToken: createJoseJwtVerifier({
266
+ secret: process.env.INTERNAL_JWT_SECRET!,
267
+ issuer: "auth-service",
268
+ audience: "gateway-service",
269
+ algorithms: ["HS256"],
270
+ }),
271
+ });
272
+
273
+ const service = new Service()
274
+ .withAuthStrategy(jwtStrategy)
275
+ .withoutDefaultHeaderAuthFallback()
276
+ .build();
277
+ ```
278
+
279
+ Default behavior remains backward compatible. If no strategy authenticates and fallback is enabled, the service still reads `x-user-id` / `x-user-meta` headers.
280
+
225
281
  ### Methods
226
282
 
227
283
  1. shutdown()