generated from BrunoTanabe/fastapi-clean-architecture-ddd-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.env.example
More file actions
102 lines (75 loc) · 3.55 KB
/
.env.example
File metadata and controls
102 lines (75 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# APPLICATION
APPLICATION_TITLE="FastAPI API Key Authentication Example"
APPLICATION_SUMMARY="Example FastAPI app showing **API Key** auth via `Header`, using dependency injection, optional scopes, and reusable OpenAPI security components."
APPLICATION_DESCRIPTION="## Overview
This project is a minimal FastAPI example that demonstrates **API Key authentication** using a single, fixed key loaded from a `.env` file. There is **no key administration** (no rotation, revocation, or multi‑key store) — the goal is to show a clean, reproducible pattern suitable for learning and for small internal tools.
## Authentication
- **Scheme name (OpenAPI):** `ApiKeyAuth`
- **Transport:** API key in HTTP header
- **Header name:** `X-API-Key`
- **Header description:** “API key to access the application. This key is used to authenticate requests to the API.”
- **Validation:** Requests must include a header whose value matches the configured default key.
- **Default key (sample):** `a8c46a27-712d-4091-84c3-3f843bad9826`
Example:
```
X-API-Key: a8c46a27-712d-4091-84c3-3f843bad9826
````
## Endpoint
### `POST /api/v1/example`
**Request body (JSON):**
```json
{
\"name\": \"Alice\"
}
````
**Success response (200):**
```
Hello Alice!
```
This endpoint simply greets the provided `name`. It exists to illustrate the authentication flow with a concrete, end‑to‑end request.
## Quick start
1. Create a `.env` file (see **Configuration**).
2. Run the app: `uvicorn app.main:app --reload`
3. Call the endpoint with a valid API key:
```bash
curl -X POST http://localhost:8000/api/v1/example \
-H \"Content-Type: application/json\" \
-H \"X-API-Key: a8c46a27-712d-4091-84c3-3f843bad9826\" \
-d '{\"name\":\"Alice\"}'
```
**Expected output:**
```
Hello Alice!
```
## Configuration
All security settings are read from environment variables (e.g., via `.env`):
```env
SECURITY_API_KEY_HEADER=\"X-API-Key\"
SECURITY_API_KEY_HEADER_DESCRIPTION=\"API key to access the application. This key is used to authenticate requests to the API.\"
SECURITY_SCHEME_NAME=\"ApiKeyAuth\"
SECURITY_DEFAULT_API_KEY=\"a8c46a27-712d-4091-84c3-3f843bad9826\"
```
> **Note:** The default key above is provided for demonstration. For any real usage, replace it with a secret value and keep your `.env` outside version control.
## OpenAPI UI
Once running, you can explore and try the endpoint from the autogenerated docs at `/docs` (Swagger UI) or `/redoc`.
"
APPLICATION_VERSION="1.5.0"
APPLICATION_CONTACT_NAME="Bruno Tanabe"
APPLICATION_CONTACT_URL="https://github.com/BrunoTanabe"
APPLICATION_CONTACT_EMAIL="tanabebruno@gmail.com"
APPLICATION_CONTACT_PHONE="+55 (12) 98844-1848"
# ENVIRONMENT
ENVIRONMENT="DEV"
# SECURITY
SECURITY_API_KEY_HEADER="X-API-Key"
SECURITY_API_KEY_HEADER_DESCRIPTION="API key to access the application. This key is used to authenticate requests to the API."
SECURITY_SCHEME_NAME="ApiKeyAuth"
SECURITY_DEFAULT_API_KEY="a8c46a27-712d-4091-84c3-3f843bad9826"
SECURITY_DEFAULT_API_KEY_NAME="Default API Key" # note: This value is not used actually in the code, but can be used for api key management.
SECURITY_DEFAULT_API_KEY_DESCRIPTION="Default API Key for project FastAPI API Key Authentication. This key is internally used for development purposes and should not be shared publicly. It is used to authenticate requests to the API and should be kept secure." # note: This value is not used actually in the code, but can be used for api key management.
# LOGS
LOGS_NAME="fastapi-clean-architecture-ddd-template"
LOGS_PATH="logs"
LOGS_LEVEL="DEBUG"
LOGS_REQUEST_ID_LENGTH=8
LOGS_PYGMENTS_STYLE="monokai"