drf-simplejwt-additions


Namedrf-simplejwt-additions JSON
Version 1.1.3 PyPI version JSON
download
home_pagehttps://github.com/AllYouZombies/drf-simplejwt-additions
SummaryAdditions for Django Rest Framework Simple JWT
upload_time2023-06-15 10:52:36
maintainer
docs_urlNone
authorAstafeev Rustam
requires_python>=3.7
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DRF SimpleJWT additions

Additional features for [django-rest-framework-simplejwt](https://django-rest-framework-simplejwt.readthedocs.io/en/latest/index.html).
  
---
  
## Features
  
- [x] Full user info in TokenObtainPairSerializer
- [x] Full user info in TokenObtainPairView
- [x] Auto creation of user from token
  
---
  
## Installation
  
```bash
pip install drf-simplejwt-additions
```
  
---
  
## Usage

> Note: for all these features you need to set same `SECRET_KEY` and `SIMPLE_JWT['ALGORITHM']` in all services.
  
### Full user info in TokenObtainPairSerializer
  
In `settings.py`:
  
```python
INSTALLED_APPS = [
    ...
    'drf_simplejwt_additions',
    ...
]
  
...
  
SIMPLE_JWT = {
    ...
    "TOKEN_OBTAIN_SERIALIZER": "drf_simplejwt_additions.serializers.TokenObtainPairWithFullUserSerializer",
    ...
}
```
  
From now on, the response of the `TokenObtainPairView` will contain the full user info.  
Serializer get all fields from the user model.  
Then theses fields are added to the response in the `user` field.  

> User's password is also added to the response. But it's encrypted twice:
> - First time by Django itself
> - Second: JWT encryption
  
### Auto creation of user from token
  
This feature is useful in microservices architecture.
Token, obtained from one service, can be used in another service to get user info.
So, if the user doesn't exist in the second service, it will be created automatically.
  
In `settings.py`:
  
```python
INSTALLED_APPS = [
    ...
    'drf_simplejwt_additions',
    ...
]

...

MIDDLEWARE = [
    ...
    'drf_simplejwt_additions.middleware.AutoCreateUserFromTokenMiddleware',
    ...
]

...

REST_FRAMEWORK = {
    ...
    'DEFAULT_AUTHENTICATION_CLASSES': (
        ...
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        ...
    ),
    ...
}
```
  
> django-rest-framework-simplejwt has great feature: [TokenUserAuthentication](https://django-rest-framework-simplejwt.readthedocs.io/en/latest/customizing_token_claims.html#tokenuserauthentication).
> But it doesn't create user automatically.
  
---
  
### Full user info in TokenObtainPairView
  
In `urls.py`:
  
```python
from drf_simplejwt_additions.views import TokenObtainPairWithFullUserView

urlpatterns = [
    ...
    path('api/token/', TokenObtainPairWithFullUserView.as_view(), name='token_obtain_pair'),
    ...
]
```
  
The `TokenObtainPairWithFullUserView` is a subclass of `TokenObtainPairView` with the `TokenObtainPairWithFullUserSerializer` serializer.
  
---
  
## License
  
[MIT](https://choosealicense.com/licenses/mit/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AllYouZombies/drf-simplejwt-additions",
    "name": "drf-simplejwt-additions",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Astafeev Rustam",
    "author_email": "rustam@astafeev.dev",
    "download_url": "https://files.pythonhosted.org/packages/6f/47/b0d4597e341ac048add9ad13ef614fc7421da069156201945d55fd9071bc/drf-simplejwt-additions-1.1.3.tar.gz",
    "platform": null,
    "description": "# DRF SimpleJWT additions\n\nAdditional features for [django-rest-framework-simplejwt](https://django-rest-framework-simplejwt.readthedocs.io/en/latest/index.html).\n  \n---\n  \n## Features\n  \n- [x] Full user info in TokenObtainPairSerializer\n- [x] Full user info in TokenObtainPairView\n- [x] Auto creation of user from token\n  \n---\n  \n## Installation\n  \n```bash\npip install drf-simplejwt-additions\n```\n  \n---\n  \n## Usage\n\n> Note: for all these features you need to set same `SECRET_KEY` and `SIMPLE_JWT['ALGORITHM']` in all services.\n  \n### Full user info in TokenObtainPairSerializer\n  \nIn `settings.py`:\n  \n```python\nINSTALLED_APPS = [\n    ...\n    'drf_simplejwt_additions',\n    ...\n]\n  \n...\n  \nSIMPLE_JWT = {\n    ...\n    \"TOKEN_OBTAIN_SERIALIZER\": \"drf_simplejwt_additions.serializers.TokenObtainPairWithFullUserSerializer\",\n    ...\n}\n```\n  \nFrom now on, the response of the `TokenObtainPairView` will contain the full user info.  \nSerializer get all fields from the user model.  \nThen theses fields are added to the response in the `user` field.  \n\n> User's password is also added to the response. But it's encrypted twice:\n> - First time by Django itself\n> - Second: JWT encryption\n  \n### Auto creation of user from token\n  \nThis feature is useful in microservices architecture.\nToken, obtained from one service, can be used in another service to get user info.\nSo, if the user doesn't exist in the second service, it will be created automatically.\n  \nIn `settings.py`:\n  \n```python\nINSTALLED_APPS = [\n    ...\n    'drf_simplejwt_additions',\n    ...\n]\n\n...\n\nMIDDLEWARE = [\n    ...\n    'drf_simplejwt_additions.middleware.AutoCreateUserFromTokenMiddleware',\n    ...\n]\n\n...\n\nREST_FRAMEWORK = {\n    ...\n    'DEFAULT_AUTHENTICATION_CLASSES': (\n        ...\n        'rest_framework_simplejwt.authentication.JWTAuthentication',\n        ...\n    ),\n    ...\n}\n```\n  \n> django-rest-framework-simplejwt has great feature: [TokenUserAuthentication](https://django-rest-framework-simplejwt.readthedocs.io/en/latest/customizing_token_claims.html#tokenuserauthentication).\n> But it doesn't create user automatically.\n  \n---\n  \n### Full user info in TokenObtainPairView\n  \nIn `urls.py`:\n  \n```python\nfrom drf_simplejwt_additions.views import TokenObtainPairWithFullUserView\n\nurlpatterns = [\n    ...\n    path('api/token/', TokenObtainPairWithFullUserView.as_view(), name='token_obtain_pair'),\n    ...\n]\n```\n  \nThe `TokenObtainPairWithFullUserView` is a subclass of `TokenObtainPairView` with the `TokenObtainPairWithFullUserSerializer` serializer.\n  \n---\n  \n## License\n  \n[MIT](https://choosealicense.com/licenses/mit/)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Additions for Django Rest Framework Simple JWT",
    "version": "1.1.3",
    "project_urls": {
        "Homepage": "https://github.com/AllYouZombies/drf-simplejwt-additions"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b877080bad80c0e0b732459225f3cd68f012bdd80e1b21b8ffd98771500ef7f",
                "md5": "f1253e350564ec95d58e15f3c628c70e",
                "sha256": "591d06a2007ed704ce9e50c32dc7ff9d54641d8bf9ae131d6144ef7f0f9d1a13"
            },
            "downloads": -1,
            "filename": "drf_simplejwt_additions-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f1253e350564ec95d58e15f3c628c70e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4281,
            "upload_time": "2023-06-15T10:52:34",
            "upload_time_iso_8601": "2023-06-15T10:52:34.950209Z",
            "url": "https://files.pythonhosted.org/packages/6b/87/7080bad80c0e0b732459225f3cd68f012bdd80e1b21b8ffd98771500ef7f/drf_simplejwt_additions-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f47b0d4597e341ac048add9ad13ef614fc7421da069156201945d55fd9071bc",
                "md5": "6232a933d7d21053734d57a4f513b10a",
                "sha256": "70e09c325639af3d47fb201a210e7e60b2de15dfd1768abbd23d7e73139c3af5"
            },
            "downloads": -1,
            "filename": "drf-simplejwt-additions-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "6232a933d7d21053734d57a4f513b10a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3597,
            "upload_time": "2023-06-15T10:52:36",
            "upload_time_iso_8601": "2023-06-15T10:52:36.879094Z",
            "url": "https://files.pythonhosted.org/packages/6f/47/b0d4597e341ac048add9ad13ef614fc7421da069156201945d55fd9071bc/drf-simplejwt-additions-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-15 10:52:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AllYouZombies",
    "github_project": "drf-simplejwt-additions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "drf-simplejwt-additions"
}
        
Elapsed time: 0.08022s