Skip to content

ccproxy.auth.credentials_adapter

ccproxy.auth.credentials_adapter

Adapter to make CredentialsManager compatible with AuthManager interface.

CredentialsAuthManager

CredentialsAuthManager(credentials_manager=None)

Bases: BaseAuthManager

Adapter to make CredentialsManager compatible with AuthManager interface.

Parameters:

Name Type Description Default
credentials_manager CredentialsManager | None

CredentialsManager instance, creates new if None

None
Source code in ccproxy/auth/credentials_adapter.py
def __init__(self, credentials_manager: CredentialsManager | None = None) -> None:
    """Initialize with credentials manager.

    Args:
        credentials_manager: CredentialsManager instance, creates new if None
    """
    self._credentials_manager = credentials_manager or CredentialsManager()

get_access_token async

get_access_token()

Get valid access token from credentials manager.

Returns:

Type Description
str

Access token string

Raises:

Type Description
AuthenticationError

If authentication fails

Source code in ccproxy/auth/credentials_adapter.py
async def get_access_token(self) -> str:
    """Get valid access token from credentials manager.

    Returns:
        Access token string

    Raises:
        AuthenticationError: If authentication fails
    """
    try:
        return await self._credentials_manager.get_access_token()
    except CredentialsNotFoundError as e:
        raise AuthenticationError("No credentials found") from e
    except CredentialsExpiredError as e:
        raise AuthenticationError("Credentials expired") from e
    except CredentialsError as e:
        raise AuthenticationError(f"Credentials error: {e}") from e

get_credentials async

get_credentials()

Get valid credentials from credentials manager.

Returns:

Type Description
ClaudeCredentials

Valid credentials

Raises:

Type Description
AuthenticationError

If authentication fails

Source code in ccproxy/auth/credentials_adapter.py
async def get_credentials(self) -> ClaudeCredentials:
    """Get valid credentials from credentials manager.

    Returns:
        Valid credentials

    Raises:
        AuthenticationError: If authentication fails
    """
    try:
        return await self._credentials_manager.get_valid_credentials()
    except CredentialsNotFoundError as e:
        raise AuthenticationError("No credentials found") from e
    except CredentialsExpiredError as e:
        raise AuthenticationError("Credentials expired") from e
    except CredentialsError as e:
        raise AuthenticationError(f"Credentials error: {e}") from e

is_authenticated async

is_authenticated()

Check if current authentication is valid.

Returns:

Type Description
bool

True if authenticated, False otherwise

Source code in ccproxy/auth/credentials_adapter.py
async def is_authenticated(self) -> bool:
    """Check if current authentication is valid.

    Returns:
        True if authenticated, False otherwise
    """
    try:
        await self._credentials_manager.get_valid_credentials()
        return True
    except CredentialsError:
        return False

get_user_profile async

get_user_profile()

Get user profile information.

Returns:

Type Description
UserProfile | None

UserProfile if available, None otherwise

Source code in ccproxy/auth/credentials_adapter.py
async def get_user_profile(self) -> UserProfile | None:
    """Get user profile information.

    Returns:
        UserProfile if available, None otherwise
    """
    try:
        return await self._credentials_manager.fetch_user_profile()
    except CredentialsError:
        return None