SmarterTokenAuthenticationMiddleware
- class smarter.lib.drf.middleware.SmarterTokenAuthenticationMiddleware(get_response)[source]
Bases:
MiddlewareMixin,SmarterHelperMixinMiddleware to authenticate requests via SmarterTokenAuthentication, a subclass of knox.auth TokenAuthentication tokens. Provides seamless token authentication for incoming requests.
Does the following:
Checks for the presence of an Authorization header with a valid token.
Uses SmarterTokenAuthentication to authenticate the token.
Logs authentication attempts and outcomes.
adds Django signals for token authentication events.
verifies token activity.
adds timestamp update on token use.
- Raises:
AuthenticationFailed – Raised when authentication fails.
SmarterTokenAuthenticationError – Raised for errors specific to SmarterTokenAuthentication.
- get_request_with_verified_user(request)[source]
Ensure the request has a user set, defaulting to SmarterAnonymousUser if not.
- Return type:
- Parameters:
request (HttpRequest) – The incoming HTTP request.