Skip to main content
Glama
auth_box.py1.71 kB
import logging from typing import Optional from fastapi import status from starlette.responses import JSONResponse logger = logging.getLogger(__name__) def box_auth_validate_token(scope) -> Optional[JSONResponse]: """Validate if the auth token is properly configured.""" path = scope["path"] logger.debug(f"Token validation processing: {scope['method']} {path}") # Extract authorization header headers = dict(scope.get("headers", [])) auth_header = headers.get(b"authorization", b"").decode("utf-8") # Validate authentication response = None if not auth_header: logger.warning( f"[Token] Missing authorization header for {scope['method']} {path}" ) response = JSONResponse( content={ "error": "invalid_request", "error_description": "Missing Authorization header", }, status_code=status.HTTP_401_UNAUTHORIZED, ) elif not auth_header.startswith("Bearer "): logger.warning("[Token] Invalid authorization header format") response = JSONResponse( content={ "error": "invalid_request", "error_description": "Authorization header must use Bearer scheme", }, status_code=status.HTTP_401_UNAUTHORIZED, ) else: token = auth_header.replace("Bearer ", "") logger.debug(f"Token is present for {scope['method']} {path}") logger.debug("A box client will be created using the provided token.") # Store the OAuth token in the scope for use in request handlers scope["oauth_token"] = token return None return response

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/box-community/mcp-server-box'

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