> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # AuthHandler > Unified authentication handler for Basic Auth, Bearer tokens, and API keys. [mcp-gateway]: /docs/server-sdks/reference/python/agents/cli/mcp-gateway [securityconfig]: /docs/server-sdks/reference/python/agents/configuration/security-config [flaskdecorator]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/flask-decorator [getauthinfo]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/get-auth-info [getfastapidependency]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/get-fastapi-dependency [verifyapikey]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-api-key [verifybasicauth]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-basic-auth [verifybearertoken]: /docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-bearer-token `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`][mcp-gateway] and agent webhook endpoints. ```python from signalwire.core.auth_handler import AuthHandler from signalwire.core.security_config import SecurityConfig security = SecurityConfig() auth = AuthHandler(security) ``` ## **Properties** **`security_config`** `SecurityConfig` — required A [`SecurityConfig`][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** #### [flask\_decorator](/docs/server-sdks/reference/python/agents/configuration/auth-handler/flask-decorator) Flask decorator for protecting routes with authentication. #### [get\_auth\_info](/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-auth-info) Get a summary of configured authentication methods. #### [get\_fastapi\_dependency](/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-fastapi-dependency) Get a FastAPI dependency function for protecting routes. #### [verify\_api\_key](/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-api-key) Verify an API key using constant-time comparison. #### [verify\_basic\_auth](/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-basic-auth) Verify HTTP Basic Auth credentials using constant-time comparison. #### [verify\_bearer\_token](/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-bearer-token) Verify a Bearer token using constant-time comparison. ## **Example** ```python {5} from signalwire.core.security_config import SecurityConfig from signalwire.core.auth_handler import AuthHandler security = SecurityConfig() auth = AuthHandler(security) # Check which methods are configured info = auth.get_auth_info() print(info) # {'basic': {'enabled': True, 'username': 'signalwire'}} ``` > Unified authentication handler for Basic Auth, Bearer tokens, and API keys. ## Docs - [flask_decorator](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/flask-decorator.md): Flask decorator for protecting routes with authentication. - [get_auth_info](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-auth-info.md): Get a summary of configured authentication methods. - [get_fastapi_dependency](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-fastapi-dependency.md): Get a FastAPI dependency function for protecting routes. - [verify_api_key](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-api-key.md): Verify an API key using constant-time comparison. - [verify_basic_auth](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-basic-auth.md): Verify HTTP Basic Auth credentials using constant-time comparison. - [verify_bearer_token](https://signalwire.com/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-bearer-token.md): Verify a Bearer token using constant-time comparison.