Skip to content

PasswordAuth

Bases: BaseAuth

Authentication using a username or email and password

Attributes:

Name Type Description
endpoint str

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

Source code in src/plankapy/handlers.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
class PasswordAuth(BaseAuth):
    """Authentication using a username or email and password

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

    endpoint = 'api/access-tokens'

    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
        }

    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}"}

__init__(username_or_email, password)

Initialize a PasswordAuth instance with a username or email and password

Parameters:

Name Type Description Default
username_or_email str

The username or email to use for authentication

required
password str

The password to use for authentication

required
Example
>>> auth = PasswordAuth('username', 'password')
>>> auth.authenticate('http://planka.instance')
{'Authorization' : 'Bearer <token>'}
Source code in src/plankapy/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(url)

Implementation of the authenticate method

Parameters:

Name Type Description Default
url str

The base url of the Planka instance

required

Returns:

Type Description
dict[str, str]

Headers with the token in the Authorization key

Source code in src/plankapy/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}"}