(
credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer(auto_error=False)),
)
| 90 | |
| 91 | |
| 92 | def verify_api_key( |
| 93 | credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer(auto_error=False)), |
| 94 | ): |
| 95 | if not g_config.server.api_key: |
| 96 | return "" |
| 97 | |
| 98 | if credentials is None or credentials.scheme.lower() != "bearer": |
| 99 | raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Invalid or missing token") |
| 100 | |
| 101 | api_key = credentials.credentials |
| 102 | if api_key != g_config.server.api_key: |
| 103 | raise HTTPException(status.HTTP_403_FORBIDDEN, detail="Wrong API key") |
| 104 | |
| 105 | return api_key |
| 106 | |
| 107 | |
| 108 | def add_exception_handler(app: FastAPI): |
nothing calls this directly
no outgoing calls
no test coverage detected