The tokenauth
app provides a set of models, decorators, and a custom authentication backend that can be used to
add simple token-based authentication to a Django project.
An access token has the following characteristics:
- It is valid for a single user and resource combination.
- It expires after a period of time automatically. By default this is two hours but it's configurable.
from tokenauth.models import AccessToken
token = AccessToken.create_token(resource, user)
is_valid, token = AccessToken.validate(access_token_as_string, resource_id)
if is_valid:
... # do something
else:
... # do something else
More examples in the documentation.