from typing import List from structlog import getLogger from delphi_api.const import AUTH0_API_AUDIENCE, AUTH0_DOMAIN, DEFAULT_OAUTH2_FLOW from delphi_api.core import BaseStruct LOG = getLogger(__name__) class AuthCredentials(BaseStruct): """Auth credentials helper class.""" audience: str = AUTH0_API_AUDIENCE client_id: str = None client_secret: str = None grant_type: str = DEFAULT_OAUTH2_FLOW scope: str = None @property def access_token_url(self) -> str: return f'https://{AUTH0_DOMAIN}/oauth/token' @property def api_base_url(self) -> str: return f'https://{AUTH0_DOMAIN}' @property def authorize_url(self) -> str: return f'https://{AUTH0_DOMAIN}/authorize' @property def client_kwargs(self) -> dict: data = { 'token_placement': 'header', } if self.scope: data.update({'scope': f'{self.scope}'}) return data @property def token_endpoint_auth_method(self) -> str: """ Defines the requested authentication method for the token endpoint. Possible values are 'none' (public application without a client secret), 'post' (application uses HTTP POST parameters) or 'basic' (application uses HTTP Basic). """ return 'client_secret_post' def _ignore_fields(self) -> List[str]: """ Properties to ignore when calling ``.to_dict()`` that will give us a nice dictionary to pass as kwargs for the auth flask wrapper """ return []