Skip to main content
Glama
dependencies.py1.49 kB
from fastapi import Header, HTTPException from app.auth_client.factory import build_auth_verifier from app.auth_client.interface import AuthVerifier from app.core.auth.exceptions import InvalidTokenError, MissingAuthorizationError from app.core.auth.models import AuthContext from app.core.config import settings def _extract_bearer_token(authorization: str | None) -> str: if not authorization: raise MissingAuthorizationError("missing Authorization header") prefix = "Bearer " if not authorization.startswith(prefix): raise MissingAuthorizationError("invalid Authorization scheme") token = authorization[len(prefix):].strip() if not token: raise MissingAuthorizationError("empty bearer token") return token async def get_auth_context( authorization: str | None = Header(default=None), ) -> AuthContext: if not settings.auth_enabled: return AuthContext(user_id="", token="", claims={}) try: token = _extract_bearer_token(authorization) except MissingAuthorizationError as e: raise HTTPException(status_code=401, detail=str(e)) from e try: verifier: AuthVerifier = build_auth_verifier(settings) except ValueError as e: raise HTTPException( status_code=500, detail="auth misconfigured") from e try: return await verifier.verify(token) except InvalidTokenError as e: raise HTTPException(status_code=401, detail="invalid token") from e

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jayleonc/weather-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server