About
A new authentication backend for Django REST framework that uses a token with an expiration date. A new token is created every time a user logs in. The token expiration date is refreshed every time the token is used. It supports custom user models
How To Use
Add to your installed apps
INSTALLED_APPS = (
...
'timed_auth_token',
)
Add the authentication class to the default authentication classes
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'timed_auth_token.authentication.TimedAuthTokenAuthentication',
)
}
The app comes with a login URL at /login. The endpoint expects two parameters: username and password.
url_patterns = [
...
# Can login by using /auth/login
url(r'^auth/', include('timed_auth_token.urls', namespace='auth')),
]
After a successful login the response contains one key: token.
{'token': 'lkjalsdjf8asdkjfal;kdfa8s;dlna;sdf'}
To use this token to authenticate it must be included in the HTTP headers:
Authorization: Token YOURTOKEN
Configuration
The only available configuration option is the duration of the token. It defaults to 30 days. You can set it either on the user model as an attribute or as a setting in your settings.py. If they are both set, the user model will take precedence.
Put it on your user model as an attribute
from datetime import timedelta from django.contrib.auth.models import User class MyUserModel(User): token_validity_duration = timedelta(days=60)Put it in your settings.py
from datetime import timedelta TIMED_AUTH_TOKEN = { 'DEFAULT_VALIDITY_DURATION': timedelta(days=45) }
Credits
Starting code (model, auth backend) thanks to Jake from jh.gg.
Metadata
Release files for djangorestframework-timed-auth-token 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| djangorestframework-timed-auth-token-1.3.0.tar.gz | 4.4 kB | Without provenance | Details for djangorestframework-timed-auth-token-1.3.0.tar.gz |
Release files / djangorestframework-timed-auth-token-1.3.0.tar.gz
| Download URL | djangorestframework-timed-auth-token-1.3.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31a0c2757ef8dc3bf1ff50adeaa78a4ceffeb46d743ae0d611b69c487362c565
|
|
BLAKE2b-256 checksum How to use checksums |
55a447df474254187ba22e48f3598e569354e002d8a4a1488d191cc4df3742ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for djangorestframework-timed-auth-token 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.