user#

Description#

Plugin to programmatically create and manage users and user sessions

Configuration#

user:
    # No configuration required

Actions#

Module reference#

class platypush.plugins.user.UserPlugin(**kwargs)[source]#

Bases: Plugin

Plugin to programmatically create and manage users and user sessions

__init__(**kwargs)[source]#
authenticate_session(session_token)[source]#

Authenticate a session by token and return the associated user.

Returns:

{
    "user_id": 1,
    "username": "test-user",
    "created_at": "2020-11-26T22:41:40.550574"
}

authenticate_user(username: str, password: str, code: str | None = None, return_details: bool = False) bool | Tuple[bool, str][source]#

Authenticate a user.

Parameters:
  • username – Username.

  • password – Password.

  • code – Optional 2FA code, if 2FA is enabled for the user.

  • return_details – If True then return the error details in case of authentication failure.

Returns:

If return_details is False (default), the action returns True if the provided credentials are valid, False otherwise. If return_details is True then the action returns a tuple (authenticated, error_details) where authenticated is True if the provided credentials are valid, False otherwise, and error_details is a string containing the error details in case of authentication failure. Supported error details are:

  • invalid_credentials: Invalid username or password.

  • invalid_otp_code: Invalid 2FA code.

  • missing_otp_code: Username/password are correct, but a 2FA code is required for the user.

create_session(username, password, code=None, expires_at=None)[source]#

Create a user session.

Returns:

{
    "session_token": "secret",
    "user_id": 1,
    "username": "test-user",
    "created_at": "2020-11-26T22:41:40.550574",
    "expires_at": "2020-11-26T22:41:40.550574"
}

create_user(username, password, executing_user=None, executing_user_password=None, session_token=None, **kwargs)[source]#

Create a user. This action needs to be executed by an already existing user, who needs to authenticate with their own credentials, unless this is the first user created on the system.

Returns:

{
    "user_id": 1,
    "username": "test-user",
    "created_at": "2020-11-26T22:41:40.550574"
}

delete_session(session_token)[source]#

Delete a user session.

delete_user(username, executing_user=None, executing_user_password=None, session_token=None)[source]#

Delete a user.

get_user_by_session(session_token: str) dict[source]#

Get the user record associated to a session token.

Parameters:

session_token – Session token.

Returns:

[
    {
        "user_id": 1,
        "username": "user1",
        "created_at": "2020-11-26T22:41:40.550574"
    }
]

get_users() List[Dict[str, Any]][source]#

Get the list of registered users.

Returns:

[
    {
        "user_id": 1,
        "username": "user1",
        "created_at": "2020-11-26T22:41:40.550574"
    },
    {
        "user_id": 2,
        "username": "user2",
        "created_at": "2020-11-28T21:10:23.224813"
    }
]

update_password(username, old_password, new_password)[source]#

Update the password of a user.

Returns:

True if the password was successfully updated, false otherwise