Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmetkotan/tokenauth
Django Simple Token Authentication with Expiration Time and Prefix
https://github.com/ahmetkotan/tokenauth
django expire refresh rest token
Last synced: 7 days ago
JSON representation
Django Simple Token Authentication with Expiration Time and Prefix
- Host: GitHub
- URL: https://github.com/ahmetkotan/tokenauth
- Owner: ahmetkotan
- Created: 2019-01-27T11:17:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-28T06:50:35.000Z (almost 6 years ago)
- Last Synced: 2024-08-10T23:23:11.273Z (3 months ago)
- Topics: django, expire, refresh, rest, token
- Language: Python
- Size: 6.84 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
=====================================================================
Tokenauth
=====================================================================
Tokenauth developed for django rest token authentication. It enables you to define expiration time and token prefix. Tokens generate with random data and it use SHA-256 algorithm.Installation
============
on Pypi
::
pip install tokenauth
on Github
::
git clone [email protected]:ahmetkotan/tokenauth.git
cd tokenauth
python setup.py installSettings
============
Added to `INSTALLED_APPS`.
::INSTALLED_APPS = [
...
'tokenauth',
...
]Added to `urls.py`.
::
urlpatterns = [
...
url(r'^/', include('tokenauth.urls')),
...
]Definition in `settings.py`
::
TOKEN_EXPIRATION_TIME = 60 * 60 * 24 * 3 # Default 3 days
TOKEN_PREFIX = "Bearer"
TOKEN_REFRESH = TrueUsage
=====
Definition in `settings.py`
::
# Rest Framework
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': (
'tokenauth.auth.TokenAuthentication',
),
...
}Or in `views.py`
::
from tokenauth.auth import TokenAuthentication
class SimpleView(ModelViewset):
authentication_classes = (TokenAuthentication, )Created token and login:
::
curl -X POST -H "Content-Type: application/json" -d '{"username": "", "password":""}' //tokens/Refresh token:
::
curl -X PUT -H "Content-Type: application/json" -d '{"key": ""}' //tokens/Deleted token and logout:
::
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: " //tokens/