Skip to content

ccproxy.auth.bearer

ccproxy.auth.bearer

Bearer token authentication implementation.

BearerTokenAuthManager

BearerTokenAuthManager(token)

Authentication manager for static bearer tokens.

Parameters:

Name Type Description Default
token str

Bearer token string

required
Source code in ccproxy/auth/bearer.py
def __init__(self, token: str) -> None:
    """Initialize with a static bearer token.

    Args:
        token: Bearer token string
    """
    self.token = token.strip()
    if not self.token:
        raise ValueError("Token cannot be empty")

get_access_token async

get_access_token()

Get the bearer token.

Returns:

Type Description
str

Bearer token string

Raises:

Type Description
AuthenticationError

If token is invalid

Source code in ccproxy/auth/bearer.py
async def get_access_token(self) -> str:
    """Get the bearer token.

    Returns:
        Bearer token string

    Raises:
        AuthenticationError: If token is invalid
    """
    if not self.token:
        raise AuthenticationError("No bearer token available")
    return self.token

get_credentials async

get_credentials()

Bearer tokens do not expose structured credentials.

Source code in ccproxy/auth/bearer.py
async def get_credentials(self) -> BaseCredentials:
    """Bearer tokens do not expose structured credentials."""
    raise AuthenticationError(
        "Bearer token authentication doesn't support full credentials"
    )

is_authenticated async

is_authenticated()

Check if bearer token is available.

Returns:

Type Description
bool

True if token is available, False otherwise

Source code in ccproxy/auth/bearer.py
async def is_authenticated(self) -> bool:
    """Check if bearer token is available.

    Returns:
        True if token is available, False otherwise
    """
    return bool(self.token)

get_user_profile async

get_user_profile()

Return None because bearer tokens have no profile context.

Source code in ccproxy/auth/bearer.py
async def get_user_profile(self) -> StandardProfileFields | None:
    """Return ``None`` because bearer tokens have no profile context."""
    return None

validate_credentials async

validate_credentials()

Validate that credentials are available and valid.

Returns:

Type Description
bool

True if credentials are valid, False otherwise

Source code in ccproxy/auth/bearer.py
async def validate_credentials(self) -> bool:
    """Validate that credentials are available and valid.

    Returns:
        True if credentials are valid, False otherwise
    """
    return bool(self.token)

get_provider_name

get_provider_name()

Get the provider name for logging.

Returns:

Type Description
str

Provider name string

Source code in ccproxy/auth/bearer.py
def get_provider_name(self) -> str:
    """Get the provider name for logging.

    Returns:
        Provider name string
    """
    return "bearer-token"