Auth¶
- class pyniryo_nate.components.Auth(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]¶
Bases:
BaseAPIComponentAuthentication 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
closeClose the component and release any resources if needed.
Log in to the API.
Set the callback to call when a user logs in.
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_atcarries no timezone.- Return type:
- 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]