MCPcopy Create free account
hub / github.com/Nativu5/Gemini-FastAPI / verify_api_key

Function verify_api_key

app/server/middleware.py:92–105  ·  view source on GitHub ↗
(
    credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer(auto_error=False)),
)

Source from the content-addressed store, hash-verified

90
91
92def 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
108def add_exception_handler(app: FastAPI):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected