flask_decorator

View as MarkdownOpen in Claude

Flask decorator for protecting routes. Tries Bearer token, API key, and Basic Auth in order. Returns a 401 response if all methods fail.

Parameters

f
CallableRequired

The Flask view function to protect.

Returns

Callable — The wrapped function that checks authentication before calling the original view.

Example

from flask import Flask
from signalwire.core.security_config import SecurityConfig
from signalwire.core.auth_handler import AuthHandler
security = SecurityConfig()
auth = AuthHandler(security)
app = Flask(__name__)
@app.route("/protected")
@auth.flask_decorator
def protected_route():
return {"status": "authenticated"}

The Flask decorator is used by the mcp-gateway service. For agent-based applications, use the FastAPI dependency instead.