Auth

class pyniryo_nate.components.Auth(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]

Bases: BaseAPIComponent

Authentication component for managing user sessions and monitoring login/logout events.

This component provides methods for: - Logging in to obtain authentication tokens - Monitoring user login and logout events via callbacks

Methods

close

Close the component and release any resources if needed.

login

Log in to the API.

on_user_logged_in

Set the callback to call when a user logs in.

on_user_logged_out

Set the callback to call when a user logs out.

Parameters:
  • http_client (HttpClient)

  • mqtt_client (MqttClient)

  • correlation_id (str)

login(login: str, password: str, expires_at: datetime | None = None) → Token[source]

Log in to the API.

Parameters:
  • login (str) – The login of the user, its email.

  • password (str) – The password of the user.

  • expires_at (datetime | None) – The expiration date of the token, timezone-aware. If None, the robot picks it.

Returns:

The token generated for this login session.

Raises:

DataValidationError – If expires_at carries no timezone.

Return type:

Token

on_user_logged_in(callback: Callable[[str, UserEvent], None], user_id: str | None = None) → Callable[[], None][source]

Set the callback to call when a user logs in.

Parameters:
  • callback (Callable[[str, UserEvent], None]) – The callback to call. The callback must take the user ID and the payload as parameters.

  • user_id (str | None) – The user ID to listen to. If not specified, listen to all users.

Return type:

Callable[[], None]

on_user_logged_out(callback: Callable[[str, UserEvent], None], user_id: str | None = None) → Callable[[], None][source]

Set the callback to call when a user logs out.

Parameters:
  • callback (Callable[[str, UserEvent], None]) – The callback to call. The callback must take the user ID and the payload as parameters.

  • user_id (str | None) – The user ID to listen to. If not specified, listen to all users.

Return type:

Callable[[], None]