verify_bearer_token

View as MarkdownOpen in Claude

Verify a Bearer token using constant-time comparison.

Parameters

credentials
HTTPAuthorizationCredentialsRequired

FastAPI HTTPAuthorizationCredentials object containing the credentials (token) attribute.

Returns

bool — True if the token matches the configured bearer token. Returns False if bearer authentication is not enabled.

Example

from fastapi.security import HTTPAuthorizationCredentials
from signalwire.core.security_config import SecurityConfig
from signalwire.core.auth_handler import AuthHandler
security = SecurityConfig()
auth = AuthHandler(security)
creds = HTTPAuthorizationCredentials(scheme="Bearer", credentials="my-token")
is_valid = auth.verify_bearer_token(creds)
print(f"Bearer token valid: {is_valid}")

Bearer token authentication is only available when the SecurityConfig instance has a bearer_token attribute set (typically via config file).