Skip to main content

DRF SimpleJWT additions

Additional features for django-rest-framework-simplejwt.


Features

  • Full user info in TokenObtainPairSerializer
  • Full user info in TokenObtainPairView
  • Auto creation of user from token

Installation

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:

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:

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. But it doesn't create user automatically.


Full user info in TokenObtainPairView

In urls.py:

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

Metadata

Release files for drf-simplejwt-additions 1.1.3

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

Source distribution (sdist)

Source distribution for drf-simplejwt-additions 1.1.3
File Size Uploaded Provenance Actions
drf-simplejwt-additions-1.1.3.tar.gz 3.6 kB Without provenance Details for drf-simplejwt-additions-1.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-simplejwt-additions 1.1.3
File Interpreter ABI Platform Actions
drf_simplejwt_additions-1.1.3-py3-none-any.whl Python 3 none any Details for drf_simplejwt_additions-1.1.3-py3-none-any.whl

Total release size: 7.9 kB

Release files / drf-simplejwt-additions-1.1.3.tar.gz

Download URL drf-simplejwt-additions-1.1.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
70e09c325639af3d47fb201a210e7e60b2de15dfd1768abbd23d7e73139c3af5
BLAKE2b-256 checksum
How to use checksums
6f47b0d4597e341ac048add9ad13ef614fc7421da069156201945d55fd9071bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / drf_simplejwt_additions-1.1.3-py3-none-any.whl

Download URL drf_simplejwt_additions-1.1.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
591d06a2007ed704ce9e50c32dc7ff9d54641d8bf9ae131d6144ef7f0f9d1a13
BLAKE2b-256 checksum
How to use checksums
6b877080bad80c0e0b732459225f3cd68f012bdd80e1b21b8ffd98771500ef7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for drf-simplejwt-additions 1.1.3

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