Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Latest commit

 

History

History
173 lines (88 loc) · 4.6 KB

auth.md

File metadata and controls

173 lines (88 loc) · 4.6 KB

module auth


class CartoAuth

CARTO Authentication object used to gather connect with the CARTO services.

Args:

  • mode (str): Type of authentication: oauth, m2m.
  • api_base_url (str, optional): Base URL for a CARTO account.
  • access_token (str, optional): Token already generated with CARTO.
  • expiration (int, optional): Time in seconds when the token will be expired.
  • client_id (str, optional): Client id of a M2M application provided by CARTO.
  • client_secret (str, optional): Client secret of a M2M application provided by CARTO.
  • cache_filepath (str, optional): File path where the token is stored. Default "home()/.carto-auth/token.json".
  • use_cache (bool, optional): Whether the stored cached token should be used. Default True.
  • open_browser (bool, optional): Whether the web browser should be opened to authorize a user. Default True.

method __init__

__init__(
    mode,
    api_base_url=None,
    access_token=None,
    expiration=None,
    client_id=None,
    client_secret=None,
    cache_filepath=None,
    use_cache=True,
    open_browser=True
)

classmethod from_m2m

from_m2m(filepath, cache_filepath=None, use_cache=True)

Create a CartoAuth object using CARTO credentials file.

Args:

  • filepath (str): File path of the CARTO credentials file.
  • cache_filepath (str, optional): File path where the token is stored. Default "home()/.carto-auth/token_m2m.json".
  • use_cache (bool, optional): Whether the stored cached token should be used. Default True.

Raises:

  • AttributeError: If the CARTO credentials file does not contain the attributes "api_base_url", "client_id", "client_secret".
  • ValueError: If the CARTO credentials file does not contain any attribute value.

classmethod from_oauth

from_oauth(cache_filepath=None, use_cache=True, open_browser=True)

Create a CartoAuth object using OAuth with CARTO.

Args:

  • cache_filepath (str, optional): File path where the token is stored. Default "home()/.carto-auth/token_oauth.json".
  • use_cache (bool, optional): Whether the stored cached token should be used. Default True.
  • open_browser (bool, optional): Whether the web browser should be opened to authorize a user. Default True.

method get_access_token

get_access_token()

method get_api_base_url

get_api_base_url()

method get_carto_dw_client

get_carto_dw_client()

Returns a client to query directly the CARTO Data Warehouse.

It requires extra dependencies carto-auth[carto-dw] to be installed.


method get_carto_dw_credentials

get_carto_dw_credentials() → tuple

Get the CARTO Data Warehouse credentials.

Returns:

  • tuple: carto_dw_project, carto_dw_token.

Raises:

  • CredentialsError: If the API Base URL is not provided, the response is not JSON or has invalid attributes.