Skip to content

AuthXConfig

authx.config.AuthXConfig

AuthXConfig(__pydantic_self__, _case_sensitive=None, _env_prefix=None, _env_file=ENV_FILE_SENTINEL, _env_file_encoding=None, _env_ignore_empty=None, _env_nested_delimiter=None, _env_parse_none_str=None, _secrets_dir=None, **values)

Bases: BaseSettings

AuthX Base Configuration Object

PARAMETER DESCRIPTION
BaseSettings

BaseSettings class from Pydantic

TYPE: BaseSettings

RAISES DESCRIPTION
BadConfigurationError

If JWT_ALGORITHM is not supported

BadConfigurationError

If JWT_ALGORITHM requires a key and it is not set

RETURNS DESCRIPTION
AuthXConfig

AuthX Configuration Object

PARAMETER DESCRIPTION
__pydantic_self__

_case_sensitive

TYPE: bool | None DEFAULT: None

_env_prefix

TYPE: str | None DEFAULT: None

_env_file

TYPE: DotenvType | None DEFAULT: ENV_FILE_SENTINEL

_env_file_encoding

TYPE: str | None DEFAULT: None

_env_ignore_empty

TYPE: bool | None DEFAULT: None

_env_nested_delimiter

TYPE: str | None DEFAULT: None

_env_parse_none_str

TYPE: str | None DEFAULT: None

_secrets_dir

TYPE: str | Path | None DEFAULT: None

**values

TYPE: Any DEFAULT: {}

Source code in pydantic_settings/main.py
def __init__(
    __pydantic_self__,
    _case_sensitive: bool | None = None,
    _env_prefix: str | None = None,
    _env_file: DotenvType | None = ENV_FILE_SENTINEL,
    _env_file_encoding: str | None = None,
    _env_ignore_empty: bool | None = None,
    _env_nested_delimiter: str | None = None,
    _env_parse_none_str: str | None = None,
    _secrets_dir: str | Path | None = None,
    **values: Any,
) -> None:
    # Uses something other than `self` the first arg to allow "self" as a settable attribute
    super().__init__(
        **__pydantic_self__._settings_build_values(
            values,
            _case_sensitive=_case_sensitive,
            _env_prefix=_env_prefix,
            _env_file=_env_file,
            _env_file_encoding=_env_file_encoding,
            _env_ignore_empty=_env_ignore_empty,
            _env_nested_delimiter=_env_nested_delimiter,
            _env_parse_none_str=_env_parse_none_str,
            _secrets_dir=_secrets_dir,
        )
    )

model_config class-attribute

model_config = SettingsConfigDict(extra='forbid', arbitrary_types_allowed=True, validate_default=True, case_sensitive=False, env_prefix='', env_file=None, env_file_encoding=None, env_ignore_empty=False, env_nested_delimiter=None, env_parse_none_str=None, json_file=None, json_file_encoding=None, yaml_file=None, yaml_file_encoding=None, toml_file=None, secrets_dir=None, protected_namespaces=('model_', 'settings_'))

JWT_ACCESS_TOKEN_EXPIRES class-attribute instance-attribute

JWT_ACCESS_TOKEN_EXPIRES = timedelta(minutes=15)

JWT_ALGORITHM class-attribute instance-attribute

JWT_ALGORITHM = 'HS256'

JWT_DECODE_ALGORITHMS class-attribute instance-attribute

JWT_DECODE_ALGORITHMS = Field(default_factory=lambda: ['HS256'])

JWT_DECODE_AUDIENCE class-attribute instance-attribute

JWT_DECODE_AUDIENCE = None

JWT_DECODE_ISSUER class-attribute instance-attribute

JWT_DECODE_ISSUER = None

JWT_DECODE_LEEWAY class-attribute instance-attribute

JWT_DECODE_LEEWAY = 0

JWT_ENCODE_AUDIENCE class-attribute instance-attribute

JWT_ENCODE_AUDIENCE = None

JWT_ENCODE_ISSUER class-attribute instance-attribute

JWT_ENCODE_ISSUER = None

JWT_ENCODE_NBF class-attribute instance-attribute

JWT_ENCODE_NBF = True

JWT_ERROR_MESSAGE_KEY class-attribute instance-attribute

JWT_ERROR_MESSAGE_KEY = 'msg'

JWT_IDENTITY_CLAIM class-attribute instance-attribute

JWT_IDENTITY_CLAIM = 'sub'

JWT_PRIVATE_KEY class-attribute instance-attribute

JWT_PRIVATE_KEY = None

JWT_PUBLIC_KEY class-attribute instance-attribute

JWT_PUBLIC_KEY = None

JWT_REFRESH_TOKEN_EXPIRES class-attribute instance-attribute

JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=20)

JWT_SECRET_KEY class-attribute instance-attribute

JWT_SECRET_KEY = None

JWT_TOKEN_LOCATION class-attribute instance-attribute

JWT_TOKEN_LOCATION = Field(['headers'])

JWT_HEADER_NAME class-attribute instance-attribute

JWT_HEADER_NAME = 'Authorization'

JWT_HEADER_TYPE class-attribute instance-attribute

JWT_HEADER_TYPE = 'Bearer'
JWT_ACCESS_COOKIE_NAME = 'access_token_cookie'
JWT_ACCESS_COOKIE_PATH = '/'
JWT_COOKIE_CSRF_PROTECT = True
JWT_COOKIE_DOMAIN = None
JWT_COOKIE_MAX_AGE = None
JWT_COOKIE_SAMESITE = 'Lax'
JWT_COOKIE_SECURE = True
JWT_REFRESH_COOKIE_NAME = 'refresh_token_cookie'
JWT_REFRESH_COOKIE_PATH = '/'
JWT_SESSION_COOKIE = True
JWT_ACCESS_CSRF_COOKIE_NAME = 'csrf_access_token'
JWT_ACCESS_CSRF_COOKIE_PATH = '/'

