Name | django-ninja-jwt-basic JSON |
Version |
0.1.2
JSON |
| download |
home_page | https://github.com/SpaceShaman/django-ninja-jwt-basic |
Summary | Simple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects. |
upload_time | 2024-07-11 12:11:42 |
maintainer | None |
docs_url | None |
author | SpaceShaman |
requires_python | <4.0.0,>=3.10.0 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# django-ninja-jwt-basic
[](https://github.com/SpaceShaman/django-ninja-jwt-basic?tab=MIT-1-ov-file)
[](https://github.com/SpaceShaman/django-ninja-jwt-basic/blob/master/.github/workflows/tests.yml)
[](https://codecov.io/gh/SpaceShaman/django-ninja-jwt-basic)
[](https://pypi.org/project/django-ninja-jwt-basic)
[](https://pypi.org/project/django-ninja-jwt-basic)
[](https://pypi.org/project/django-ninja-jwt-basic)
[](https://github.com/psf/black)
[](https://github.com/astral-sh/ruff)
Simple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects.
## Installation
```bash
pip install django-ninja-jwt-basic
```
## Configuration
Add the following settings to your Django settings:
```python
JWT_SECRET_KEY = 'your_secret key' # Required
```
Add the app to your `INSTALLED_APPS` in your Django settings:
```python
INSTALLED_APPS = [
...
'django_ninja_jwt_basic',
...
]
```
## Usage
Next, add router to your Django Ninja API and protect your endpoints
```python
from ninja import NinjaAPI
from django_ninja_jwt_basic import JWTAuth
api = NinjaAPI(auth=JWTAuth())
api.add_router('/auth', 'django_ninja_jwt_basic.router')
```
This will add the following endpoint to your API:
- `/auth/login` - POST - Login endpoint
- Request body:
```json
{
"username": "your_username",
"password": "your_password"
}
```
- Response body:
```json
{
"token": "your_access_token"
}
```
If you don't want protect all endpoints, you can use `JWTAuth` class directly in your endpoints or routers like below:
```python
from ninja import Router
from django_ninja_jwt_basic import JWTAuth
router = Router(auth=JWTAuth())
@router.get('/protected')
def protected(request):
return {'message': 'This is a protected endpoint'}
```
``` python
from django_ninja_jwt_basic import JWTAuth
@api.get('/protected', auth=JWTAuth())
def protected(request):
return {'message': 'This is a protected endpoint'}
```
You can find more information about protecting endpoints in the [Django Ninja documentation](https://django-ninja.dev/guides/authentication/)
Raw data
{
"_id": null,
"home_page": "https://github.com/SpaceShaman/django-ninja-jwt-basic",
"name": "django-ninja-jwt-basic",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.10.0",
"maintainer_email": null,
"keywords": null,
"author": "SpaceShaman",
"author_email": "spaceshaman@tuta.io",
"download_url": "https://files.pythonhosted.org/packages/70/f2/f0683bc60f6079766a39b3dd1c36d6581a5ab4d9d08ab54999fccbae01d7/django_ninja_jwt_basic-0.1.2.tar.gz",
"platform": null,
"description": "# django-ninja-jwt-basic\n\n[](https://github.com/SpaceShaman/django-ninja-jwt-basic?tab=MIT-1-ov-file)\n[](https://github.com/SpaceShaman/django-ninja-jwt-basic/blob/master/.github/workflows/tests.yml)\n[](https://codecov.io/gh/SpaceShaman/django-ninja-jwt-basic)\n[](https://pypi.org/project/django-ninja-jwt-basic)\n[](https://pypi.org/project/django-ninja-jwt-basic)\n[](https://pypi.org/project/django-ninja-jwt-basic)\n[](https://github.com/psf/black)\n[](https://github.com/astral-sh/ruff)\n\nSimple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects.\n\n## Installation\n\n```bash\npip install django-ninja-jwt-basic\n```\n\n## Configuration\n\nAdd the following settings to your Django settings:\n\n```python\nJWT_SECRET_KEY = 'your_secret key' # Required\n```\n\nAdd the app to your `INSTALLED_APPS` in your Django settings:\n\n```python\nINSTALLED_APPS = [\n ...\n 'django_ninja_jwt_basic',\n ...\n]\n```\n\n## Usage\n\nNext, add router to your Django Ninja API and protect your endpoints\n\n```python\nfrom ninja import NinjaAPI\nfrom django_ninja_jwt_basic import JWTAuth\n\napi = NinjaAPI(auth=JWTAuth())\napi.add_router('/auth', 'django_ninja_jwt_basic.router')\n```\n\nThis will add the following endpoint to your API:\n\n- `/auth/login` - POST - Login endpoint\n\n - Request body:\n\n ```json\n {\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n }\n ```\n \n - Response body:\n\n ```json\n {\n \"token\": \"your_access_token\"\n }\n ```\n\nIf you don't want protect all endpoints, you can use `JWTAuth` class directly in your endpoints or routers like below:\n\n```python\nfrom ninja import Router\nfrom django_ninja_jwt_basic import JWTAuth\n\nrouter = Router(auth=JWTAuth())\n\n@router.get('/protected')\ndef protected(request):\n return {'message': 'This is a protected endpoint'}\n```\n\n``` python\nfrom django_ninja_jwt_basic import JWTAuth\n\n@api.get('/protected', auth=JWTAuth())\ndef protected(request):\n return {'message': 'This is a protected endpoint'}\n```\n\nYou can find more information about protecting endpoints in the [Django Ninja documentation](https://django-ninja.dev/guides/authentication/)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/SpaceShaman/django-ninja-jwt-basic",
"Repository": "https://github.com/SpaceShaman/django-ninja-jwt-basic"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8077252cb29ccdafbd026020734991b896b82c833361225522f676f5ebdaf7c6",
"md5": "e76a2ac05aefe25149fd880f5a271cf6",
"sha256": "eca2680eae29794d41ea427885ee9c4c1ce0350f3116b5f8100ec26499b1f855"
},
"downloads": -1,
"filename": "django_ninja_jwt_basic-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e76a2ac05aefe25149fd880f5a271cf6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.10.0",
"size": 4726,
"upload_time": "2024-07-11T12:11:41",
"upload_time_iso_8601": "2024-07-11T12:11:41.109066Z",
"url": "https://files.pythonhosted.org/packages/80/77/252cb29ccdafbd026020734991b896b82c833361225522f676f5ebdaf7c6/django_ninja_jwt_basic-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "70f2f0683bc60f6079766a39b3dd1c36d6581a5ab4d9d08ab54999fccbae01d7",
"md5": "6a926d409d3a0bda0d385a17bd8d2d8e",
"sha256": "f811755ac43e9b61750bb148e71d789193f3717685670c7f3fcbffe08c05afa6"
},
"downloads": -1,
"filename": "django_ninja_jwt_basic-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "6a926d409d3a0bda0d385a17bd8d2d8e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.10.0",
"size": 3471,
"upload_time": "2024-07-11T12:11:42",
"upload_time_iso_8601": "2024-07-11T12:11:42.718499Z",
"url": "https://files.pythonhosted.org/packages/70/f2/f0683bc60f6079766a39b3dd1c36d6581a5ab4d9d08ab54999fccbae01d7/django_ninja_jwt_basic-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-11 12:11:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SpaceShaman",
"github_project": "django-ninja-jwt-basic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-ninja-jwt-basic"
}