feat(auth): implement authentication endpoints and JWT handling
This commit is contained in:
@@ -18,6 +18,16 @@ cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
variabili auth richieste in `.env`:
|
||||
|
||||
```bash
|
||||
JWT_SECRET_KEY=change-this-secret
|
||||
JWT_ALGORITHM=HS256
|
||||
JWT_EXPIRE_MINUTES=30
|
||||
AUTH_USERNAME=admin
|
||||
AUTH_PASSWORD=change-this-password
|
||||
```
|
||||
|
||||
avvia i servizi e il server locale
|
||||
```bash
|
||||
docker compose up -d mongodb redis
|
||||
@@ -28,6 +38,35 @@ fastapi dev app/main.py
|
||||
|
||||
accedi a FastAPI su: [FastAPI docs](http://localhost:3671/docs)
|
||||
|
||||
## Auth API
|
||||
|
||||
Gli endpoint auth disponibili sono solo:
|
||||
|
||||
- `POST /auth/login`
|
||||
- `POST /auth/logout`
|
||||
|
||||
Esempio login:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3671/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"change-this-password"}'
|
||||
```
|
||||
|
||||
L'access token ottenuto va inviato come bearer token:
|
||||
|
||||
```bash
|
||||
curl http://localhost:3671/proxy \
|
||||
-H "Authorization: Bearer <ACCESS_TOKEN>"
|
||||
```
|
||||
|
||||
Esempio logout (revoca server-side del token):
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3671/auth/logout \
|
||||
-H "Authorization: Bearer <ACCESS_TOKEN>"
|
||||
```
|
||||
|
||||
## Documentazione per Sviluppo
|
||||
|
||||
[MitMProxy examples](https://docs.mitmproxy.org/stable/addons/examples/)
|
||||
|
||||
Reference in New Issue
Block a user