JWT_ACCESS_CSRF_FIELD_NAME class-attribute instance-attribute

JWT_ACCESS_CSRF_FIELD_NAME = 'csrf_token'

JWT_ACCESS_CSRF_HEADER_NAME class-attribute instance-attribute

JWT_ACCESS_CSRF_HEADER_NAME = 'X-CSRF-TOKEN'

JWT_CSRF_CHECK_FORM class-attribute instance-attribute

JWT_CSRF_CHECK_FORM = False

JWT_CSRF_IN_COOKIES class-attribute instance-attribute

JWT_CSRF_IN_COOKIES = True

JWT_CSRF_METHODS class-attribute instance-attribute

JWT_CSRF_METHODS = Field(default_factory=lambda: ['POST', 'PUT', 'PATCH', 'DELETE'])
JWT_REFRESH_CSRF_COOKIE_NAME = 'csrf_refresh_token'
JWT_REFRESH_CSRF_COOKIE_PATH = '/'

JWT_REFRESH_CSRF_FIELD_NAME class-attribute instance-attribute

JWT_REFRESH_CSRF_FIELD_NAME = 'csrf_token'

JWT_REFRESH_CSRF_HEADER_NAME class-attribute instance-attribute

JWT_REFRESH_CSRF_HEADER_NAME = 'X-CSRF-TOKEN'

JWT_QUERY_STRING_NAME class-attribute instance-attribute

JWT_QUERY_STRING_NAME = 'token'

JWT_JSON_KEY class-attribute instance-attribute

JWT_JSON_KEY = 'access_token'

JWT_REFRESH_JSON_KEY class-attribute instance-attribute

JWT_REFRESH_JSON_KEY = 'refresh_token'

JWT_IMPLICIT_REFRESH_ROUTE_EXCLUDE class-attribute instance-attribute

JWT_IMPLICIT_REFRESH_ROUTE_EXCLUDE = Field(default_factory=list)

JWT_IMPLICIT_REFRESH_ROUTE_INCLUDE class-attribute instance-attribute

JWT_IMPLICIT_REFRESH_ROUTE_INCLUDE = Field(default_factory=list)

JWT_IMPLICIT_REFRESH_METHOD_EXCLUDE class-attribute instance-attribute

JWT_IMPLICIT_REFRESH_METHOD_EXCLUDE = Field(default_factory=list)

JWT_IMPLICIT_REFRESH_METHOD_INCLUDE class-attribute instance-attribute

JWT_IMPLICIT_REFRESH_METHOD_INCLUDE = Field(default_factory=list)

JWT_IMPLICIT_REFRESH_DELTATIME class-attribute instance-attribute

JWT_IMPLICIT_REFRESH_DELTATIME = timedelta(minutes=10)

is_algo_symmetric property

is_algo_symmetric

Check if the JWT_ALGORITHM is a symmetric encryption algorithm

is_algo_asymmetric property

is_algo_asymmetric

Check if the JWT_ALGORITHM is an asymmetric encryption algorithm

private_key property

private_key

Private key to encode token

public_key property

public_key

Public key to decode token

settings_customise_sources classmethod

settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)

Define the sources and their order for loading the settings values.

PARAMETER DESCRIPTION
settings_cls

TYPE: type[BaseSettings]

init_settings

TYPE: PydanticBaseSettingsSource

env_settings

TYPE: PydanticBaseSettingsSource

dotenv_settings

TYPE: PydanticBaseSettingsSource

file_secret_settings

TYPE: PydanticBaseSettingsSource

PARAMETER DESCRIPTION
settings_cls

The Settings class.

TYPE: type[BaseSettings]

init_settings

The InitSettingsSource instance.

TYPE: PydanticBaseSettingsSource

env_settings

The EnvSettingsSource instance.

TYPE: PydanticBaseSettingsSource

dotenv_settings

The DotEnvSettingsSource instance.

TYPE: PydanticBaseSettingsSource

file_secret_settings

The SecretsSettingsSource instance.

TYPE: PydanticBaseSettingsSource

RETURNS DESCRIPTION
tuple[PydanticBaseSettingsSource, ...]

A tuple containing the sources and their order for loading the settings values.

Source code in pydantic_settings/main.py
@classmethod
def settings_customise_sources(
    cls,
    settings_cls: type[BaseSettings],
    init_settings: PydanticBaseSettingsSource,
    env_settings: PydanticBaseSettingsSource,
    dotenv_settings: PydanticBaseSettingsSource,
    file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]:
    """
    Define the sources and their order for loading the settings values.

    Args:
        settings_cls: The Settings class.
        init_settings: The `InitSettingsSource` instance.
        env_settings: The `EnvSettingsSource` instance.
        dotenv_settings: The `DotEnvSettingsSource` instance.
        file_secret_settings: The `SecretsSettingsSource` instance.

    Returns:
        A tuple containing the sources and their order for loading the settings values.
    """
    return init_settings, env_settings, dotenv_settings, file_secret_settings

has_location

has_location(location)

Check if the token location is enabled

PARAMETER DESCRIPTION
location

TYPE: str

Source code in authx/config.py
def has_location(self, location: str) -> bool:
    """Check if the token location is enabled"""
    return location in self.JWT_TOKEN_LOCATION