Verify API key from Authorization header, x-goog-api-key header, or key query param.
(
credentials: Optional[HTTPAuthorizationCredentials] = Security(optional_security),
x_goog_api_key: Optional[str] = Header(None, alias="x-goog-api-key"),
key: Optional[str] = Query(None),
)
| 42 | |
| 43 | |
| 44 | async def verify_api_key_flexible( |
| 45 | credentials: Optional[HTTPAuthorizationCredentials] = Security(optional_security), |
| 46 | x_goog_api_key: Optional[str] = Header(None, alias="x-goog-api-key"), |
| 47 | key: Optional[str] = Query(None), |
| 48 | ) -> str: |
| 49 | """Verify API key from Authorization header, x-goog-api-key header, or key query param.""" |
| 50 | api_key = None |
| 51 | |
| 52 | if credentials is not None: |
| 53 | api_key = credentials.credentials |
| 54 | elif x_goog_api_key: |
| 55 | api_key = x_goog_api_key |
| 56 | elif key: |
| 57 | api_key = key |
| 58 | |
| 59 | if not api_key or not AuthManager.verify_api_key(api_key): |
| 60 | raise HTTPException(status_code=401, detail="Invalid API key") |
| 61 | |
| 62 | return api_key |
nothing calls this directly
no test coverage detected