Skip to main content

django-token-manager

A Django Rest Token Authentication system like telegram which will be using JWT as core with extended features.

Features

  • Validation of tokens first with jwt algorithms to filter not valid token formats, before hitting database.
  • Able to see list of active tokens of each user_id
  • Able to delete each token if needed
  • Able to remove all other tokens of each users and keep just existing one
  • Fetch useful info for each token request like os, ip and ...

Why django-token-manager

Reason to use this module is that by default if you are using jwt system for token authorization of client, you don't have control on existing tokens. Of course you can set a expire date for each token. But if the expiration date isn't arrived yet, you can't delete this token. What happens if you want to delete all sessions of a user. With jwt you don't have control on it, and you should wait for expiration of token to be arrived.

The purpose of this package, is to give more control on jwt tokens. For this there will be a lookup_id in payload of each jwt token. First token with be validated with jwt algorithms. Then payload lookup_id will be checked on database and if available will give access. And with this solution no need to query on a big string (session string) on database, if the jwt token is valid, will just query on a db_index ed field lookup_id.

Requirements

To use this package following needed. if not provided will be installed automatically.

Django>=2.0
djangorestframework>=3.0
django-jalali>=3.1.0
django-rest-captcha>=0.1.0

Installation

Note: This package is well tested on django>=2.0. But if you are using older versions can be used with minor changes in structure.

install using pip:

$ pip install django-token-manager

Usage

Now register app in your settings.py file.

INSTALLED_APPS = [
    "token_manager",
]

In your settings.py, add JSONWebTokenAuthentication to Django REST framework's DEFAULT_AUTHENTICATION_CLASSES.

REST_FRAMEWORK = {
    ...,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'token_manager.authentication.JSONWebTokenAuthentication',
        ...
    ),
}

This package uses user-agents package for fetching user agent info like device OS, IP address and ... So you should register below to be able to use it:

MIDDLEWARE = [
    ...,
    'django_user_agents.middleware.UserAgentMiddleware',
]

Remember to apply migration files in database:

python manage.py migrate

To get token:

curl -X POST -d "username=admin&password=admin" "http://localhost:8000/token/get/"

Verify token:

curl -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb29rdXBfaWQiOjUsInVzZXJfaWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJleHAiOjE1OTg1MjY4MjEsImVtYWlsIjoiIn0.l6JyGgAs_hBRejX1BpvA7PjubM2m89lV35PTVUBnV_I" "http://localhost:8000/token/manage/"

Metadata

Release files for django-token-manager 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-token-manager 1.1.2
File Size Uploaded Provenance Actions
django-token-manager-1.1.2.tar.gz 24.9 kB Without provenance Details for django-token-manager-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-token-manager 1.1.2
File Interpreter ABI Platform Actions
django_token_manager-1.1.2-py3-none-any.whl Python 3 none any Details for django_token_manager-1.1.2-py3-none-any.whl

Total release size: 53.7 kB

Release files / django-token-manager-1.1.2.tar.gz

Download URL django-token-manager-1.1.2.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e1e7ba86dfa9c3ce99a2d1706241137e6c638053a1564ba9b0e83ccabe0a297d
BLAKE2b-256 checksum
How to use checksums
b0708ad6801f1873c7a54143546cbc54d10f396d5fdc7de0804d91a458ce5860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Release files / django_token_manager-1.1.2-py3-none-any.whl

Download URL django_token_manager-1.1.2-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
081ed5804e074e7ee352e927afba178d2c83e746b8649a4209d798addc62f9bc
BLAKE2b-256 checksum
How to use checksums
084aefdf8fe809b6e733bf1f7d77aaa5106c9dd0686566a5980d75b8e63f4a53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Security for django-token-manager 1.1.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page