Name | django-ninja-jwt JSON |
Version |
5.3.5
JSON |
| download |
home_page | None |
Summary | Django Ninja JWT - JSON Web Token for Django-Ninja |
upload_time | 2024-11-16 04:04:52 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
# Ninja JWT

[](https://badge.fury.io/py/django-ninja-jwt)
[](https://pypi.python.org/pypi/django-ninja-jwt)
[](https://pypi.python.org/pypi/django-ninja-jwt)
[](https://pypi.python.org/pypi/django-ninja-jwt)
[](https://codecov.io/gh/eadwinCode/django-ninja-jwt)
[](https://pepy.tech/project/django-ninja-jwt)
## Abstract
Ninja JWT is a JSON Web Token (JWT) plugin for Django-Ninja.
This library is a fork of [Simple JWT](https://github.com/jazzband/djangorestframework-simplejwt) by Jazzband,
a widely-used JWT plugin for the [Django REST Framework](http://www.django-rest-framework.org).
#### Notice
This library does not address any issues present in the original SIMPLE JWT.
It only adds support for Django-Ninja and removes dependencies on DRF.
Subsequent updates from SIMPLE JWT will be reflected here over time.
For full documentation, [visit this page](https://eadwincode.github.io/django-ninja-jwt/).
#### Requirements
- Python >= 3.6
- Django >= 2.1
- Django-Ninja >= 0.16.1
- Django-Ninja-Extra >= 0.14.2
## Example
Checkout this sample project: https://github.com/eadwinCode/bookstoreapi
## Installation
Ninja JWT can be installed with pip:
```shell
pip install django-ninja-jwt
```
You also need to register the `NinjaJWTDefaultController` controller to your Django-Ninja API:
```python
from ninja_jwt.controller import NinjaJWTDefaultController
from ninja_extra import NinjaExtraAPI
api = NinjaExtraAPI()
api.register_controllers(NinjaJWTDefaultController)
```
The `NinjaJWTDefaultController` includes three routes: `obtain_token`, `refresh_token`, and `verify_token`.
It combines two subclasses, `TokenVerificationController` and `TokenObtainPairController`.
If you want to customize these routes, you can inherit from these controllers and modify their implementation:
```python
from ninja_extra import api_controller
from ninja_jwt.controller import TokenObtainPairController
@api_controller('token', tags=['Auth'])
class MyCustomController(TokenObtainPairController):
"""obtain_token and refresh_token only"""
...
api.register_controllers(MyCustomController)
```
To use localizations/translations, add `ninja_jwt` to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = [
...
'ninja_jwt',
...
]
```
## Using Ninja Router
If you prefer not to follow the NinjaExtra methodology,
refer to this [documentation](https://eadwincode.github.io/django-ninja-jwt/customizing_token_claims/#use-django-ninja-router)
on how to use `Ninja-JWT` with `Django-Ninja Router`.
## Usage
To verify that Ninja JWT is working, you can use curl to issue a couple
of test requests:
``` {.sourceCode .bash}
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"username": "davidattenborough", "password": "boatymcboatface"}' \
http://localhost:8000/api/token/pair
...
{
"access":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU",
"refresh":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}
```
You can use the returned access token to prove authentication for a
protected view:
``` {.sourceCode .bash}
curl \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU" \
http://localhost:8000/api/some-protected-view/
```
When this short-lived access token expires, you can use the longer-lived
refresh token to obtain another access token:
``` {.sourceCode .bash}
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"refresh":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"}' \
http://localhost:8000/api/token/refresh
...
{"access":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w"}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "django-ninja-jwt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Ezeudoh Tochukwu <tochukwu.ezeudoh@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ea/2d/628cf2bd7b99fa16a84a89255e83e92a4b695b5b96820416eaa3eae92739/django_ninja_jwt-5.3.5.tar.gz",
"platform": null,
"description": "# Ninja JWT\n\n[](https://badge.fury.io/py/django-ninja-jwt)\n[](https://pypi.python.org/pypi/django-ninja-jwt)\n[](https://pypi.python.org/pypi/django-ninja-jwt)\n[](https://pypi.python.org/pypi/django-ninja-jwt)\n[](https://codecov.io/gh/eadwinCode/django-ninja-jwt)\n[](https://pepy.tech/project/django-ninja-jwt)\n\n\n## Abstract\n\nNinja JWT is a JSON Web Token (JWT) plugin for Django-Ninja.\nThis library is a fork of [Simple JWT](https://github.com/jazzband/djangorestframework-simplejwt) by Jazzband,\na widely-used JWT plugin for the [Django REST Framework](http://www.django-rest-framework.org).\n\n#### Notice\n\nThis library does not address any issues present in the original SIMPLE JWT.\nIt only adds support for Django-Ninja and removes dependencies on DRF.\nSubsequent updates from SIMPLE JWT will be reflected here over time.\n\nFor full documentation, [visit this page](https://eadwincode.github.io/django-ninja-jwt/).\n#### Requirements\n- Python >= 3.6\n- Django >= 2.1\n- Django-Ninja >= 0.16.1\n- Django-Ninja-Extra >= 0.14.2\n\n## Example\nCheckout this sample project: https://github.com/eadwinCode/bookstoreapi\n\n\n## Installation\n\nNinja JWT can be installed with pip:\n\n```shell\npip install django-ninja-jwt\n```\n\nYou also need to register the `NinjaJWTDefaultController` controller to your Django-Ninja API:\n\n```python\nfrom ninja_jwt.controller import NinjaJWTDefaultController\nfrom ninja_extra import NinjaExtraAPI\n\napi = NinjaExtraAPI()\napi.register_controllers(NinjaJWTDefaultController)\n```\n\nThe `NinjaJWTDefaultController` includes three routes: `obtain_token`, `refresh_token`, and `verify_token`.\nIt combines two subclasses, `TokenVerificationController` and `TokenObtainPairController`.\nIf you want to customize these routes, you can inherit from these controllers and modify their implementation:\n\n```python\nfrom ninja_extra import api_controller\nfrom ninja_jwt.controller import TokenObtainPairController\n\n@api_controller('token', tags=['Auth'])\nclass MyCustomController(TokenObtainPairController):\n \"\"\"obtain_token and refresh_token only\"\"\"\n ...\napi.register_controllers(MyCustomController)\n```\n\nTo use localizations/translations, add `ninja_jwt` to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n ...\n 'ninja_jwt',\n ...\n]\n```\n\n## Using Ninja Router\n\nIf you prefer not to follow the NinjaExtra methodology,\nrefer to this [documentation](https://eadwincode.github.io/django-ninja-jwt/customizing_token_claims/#use-django-ninja-router)\non how to use `Ninja-JWT` with `Django-Ninja Router`.\n\n## Usage\n\nTo verify that Ninja JWT is working, you can use curl to issue a couple\nof test requests:\n\n``` {.sourceCode .bash}\ncurl \\\n -X POST \\\n -H \"Content-Type: application/json\" \\\n -d '{\"username\": \"davidattenborough\", \"password\": \"boatymcboatface\"}' \\\n http://localhost:8000/api/token/pair\n\n...\n{\n \"access\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU\",\n \"refresh\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4\"\n}\n```\n\nYou can use the returned access token to prove authentication for a\nprotected view:\n\n``` {.sourceCode .bash}\ncurl \\\n -H \"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU\" \\\n http://localhost:8000/api/some-protected-view/\n```\n\nWhen this short-lived access token expires, you can use the longer-lived\nrefresh token to obtain another access token:\n\n``` {.sourceCode .bash}\ncurl \\\n -X POST \\\n -H \"Content-Type: application/json\" \\\n -d '{\"refresh\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4\"}' \\\n http://localhost:8000/api/token/refresh\n\n...\n{\"access\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w\"}\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Django Ninja JWT - JSON Web Token for Django-Ninja",
"version": "5.3.5",
"project_urls": {
"Documentation": "https://github.com/eadwinCode/django-ninja-jwt",
"Source": "https://github.com/eadwinCode/django-ninja-jwt"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "58bd95e3de2bf44b3f3bfb90810c0a44b1ad6635eebbebe07795f3cd1e889d1b",
"md5": "e421f3d57785a75301402a64949d2d61",
"sha256": "bf3a577e6a75c3afb8ca49eef38f24f087a39f86761bfc4120f02a3bfce7a902"
},
"downloads": -1,
"filename": "django_ninja_jwt-5.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e421f3d57785a75301402a64949d2d61",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 87711,
"upload_time": "2024-11-16T04:04:51",
"upload_time_iso_8601": "2024-11-16T04:04:51.004871Z",
"url": "https://files.pythonhosted.org/packages/58/bd/95e3de2bf44b3f3bfb90810c0a44b1ad6635eebbebe07795f3cd1e889d1b/django_ninja_jwt-5.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ea2d628cf2bd7b99fa16a84a89255e83e92a4b695b5b96820416eaa3eae92739",
"md5": "66d04944c1d31e1a46bea4f1258939fd",
"sha256": "3bc5f7dec64d690c194a8a32b25afe53f5c51514a4027c4c716701d466107f3d"
},
"downloads": -1,
"filename": "django_ninja_jwt-5.3.5.tar.gz",
"has_sig": false,
"md5_digest": "66d04944c1d31e1a46bea4f1258939fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 39190,
"upload_time": "2024-11-16T04:04:52",
"upload_time_iso_8601": "2024-11-16T04:04:52.812733Z",
"url": "https://files.pythonhosted.org/packages/ea/2d/628cf2bd7b99fa16a84a89255e83e92a4b695b5b96820416eaa3eae92739/django_ninja_jwt-5.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-16 04:04:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "eadwinCode",
"github_project": "django-ninja-jwt",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "django-ninja-jwt"
}