What is django-rest-knox?
developdjango-rest-knox is an authentication module for Django REST Framework (DRF) that provides token-based authentication. It improves upon DRF's built-in TokenAuthentication in three key ways:
- Multiple Tokens per User: Unlike DRF, which limits users to one token, Knox allows each device/client to have its own unique token. This enables individual device logout and the ability to revoke all tokens for a user simultaneously.
- Secure Token Storage: Knox stores tokens as secure hashes (similar to passwords) rather than unencrypted strings. This protects accounts even if the database is compromised.
- Token Expiration: Knox supports configurable token expiration, whereas DRF tokens do not have an inbuilt expiration mechanism. By default, tokens expire after 10 hours.