Skip to content

TokenAuth

Bases: BaseAuth

Authentication using a pre-supplied token

ATTRIBUTE DESCRIPTION
endpoint

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

TYPE: str

Example
>>> auth = TokenAuth('<token>')
>>> auth.authenticate()
{'Authorization : 'Bearer <token>'}

Initialize a TokenAuth instance with a token

PARAMETER DESCRIPTION

token

The token to use for authentication

TYPE: str

METHOD DESCRIPTION
authenticate

Implementation of the authenticate method

Source code in src/plankapy/v1/handlers.py
289
290
291
292
293
294
295
def __init__(self, token: str) -> None:
    """Initialize a TokenAuth instance with a token

    Args:
        token (str): The token to use for authentication
    """
    self.token = token

authenticate

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

Implementation of the authenticate method

PARAMETER DESCRIPTION

url

Not used, but required by the protocol

TYPE: str DEFAULT: None

RETURNS DESCRIPTION
dict[str, str]

Headers with the token in the Authorization key

Source code in src/plankapy/v1/handlers.py
297
298
299
300
301
302
303
304
305
306
def authenticate(self, url: str=None) -> dict[str, str]:
    """Implementation of the authenticate method

    Args:
        url (str): Not used, but required by the protocol

    Returns:
       Headers with the token in the `Authorization` key
    """
    return {"Authorization": f"Bearer {self.token}"}