For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • BedrockAgent
      • CLI Tools
      • Configuration
        • AuthHandler
          • flask_decorator
          • get_auth_info
          • get_fastapi_dependency
          • verify_api_key
          • verify_basic_auth
          • verify_bearer_token
        • ConfigLoader
        • Environment Variables
        • SecurityConfig
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions
      • LiveWire
      • MCP Gateway
      • PomBuilder
      • Prefabs
      • Search
      • SkillBase
      • Skills
      • SWAIGFunction
      • SWMLBuilder
      • SWMLService
      • WebService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • Chat
      • Compat
      • Datasphere
      • Fabric
      • Imported Numbers
      • Logs
      • Lookup
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSub
      • Queues
      • Recordings
      • Registry
      • RestClient
      • Short Codes
      • SignalWireRestError
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsConfigurationAuthHandler

get_fastapi_dependency

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

verify_api_key

Next
Built with

Get a FastAPI dependency function that can be used with Depends() to protect routes. The dependency tries each enabled auth method in order: Bearer token and Basic Auth.

Parameters

optional
boolDefaults to false

When True, unauthenticated requests pass through with {"authenticated": False} instead of raising a 401 error.

Returns

Callable — An async function suitable for use as a FastAPI dependency. Returns a dict with authenticated (bool) and method (str or None) keys.

Example

1from fastapi import FastAPI, Depends
2from signalwire.core.security_config import SecurityConfig
3from signalwire.core.auth_handler import AuthHandler
4
5security = SecurityConfig()
6auth = AuthHandler(security)
7
8app = FastAPI()
9auth_dep = auth.get_fastapi_dependency()
10
11@app.get("/protected")
12async def protected_route(auth_result=Depends(auth_dep)):
13 return {"method": auth_result["method"]}
14
15# Optional auth -- don't reject unauthenticated requests
16optional_dep = auth.get_fastapi_dependency(optional=True)
17
18@app.get("/public")
19async def public_route(auth_result=Depends(optional_dep)):
20 if auth_result["authenticated"]:
21 return {"user": "authenticated"}
22 return {"user": "anonymous"}