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 |
Tags
- 함수
- pandas
- 날짜
- urllib
- 다이어트
- python
- tensorflow
- node.js
- PyQt
- port
- javascript
- ubuntu
- Unity
- MySQL
- MS-SQL
- mssql
- 맛집
- GIT
- Excel
- ASP
- PER
- sqlite
- PyQt5
- flutter
- IOS
- Linux
- swift
- 유니티
- 라즈베리파이
- 리눅스
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