Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- PyQt
- swift
- urllib
- GIT
- port
- 다이어트
- python
- sqlite
- MS-SQL
- javascript
- IOS
- flutter
- Linux
- pandas
- 함수
- Unity
- Excel
- ASP
- 리눅스
- mssql
- 유니티
- node.js
- PER
- PyQt5
- tensorflow
- 라즈베리파이
- MySQL
- 맛집
- ubuntu
- 날짜
Archives
아미(아름다운미소)
fastapi apikey 인증 본문
my_fastapi_app/
│
├── main.py
├── auth.py
└── routers/
└── secure.py
auth.py
# auth.py
from fastapi import Depends, HTTPException
from fastapi.security import APIKeyHeader
API_KEY = "your_api_key_here"
api_key_header = APIKeyHeader(name="X-API-Key")
def verify_api_key(api_key: str = Depends(api_key_header)):
if api_key != API_KEY:
raise HTTPException(status_code=403, detail="Forbidden")
routers/secure.py
# routers/secure.py
from fastapi import APIRouter, Depends
from auth import verify_api_key
router = APIRouter()
@router.get("/secure-data", dependencies=[Depends(verify_api_key)])
def read_secure_data():
return {"message": "This is a secure endpoint!"}
main.py
# main.py
from fastapi import FastAPI
from routers.secure import router as secure_router
app = FastAPI()
# 라우터를 등록합니다.
app.include_router(secure_router)
Comments