Skip to main content

django-jwt-oidc

Django library that implements the authentification for OpenId SSO with JWT from oauth2. This authentification is compatible with django session workflow and the RestFramework library.

Installation

Install the library with pip

pip install django-jwt-oidc

Add the django_jwt package into your INSTALLED_APPS in your settings.py file

INSTALLED_APPS = [
    ...
    'django_jwt',
    ...
]

Django [WIP]

This is what you need to do in order that your Django application will authenticate with JWT.

RestFramework

This settings are for views inherits RestFramework library from Django. You will need to install RestFramework on your own to your app first

View setting

You can add this to your APIviews class by adding JWTTokenAuthentication to authentification_classes attribute. In this example, the view requires that all requests must have JWT Bearer Authentication.

from rest_framework import permissions, views
from django_jwt import JWTTokenAuthentication


class ExampleAPIView(view.APIView):
    authentication_classes = [JWTTokenAuthentication]
    permission_classes = [permissions.IsAuthenticated]

Global setting

If all your application can work with JWT Bearer Authentication you can add the JWTTokenAuthentication class to DEFAULT_AUTHENTICATION_CLASSES setting on settings.py of your app.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'django_jwt.rest_framework.JWTTokenAuthentication',
    ]
}

Settings

JWT_OPENID2_URL

The openid service url without the /.well-known/openid-configuration path.

JWT_OPENID2_URL = 'https://localhost:8000'

Developing only: If this setting is set to 'fake', it will deploy a fake openid service, you will need to inlcude the 'django_jwt.urls' on your urls.py and also set DEFAULT_DOMAIN to your app domain.

JWT_RENAME_ATTRIBUTES

Dictionary to redirect the data and the sub attribute into the User attributes.

JWT_RENAME_ATTRIBUTES = {'sub': 'username'}

JWT_CREATE_USER

Boolean that creates a Django user by default if the user doesn't exists if set to True.

JWT_CREATE_USER = True

You can also change the creation method of the QuerysetManager of the User model in order to customize this.

class UserQueryset(QuerySet):
    def get_or_create(self, defaults=None, **kwargs):
        ...

class User(AbstractBaseUser):
    objects = UserQueryset.as_manager()
    ...
    

JWT_DEFAULT_ATTRIBUTES

Dictionary that sets default values to new Users created. This example sets the all the attibutes of users created by the library auto_created to True.

JWT_DEFAULT_ATTRIBUTES = {'auto_created': True}

You can also modify attributes like adding something to the value creating a change_[attribute_name] method on the User model.

class User(AbstractBaseUser):
    def change_username(self, value):
        return value + '@jwt'

Release files for django-jwt-oidc 0.1.2

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

Built distribution (wheel)

Table of built distributions (wheels) for django-jwt-oidc 0.1.2
File Interpreter ABI Platform
django_jwt_oidc-0.1.2-py3-none-any.whl Python 3 none any Details

Release files / django_jwt_oidc-0.1.2-py3-none-any.whl

Download URL django_jwt_oidc-0.1.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdd5b95ff090e45de0020fc08656815369e9afd631d27c267ae9c502cf2e4734
BLAKE2b-256 checksum
How to use checksums
be551b6572d73f33c8a1d55a62ba855349633ae9fdcc62a7f0362ad8d8bf2fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

Release history Release notifications | RSS feed

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1

1 release file

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