Smarter Token Authentication
- class smarter.lib.drf.token_authentication.SmarterTokenAuthentication(*args, **kwargs)[source]
Bases:
TokenAuthentication,SmarterHelperMixinEnhanced Django Rest Framework (DRF) knox TokenAuthentication.
This subclass adds:
adds an activation field to enable/disable tokens
adds Django signals for token authentication events
adds app logging
verifies token activity.
adds timestamp update on token use
- Raises:
AuthenticationFailed – for any failure to authenticate the token the request.
- authenticate_credentials(token)[source]
Override parent authenticate_credentials() to add token activity check and logging.
- Parameters:
token (
bytes) – The authentication token provided in the request.- Raises:
AuthenticationFailed – for any failure to authenticate the token the request.
AuthenticationFailed – _if the token is not active.
AuthenticationFailed – if the token is not a bytes instance.
- Returns:
A tuple containing the authenticated User and SmarterAuthToken.
- Return type:
- classmethod get_user_from_request(request)[source]
Override get_user_from_request() to add logging and to use SmarterAuthToken.
- Parameters:
request (
Request) – a Django request object.- Returns:
The authenticated user if the token is valid, otherwise SmarterAnonymousUser.
- Return type:
User|SmarterAnonymousUser
- model
alias of
SmarterAuthToken