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

1from flask import Flask
2from signalwire.core.security_config import SecurityConfig
3from signalwire.core.auth_handler import AuthHandler
4
5security = SecurityConfig()
6auth = AuthHandler(security)
7
8app = Flask(__name__)
9
10@app.route("/protected")
11@auth.flask_decorator
12def protected_route():
13 return {"status": "authenticated"}

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