Skip to content

hololinked.client.security.BasicSecurity

Bases: BaseModel

Basic Security Scheme with username and password. The credentials are added into the Authorization header.

Source code in hololinked/hololinked/client/security.py
class BasicSecurity(BaseModel):
    """
    Basic Security Scheme with username and password.
    The credentials are added into the `Authorization` header.
    """

    http_header_name: str = "Authorization"

    _credentials: str = PrivateAttr()

    def __init__(self, username: str, password: str, use_base64: bool = True):
        """
        Parameters
        ----------
        username: str
            The username for basic authentication
        password: str
            The password for basic authentication
        use_base64: bool
            Whether to encode the credentials in base64, by default True
        """
        super().__init__()
        credentials = f"{username}:{password}"
        if use_base64:
            credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
        self._credentials = f"Basic {credentials}"

    @property
    def http_header(self) -> str:
        """Value for the Authorization header"""
        return self._credentials

Attributes

http_header property

http_header: str

Value for the Authorization header

Functions

__init__

__init__(username: str, password: str, use_base64: bool = True)

Parameters:

Name Type Description Default

username

str

The username for basic authentication

required

password

str

The password for basic authentication

required

use_base64

bool

Whether to encode the credentials in base64, by default True

True
Source code in hololinked/hololinked/client/security.py
def __init__(self, username: str, password: str, use_base64: bool = True):
    """
    Parameters
    ----------
    username: str
        The username for basic authentication
    password: str
        The password for basic authentication
    use_base64: bool
        Whether to encode the credentials in base64, by default True
    """
    super().__init__()
    credentials = f"{username}:{password}"
    if use_base64:
        credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
    self._credentials = f"Basic {credentials}"