auth
pyDataverse.auth
This module contains authentication handlers compatible with :class:httpx.Auth
class ApiTokenAuth
Section titled “class ApiTokenAuth”An authentication handler to add an API token as the X-Dataverse-key header.
For more information on how to retrieve an API token and how it is used, please refer to https://guides.dataverse.org/en/latest/api/auth.html.
Methods
__init__
Section titled “__init__”__init__(self, api_token: str)Initializes the auth handler with an API token.
Parameters
Section titled “Parameters”api_token : str The API token retrieved from your Dataverse instance user profile.
Examples
Section titled “Examples”>>> import os >>> from pyDataverse.api import DataAccessApi >>> base_url = ‘https://demo.dataverse.org’ >>> api_token_auth = ApiTokenAuth(os.getenv(‘API_TOKEN’)) >>> api = DataAccessApi(base_url, api_token_auth)
auth_flow
Section titled “auth_flow”auth_flow(self, request: Request) -> Generator[Request, Response, None]Adds the X-Dataverse-key header with the API token and yields the
original :class:httpx.Request.
Parameters
Section titled “Parameters”request : httpx.Request The request object which requires authentication headers
Yields
Section titled “Yields”httpx.Request The original request with modified headers
class BearerTokenAuth
Section titled “class BearerTokenAuth”An authentication handler to add a Bearer token as defined in RFC 6750 <https://datatracker.ietf.org/doc/html/rfc6750>_ to the request.
A bearer token could be obtained from an OIDC provider, for example, Keycloak.
Methods
__init__
Section titled “__init__”__init__(self, bearer_token: str)Initializes the auth handler with a bearer token.
Parameters
Section titled “Parameters”bearer_token : str The bearer token retrieved from your OIDC provider.
Examples
Section titled “Examples”>>> import os >>> from pyDataverse.api import DataAccessApi >>> base_url = ‘https://demo.dataverse.org’ >>> bearer_token_auth = OAuthBearerTokenAuth(os.getenv(‘OAUTH_TOKEN’)) >>> api = DataAccessApi(base_url, bearer_token_auth)
auth_flow
Section titled “auth_flow”auth_flow(self, request: Request) -> Generator[Request, Response, None]Adds the X-Dataverse-key header with the API token and yields the
original :class:httpx.Request.
Parameters
Section titled “Parameters”request : httpx.Request The request object which requires authentication headers
Yields
Section titled “Yields”httpx.Request The original request with modified headers