Skip to content

CallbackHandler

authx._internal._callback._CallbackHandler

_CallbackHandler(model=None)

Bases: Generic[T]

Base class for callback handlers in AuthX.

PARAMETER DESCRIPTION
Generic

Model type

TYPE: T

RAISES DESCRIPTION
AttributeError

If callback is not set

Base class for callback handlers in AuthX.

PARAMETER DESCRIPTION
model

TYPE: Optional[T] DEFAULT: None

PARAMETER DESCRIPTION
model

Model instance

TYPE: T DEFAULT: None

Source code in authx/_internal/_callback.py
def __init__(self, model: Optional[T] = None) -> None:
    """Base class for callback handlers in AuthX.

    Args:
        model (T): Model instance
    """
    self._model: Optional[T] = model
    self.callback_get_model_instance: Optional[ModelCallback[T]] = None
    self.callback_is_token_in_blocklist: Optional[TokenCallback] = None

    # Exceptions
    self._callback_model_set_exception = AttributeError(
        f"Model callback not set for {self._model.__class__.__name__} instance"
    )
    self._callback_token_set_exception = AttributeError(
        f"Token callback not set for {self._model.__class__.__name__} instance"
    )

callback_get_model_instance instance-attribute

callback_get_model_instance = None

callback_is_token_in_blocklist instance-attribute

callback_is_token_in_blocklist = None

is_model_callback_set property

is_model_callback_set

Check if callback is set for model instance

is_token_callback_set property

is_token_callback_set

Check if callback is set for token

set_callback_get_model_instance

set_callback_get_model_instance(callback)

Set callback for model instance

PARAMETER DESCRIPTION
callback

TYPE: ModelCallback[T]

Source code in authx/_internal/_callback.py
def set_callback_get_model_instance(self, callback: ModelCallback[T]) -> None:
    """Set callback for model instance"""
    self.callback_get_model_instance = callback

set_callback_token_blocklist

set_callback_token_blocklist(callback)

Set callback for token

PARAMETER DESCRIPTION
callback

TYPE: TokenCallback

Source code in authx/_internal/_callback.py
def set_callback_token_blocklist(self, callback: TokenCallback) -> None:
    """Set callback for token"""
    self.callback_is_token_in_blocklist = callback

set_subject_getter

set_subject_getter(callback)

Set the callback to run for subject retrieval and serialization

PARAMETER DESCRIPTION
callback

TYPE: ModelCallback[T]

Source code in authx/_internal/_callback.py
def set_subject_getter(self, callback: ModelCallback[T]) -> None:
    """Set the callback to run for subject retrieval and serialization"""
    self.set_callback_get_model_instance(callback)

set_token_blocklist

set_token_blocklist(callback)

Set the callback to run for validation of revoked tokens

PARAMETER DESCRIPTION
callback

TYPE: TokenCallback

Source code in authx/_internal/_callback.py
def set_token_blocklist(self, callback: TokenCallback) -> None:
    """Set the callback to run for validation of revoked tokens"""
    self.set_callback_token_blocklist(callback)

is_token_in_blocklist

is_token_in_blocklist(token, **kwargs)

Check if token is in blocklist

PARAMETER DESCRIPTION
token

TYPE: Optional[str]

**kwargs

TYPE: ParamSpecKwargs DEFAULT: {}

Source code in authx/_internal/_callback.py
def is_token_in_blocklist(
    self, token: Optional[str], **kwargs: ParamSpecKwargs
) -> bool:
    """Check if token is in blocklist"""
    if self._check_token_callback_is_set(ignore_errors=True):
        callback: Optional[TokenCallback] = self.callback_is_token_in_blocklist
        if callback is not None and token is not None:
            return callback(token, **kwargs)  # type: ignore
    return False