[docs]classBeskarError(SanicException,Buzz):""" Provides a custom exception class for sanic-beskar based on py-buzz. `py-buzz on gitub <https://github.com/dusktreader/py-buzz>`_ """status:int=401def__init__(self,message:str,*args:tuple,**kwargs:dict):self.status:int=self.statusself.message:str=f"{self.__class__.__name__}: {message}"self.extra_args:tuple=argsself.extra_kwargs:dict=kwargsself.json_response:JSONResponse=json({"error":message,"data":self.__class__.__name__,"status":self.status,},status=self.status,)super().__init__(self.message,self.status)def__str__(self)->str:"""string repr"""returnf"{super().__str__()} ({self.status})"
[docs]classMissingClaimError(BeskarError):""" The token is missing a required claim """pass
[docs]classBlacklistedError(BeskarError):""" The token has been blacklisted and may not be used any more """status=403
[docs]classExpiredAccessError(BeskarError):""" The token has expired for access and must be refreshed """pass
[docs]classEarlyRefreshError(BeskarError):""" The token has not yet expired for access and may not be refreshed """status=425# HTTP Status Code : 425 Too Early
[docs]classExpiredRefreshError(BeskarError):""" The token has expired for refresh. An entirely new token must be issued """pass
[docs]classMissingToken(BeskarError):""" The header is missing the required token """pass
[docs]classInvalidTokenHeader(BeskarError):""" The token contained in the header is invalid """pass
[docs]classVerifyError(InvalidTokenHeader):""" The token contained in the header is invalid """pass
[docs]classInvalidUserError(BeskarError):""" The user is no longer valid and is now not authorized """status=403
[docs]classMissingRoleError(BeskarError):""" The token is missing a required role """status=403
[docs]classMissingRightError(BeskarError):""" The token is missing a required right based upon role breakdown """status=403
[docs]classMissingUserError(BeskarError):""" The user could not be identified """pass
[docs]classAuthenticationError(BeskarError):""" The entered user's password did not match the stored password """pass
[docs]classClaimCollisionError(BeskarError):""" " Custom claims to pack into the payload collide with reserved claims """pass
[docs]classLegacyScheme(BeskarError):""" The processed hash is using an outdated scheme """pass
[docs]classInvalidResetToken(BeskarError):""" The supplied registration token is invalid """pass
[docs]classInvalidRegistrationToken(BeskarError):""" The supplied registration token is invalid """pass
[docs]classMisusedRegistrationToken(BeskarError):""" Attempted to use a registration token for normal access """pass
[docs]classMisusedResetToken(BeskarError):""" Attempted to use a password reset token for normal access """pass
[docs]classConfigurationError(BeskarError):""" There was a problem with the configuration """pass
[docs]classTOTPRequired(AuthenticationError):""" The user requires TOTP authentication, per configuration `BESKAR_TOTP_ENFORCE` which was not performed by this call to `authenticate()`. A call to `authenticate_totp()` should be performed separately, or a call to `authenticate()` again, but providing the users `token` value should be done. """pass