You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(`Auth server listening on port ${PORT}`);
320
+
console.log("Auth server listening on port " + PORT);
316
321
});
317
322
AUTHEOF
318
323
```
319
324
320
325
Install dependencies:
321
326
322
327
```bash
323
-
cd /data/cloudsync-postgres/auth-server
324
-
# Install node if not available
325
-
apt-get install -y nodejs npm 2>/dev/null ||true
326
-
docker run --rm -v $(pwd):/app -w /app node:22-alpine npm install
328
+
docker run --rm -v $(pwd)/auth-server:/app -w /app node:22-alpine npm install
327
329
```
328
330
331
+
### 6e. (Optional) Create the JWKS auth server
332
+
333
+
If you need RS256/JWKS-based authentication instead of (or in addition to) the shared secret approach, create a second auth server that generates an RSA key pair on startup and exposes a JWKS endpoint.
console.log("JWKS Auth server listening on port " + PORT);
436
+
});
437
+
});
438
+
EOF
439
+
440
+
docker run --rm -v $(pwd)/auth-server-jwks:/app -w /app node:22-alpine npm install
441
+
```
442
+
443
+
Add the JWKS auth service to `docker-compose.yml`:
444
+
445
+
```yaml
446
+
auth-jwks:
447
+
image: node:22-alpine
448
+
container_name: cloudsync-auth-jwks
449
+
environment:
450
+
PORT: 3002
451
+
ISSUER: cloudsync-auth-jwks
452
+
ports:
453
+
- "3002:3002"
454
+
volumes:
455
+
- ./auth-server-jwks:/app
456
+
working_dir: /app
457
+
command: ["node", "server.js"]
458
+
restart: unless-stopped
459
+
```
460
+
461
+
> **Note:** The JWKS server generates a new RSA key pair each time it starts. For production, persist the key pair to a volume so tokens remain valid across restarts.
462
+
329
463
---
330
464
331
465
## Step 7: Start the stack
@@ -339,27 +473,39 @@ Verify:
339
473
340
474
```bash
341
475
docker compose ps
342
-
# Both db and auth should be running
343
476
344
477
# Test Postgres
345
478
docker compose exec db psql -U postgres -c "SELECT cloudsync_version();"
346
479
347
-
# Test auth server
480
+
# Test HS256 auth server
348
481
curl http://localhost:3001/healthz
482
+
483
+
# Test JWKS auth server (if enabled)
484
+
curl http://localhost:3002/healthz
485
+
curl http://localhost:3002/.well-known/jwks.json
349
486
```
350
487
351
488
---
352
489
353
490
## Step 8: Generate a JWT token
354
491
492
+
**HS256 (shared secret):**
493
+
355
494
```bash
356
-
# Generate a token for a user
357
495
curl -X POST http://localhost:3001/token \
358
496
-H "Content-Type: application/json" \
359
497
-d '{"sub": "user-1", "role": "authenticated"}'
360
498
```
361
499
362
-
Response:
500
+
**RS256 (JWKS):**
501
+
502
+
```bash
503
+
curl -X POST http://localhost:3002/token \
504
+
-H "Content-Type: application/json" \
505
+
-d '{"sub": "user-1", "role": "authenticated"}'
506
+
```
507
+
508
+
Response (both):
363
509
364
510
```json
365
511
{"token":"eyJhbG...","expiresIn":"24h"}
@@ -467,17 +613,35 @@ docker compose exec db psql -U postgres -c "SELECT * FROM todos;"
467
613
468
614
## Step 11: CloudSync server JWT configuration
469
615
470
-
The CloudSync server needs to validate tokens from your auth server. Configure these environment variables on the CloudSync server:
616
+
The CloudSync server needs to validate tokens from your auth server. Configuration depends on which auth method you chose.
617
+
618
+
### Option A: HS256 (shared secret)
619
+
620
+
Configure these environment variables on the CloudSync server:
471
621
472
622
```env
473
-
# Use the same JWT_SECRET as your auth server
623
+
# Use the same JWT_SECRET as your auth server (base64-encoded)
474
624
JWT_SECRET=<your-jwt-secret>
475
625
476
626
# For development/testing, set the development issuer override
# Must match the ISSUER env var on the JWKS auth server
641
+
JWT_ISSUER=cloudsync-auth-jwks
642
+
```
643
+
644
+
No shared secret is needed — the CloudSync server fetches the public key from the JWKS endpoint and uses it to verify token signatures. This is how production auth systems (Auth0, Supabase, Firebase) work.
481
645
482
646
---
483
647
@@ -486,13 +650,16 @@ This allows the CloudSync server to verify HS256 tokens signed with your shared
0 commit comments