Skip to content

auth

pyDataverse.auth

This module contains authentication handlers compatible with :class:httpx.Auth

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__(self, api_token: str)

Initializes the auth handler with an API token.

api_token : str The API token retrieved from your Dataverse instance user profile.

>>> 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(self, request: Request) -> Generator[Request, Response, None]

Adds the X-Dataverse-key header with the API token and yields the original :class:httpx.Request.

request : httpx.Request The request object which requires authentication headers

httpx.Request The original request with modified headers

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__(self, bearer_token: str)

Initializes the auth handler with a bearer token.

bearer_token : str The bearer token retrieved from your OIDC provider.

>>> 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(self, request: Request) -> Generator[Request, Response, None]

Adds the X-Dataverse-key header with the API token and yields the original :class:httpx.Request.

request : httpx.Request The request object which requires authentication headers

httpx.Request The original request with modified headers