Skip to content

AuthResource

AuthResource

Session-based authentication for PiKVM.

Source code in src/aiopikvm/resources/auth.py
class AuthResource(BaseResource):
    """Session-based authentication for PiKVM."""

    async def login(self, user: str, passwd: str, totp: str | None = None) -> Any:
        """Log in with credentials.

        Args:
            user: Username.
            passwd: Password.
            totp: Optional TOTP code (concatenated to password).

        Returns:
            The login result from the API.
        """
        password = passwd if totp is None else f"{passwd}{totp}"
        return await self._post(
            "/api/auth/login",
            json={"user": user, "passwd": password},
        )

    async def check(self) -> Any:
        """Check authentication status.

        Returns:
            The auth check result from the API.
        """
        return await self._get("/api/auth/check")

    async def logout(self) -> Any:
        """Log out of the current session.

        Returns:
            The logout result from the API.
        """
        return await self._post("/api/auth/logout")

login(user, passwd, totp=None) async

Log in with credentials.

Parameters:

Name Type Description Default
user str

Username.

required
passwd str

Password.

required
totp str | None

Optional TOTP code (concatenated to password).

None

Returns:

Type Description
Any

The login result from the API.

Source code in src/aiopikvm/resources/auth.py
async def login(self, user: str, passwd: str, totp: str | None = None) -> Any:
    """Log in with credentials.

    Args:
        user: Username.
        passwd: Password.
        totp: Optional TOTP code (concatenated to password).

    Returns:
        The login result from the API.
    """
    password = passwd if totp is None else f"{passwd}{totp}"
    return await self._post(
        "/api/auth/login",
        json={"user": user, "passwd": password},
    )

check() async

Check authentication status.

Returns:

Type Description
Any

The auth check result from the API.

Source code in src/aiopikvm/resources/auth.py
async def check(self) -> Any:
    """Check authentication status.

    Returns:
        The auth check result from the API.
    """
    return await self._get("/api/auth/check")

logout() async

Log out of the current session.

Returns:

Type Description
Any

The logout result from the API.

Source code in src/aiopikvm/resources/auth.py
async def logout(self) -> Any:
    """Log out of the current session.

    Returns:
        The logout result from the API.
    """
    return await self._post("/api/auth/logout")