def__init__(self,model:Optional[T]=None)->None:"""Base class for callback handlers in AuthX. Args: model (T): Model instance """self._model:Optional[T]=modelself.callback_get_model_instance:Optional[ModelCallback[T]]=Noneself.callback_is_token_in_blocklist:Optional[TokenCallback]=None# Exceptionsself._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")
defset_callback_get_model_instance(self,callback:ModelCallback[T])->None:"""Set callback for model instance"""self.callback_get_model_instance=callback
defset_subject_getter(self,callback:ModelCallback[T])->None:"""Set the callback to run for subject retrieval and serialization"""self.set_callback_get_model_instance(callback)
defset_token_blocklist(self,callback:TokenCallback)->None:"""Set the callback to run for validation of revoked tokens"""self.set_callback_token_blocklist(callback)
defis_token_in_blocklist(self,token:Optional[str],**kwargs:ParamSpecKwargs)->bool:"""Check if token is in blocklist"""ifself._check_token_callback_is_set(ignore_errors=True):callback:Optional[TokenCallback]=self.callback_is_token_in_blocklistifcallbackisnotNoneandtokenisnotNone:returncallback(token,**kwargs)# type: ignorereturnFalse