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

boolTrue if the token matches the configured bearer token. Returns False if bearer authentication is not enabled.

Example

1from fastapi.security import HTTPAuthorizationCredentials
2from signalwire.core.security_config import SecurityConfig
3from signalwire.core.auth_handler import AuthHandler
4
5security = SecurityConfig()
6auth = AuthHandler(security)
7
8creds = HTTPAuthorizationCredentials(scheme="Bearer", credentials="my-token")
9is_valid = auth.verify_bearer_token(creds)
10
11print(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).