Skip to content

TokenAuth

Bases: BaseAuth

Authentication using a pre-supplied token

Attributes:

Name Type Description
endpoint str

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

Example
>>> auth = TokenAuth('<token>')
>>> auth.authenticate()
{'Authorization : 'Bearer <token>'}
Source code in src/plankapy/handlers.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
class TokenAuth(BaseAuth):
    """Authentication using a pre-supplied token

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

    Example:
        ```python
        >>> auth = TokenAuth('<token>')
        >>> auth.authenticate()
        {'Authorization : 'Bearer <token>'}
        ```
    """
    endpoint = 'api/access-tokens'

    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

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

__init__(token)

Initialize a TokenAuth instance with a token

Parameters:

Name Type Description Default
token str

The token to use for authentication

required
Source code in src/plankapy/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(url=None)

Implementation of the authenticate method

Parameters:

Name Type Description Default
url str

Not used, but required by the protocol

None

Returns:

Type Description
dict[str, str]

Headers with the token in the Authorization key

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