***

title: AuthHandler
slug: /reference/python/agents/configuration/auth-handler
description: Unified authentication handler for Basic Auth, Bearer tokens, and API keys.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[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**

<ParamField path="security_config" type="SecurityConfig" required={true} toc={true}>
  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)
</ParamField>

## **Methods**

<CardGroup cols={3}>
  <Card title="flask_decorator" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/flask-decorator">
    Flask decorator for protecting routes with authentication.
  </Card>

  <Card title="get_auth_info" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-auth-info">
    Get a summary of configured authentication methods.
  </Card>

  <Card title="get_fastapi_dependency" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/get-fastapi-dependency">
    Get a FastAPI dependency function for protecting routes.
  </Card>

  <Card title="verify_api_key" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-api-key">
    Verify an API key using constant-time comparison.
  </Card>

  <Card title="verify_basic_auth" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-basic-auth">
    Verify HTTP Basic Auth credentials using constant-time comparison.
  </Card>

  <Card title="verify_bearer_token" href="/docs/server-sdks/reference/python/agents/configuration/auth-handler/verify-bearer-token">
    Verify a Bearer token using constant-time comparison.
  </Card>
</CardGroup>

## **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'}}
```