AuthHandler

View as MarkdownOpen in Claude

AuthHandler provides a unified authentication layer supporting HTTP Basic Auth, Bearer tokens, and API keys. It integrates with both FastAPI (as a dependency) and Flask (as a decorator), and is used internally by the mcp-gateway and agent webhook endpoints.

1from signalwire.core.auth_handler import AuthHandler
2from signalwire.core.security_config import SecurityConfig
3
4security = SecurityConfig()
5auth = AuthHandler(security)

Properties

security_config
SecurityConfigRequired

A SecurityConfig instance that provides the authentication credentials. The handler reads:

  • Basic auth username/password from get_basic_auth()
  • Bearer token from the bearer_token attribute (if set)
  • API key and header name from the api_key and api_key_header attributes (if set)

Methods

Example

1from signalwire.core.security_config import SecurityConfig
2from signalwire.core.auth_handler import AuthHandler
3
4security = SecurityConfig()
5auth = AuthHandler(security)
6
7# Check which methods are configured
8info = auth.get_auth_info()
9print(info)
10# {'basic': {'enabled': True, 'username': 'signalwire'}}