Skip to content

PasswordAuth

Bases: BaseAuth

Authentication using a username or email and password

ATTRIBUTE DESCRIPTION
endpoint

The token to use for authentication (default: 'api/access-tokens')

TYPE: str

Initialize a PasswordAuth instance with a username or email and password

PARAMETER DESCRIPTION

username_or_email

The username or email to use for authentication

TYPE: str

password

The password to use for authentication

TYPE: str

Example
>>> auth = PasswordAuth('username', 'password')
>>> auth.authenticate('http://planka.instance')
{'Authorization' : 'Bearer <token>'}
METHOD DESCRIPTION
authenticate

Implementation of the authenticate method

Source code in src/plankapy/v1/handlers.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def __init__(self, username_or_email: str, password: str) -> None:
    """Initialize a PasswordAuth instance with a username or email and password

    Args:
        username_or_email (str): The username or email to use for authentication
        password (str): The password to use for authentication

    Example:
        ```python
        >>> auth = PasswordAuth('username', 'password')
        >>> auth.authenticate('http://planka.instance')
        {'Authorization' : 'Bearer <token>'}
        ```    
    """
    self.token = None
    self.credentials = {
        'emailOrUsername': username_or_email,
        'password': password
    }

authenticate

authenticate(url: str) -> dict[str, str]

Implementation of the authenticate method

PARAMETER DESCRIPTION

url

The base url of the Planka instance

TYPE: str

RETURNS DESCRIPTION
dict[str, str]

Headers with the token in the Authorization key

Source code in src/plankapy/v1/handlers.py
262
263
264
265
266
267
268
269
270
271
272
def authenticate(self, url: str) -> dict[str, str]:
    """Implementation of the authenticate method

    Args:
        url (str): The base url of the Planka instance

    Returns:
        Headers with the token in the `Authorization` key
    """
    self.token = JSONHandler(url, endpoint=self.endpoint).post(self.credentials)['item']
    return {"Authorization": f"Bearer {self.token}"}