Skip to main content

G3W-ADMIN-AUTHJWT

PyPI version

A proof of concept authentication module through JSON Web Tokens for G3W-SUITE.

cookie-vs-token-auth

Installation

Install jwt module into g3w-admin applications folder:

# Install module from github (v1.0.0)
pip3 install git+https://github.com/g3w-suite/g3w-admin-authjwt.git@v1.0.0

# Install module from github (master branch)
# pip3 install git+https://github.com/g3w-suite/g3w-admin-authjwt.git@master

# Install module from local folder (git development)
# pip3 install /g3w-admin/g3w-admin/authjwt

# Install module from PyPi (not yet available)
# pip3 install g3w-admin-authjwt

Enable 'authjwt' module adding it to G3W_LOCAL_MORE_APPS list:

# local_settings.py

G3WADMIN_LOCAL_MORE_APPS = [
    ...
    'authjwt'
    ...
]

Refer to g3w-suite-docker repository for more info about running this on a docker instance.

NB On Ubuntu Jammy you could get an UNKNOWN package install instead of g3w-admin-authjwt, you can retry installing it as follows to fix it:

# Fix: https://github.com/pypa/setuptools/issues/3269#issuecomment-1254507377
export DEB_PYTHON_INSTALL_LAYOUT=deb_system

# And then install again the module
pip3 install ...

Configuration

The following packages are included in this module:

Refer to the official docs for a more comprehensive list of the available settings:

# Customize Django CORS Headers (v3.11.0)
# -------------------------------------------

CORS_ALLOW_ALL_ORIGINS = True # NB: DEVELOPMENT ONLY!

CORS_ALLOWED_ORIGINS = [      # NB: DIFFERENT PORT == DIFFERENT SERVER
     'http://localhost:8080',
     'http://localhost:8081',
     'http://127.0.0.1:8080',
     'http://127.0.0.1:8081',
]
# Customize Django REST Framework - Simple JWT (v5.2.2)
# -------------------------------------------

from datetime import timedelta

JWT_AUTH = {
    'JWT_ALLOW_REFRESH': True,
    'JWT_EXPIRATION_DELTA': timedelta(hours=1),        
    'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=7), # 
}

# NB: longer-lived tokens can reduce HTTP traffic
# but they also highlight "health check" issues after
# user logout (given the stateless nature of JWT requests,
# if not handled for example through a "token blacklist",
# the user could still appear as logged-in even after a logout)
# See also:
# - https://django-rest-framework-simplejwt.readthedocs.io/en/latest/blacklist_app.html
# - https://django-rest-framework-simplejwt.readthedocs.io/en/latest/stateless_user_authentication.html

For the default settings currently applied by this module, see also: authjwt/__init__.py

API URLs

Check the authjwt/apiurls.py file for a comprehensive list and how to use them.

Find out that they are loaded correctly in your project by running the following command in a terminal shell:

python3 manage.py show_urls
/authjwt/api/                   rest_framework.routers.APIRootView                      api-root
/authjwt/api/\.<format>/        rest_framework.routers.APIRootView                      api-root
/authjwt/api/ping/              authjwt.views.PingViewSet                               ping-list
/authjwt/api/ping\.<format>/    authjwt.views.PingViewSet                               ping-list
/authjwt/api/token/             rest_framework_simplejwt.views.TokenObtainPairView      token_obtain_pair
/authjwt/api/token/blacklist/   rest_framework_simplejwt.views.TokenBlacklistView       token_blacklist
/authjwt/api/token/refresh/     rest_framework_simplejwt.views.TokenRefreshView         token_refresh
/authjwt/api/token/verify/      rest_framework_simplejwt.views.TokenVerifyView          token_verify

Tip: if you are developing locally use a software like httpie (or postman) to import and save the following curl commands for later use:

Login user

curl --request POST \
  --url http://localhost:8000/authjwt/api/token/ \
  --header 'Content-Type: application/json' \
  --data '{ "username":"admin", "password":"admin" }'

Refresh token

curl --request POST \
  --url http://localhost:8000/authjwt/api/token/refresh/ \
  --header 'Content-Type: application/json' \
  --data '{ "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY3MTI2NTIyNiwiaWF0IjoxNjcxMTc4ODI2LCJqdGkiOiI3OGFiODU2MjcyZWM0YjAxOWI1Y2M4NTA1ZmNiMTIwOSIsInVzZXJfaWQiOjJ9.AAKmj8I3IN936PrOcxqGmsImWVkFk2AtsFJSE_o4dlY" }'

Verify token

curl --request POST \
  --url http://localhost:8000/authjwt/api/token/verify/ \
  --header 'Content-Type: application/json' \
  --data '{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY3MTI3NTg4NSwiaWF0IjoxNjcxMTg5NDg1LCJqdGkiOiIxMTk2NWNiNGFkYjE0ZmEzOTUxYzBhOTkxNDlhZWMwNyIsInVzZXJfaWQiOjJ9.YA4MesWfQcbYip6EhRxZoQAFxoZeBdlJdCrEme8sTc0" }'

Heartbeat (check access to a protected view)

curl --request GET \
  --url 'http://localhost:8000/authjwt/api/ping/?id=pong' \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjcxMTgyNDIxLCJpYXQiOjE2NzExODIxMjEsImp0aSI6IjI5YjQyN2ZlYjRkMjQ3YmM4NDAzODcyY2VhOTM2NWI5IiwidXNlcl9pZCI6Mn0.P6E7r9BCEFMzkTohJR4EMW1m8wm4DGZ03232mJO6vQI'

Logout user (optional)

curl --request POST \
  --url http://localhost:8000/authjwt/api/token/blacklist/ \
  --header 'Content-Type: application/json' \
  --data '{ "refresh":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY3MTI3NTg4NSwiaWF0IjoxNjcxMTg5NDg1LCJqdGkiOiIxMTk2NWNiNGFkYjE0ZmEzOTUxYzBhOTkxNDlhZWMwNyIsInVzZXJfaWQiOjJ9.YA4MesWfQcbYip6EhRxZoQAFxoZeBdlJdCrEme8sTc0" }'

Development and tests

The integration BDD scenarios are in authjwt/tests/features. They run in the G3W-ADMIN/QGIS environment used by CI. Install the test dependencies with:

python3 -m pip install -r requirements_test.txt

From the configured G3W-ADMIN directory, run:

python3 manage.py behave --simple authjwt/tests
Traditional workflow

Steps to follow in case of a regular install.

Clone and place the g3w-admin-authjwt repository into g3w-admin applications folder:

cd /path/to/your/development/workspace

git clone https://github.com/g3w-suite/g3w-admin.git ./g3w-admin
git clone https://github.com/g3w-suite/g3w-admin-authjwt.git ./g3w-admin/g3w-admin/authjwt

So your folder structure should matches the following:

.
└── g3w-admin/
    ├── g3w-admin/
    │   ├── authjwt/
    │   │   ├── authjwt/
    │   │   │   ├── __init__.py
    │   │   │   ├── apps.py
    │   │   │   ├── urls.py
    │   │   │   ├── views.py
    │   │   │   └── ...
    │   │   ├── pyproject.toml
    │   │   └── README.md
    │   ├── base/
    │   ├── core/
    │   ├── ...
    │   └── manage.py
    └── README.md

Install the g3w-admin-authjwt module from the local source folder:

pip3 install /g3w-admin/g3w-admin/authjwt

Then activate the 'authjwt' module as usual by adding it to G3W_LOCAL_MORE_APPS list.

Alternative workflow

Steps to follow in case of a editable install.

Clone g3w-admin and g3w-admin-authjwt repositories into two adjacent folders:

cd /path/to/your/development/workspace

git clone https://github.com/g3w-suite/g3w-admin.git
git clone https://github.com/g3w-suite/g3w-admin-authjwt.git

So your folder structure should matches the following:

.
├── g3w-admin/
│   ├── g3w-admin/
│   │   ├── base/
│   │   ├── core/
│   │   ├── ...
│   │   └── manage.py
│   └── README.md
│
└── g3w-admin-authjwt/
    ├── authjwt/
    │   ├── __init__.py
    │   ├── apps.py
    │   ├── urls.py
    │   ├── views.py
    │   └── ...
    ├── pyproject.toml
    └── README.md

Install the g3w-admin-authjwt module in editable mode starting from your g3w-admin folder:

cd g3w-admin

python3 -m pip install -e ../g3w-admin-authjwt

Then activate the 'authjwt' module as usual by adding it to G3W_LOCAL_MORE_APPS list.

TODO

Find out if it could be feasible to code a sort of proxy class for the rest_framework.permissions.IsAuthenticated (or for the rest_framework.viewsets) in order to make use of JWT Authentication with legacy API endpoints that make use of the django.contrib.auth.decorators.login_required method to check if a user is authenticated, ie:

# apiurls.py

from django.contrib.auth.decorators import login_required

...

urlpatterns = [

  path(
    'api/some-protected-view/',
    login_required(SomeProtectedView.as_view()), # currently "SomeProtectedView" doesn't support JWT Auth
    name='some-protected-view'
  )

]

Code samples on how to implement JWT with Vue and Django Rest Framework:

Sample project on how to develop a complete docker stack (backend + frontend):

Sample project on how to implement a "simplejwt" extension without using the Django Rest Framework:

Packaging a Python project:


Compatibile with: g3w-admin version g3w-suite-docker version


License: MPL-2

Metadata

Release files for g3w-admin-authjwt 0.0.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 g3w-admin-authjwt 0.0.3
File Size Uploaded Provenance Actions
g3w_admin_authjwt-0.0.3.tar.gz 19.0 kB With provenance Details for g3w_admin_authjwt-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for g3w-admin-authjwt 0.0.3
File Interpreter ABI Platform Actions
g3w_admin_authjwt-0.0.3-py3-none-any.whl Python 3 none any Details for g3w_admin_authjwt-0.0.3-py3-none-any.whl

Total release size: 34.3 kB

Release files / g3w_admin_authjwt-0.0.3.tar.gz

Download URL g3w_admin_authjwt-0.0.3.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4299da8faf51358d472db18df9a955125aab983768a6bb4e87c421f3370b724a
BLAKE2b-256 checksum
How to use checksums
a6c450e0103793a3f32d7dd9bf6309217491539225b323d8949166e1d52d0023
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / g3w_admin_authjwt-0.0.3-py3-none-any.whl

Download URL g3w_admin_authjwt-0.0.3-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c664d1f4d9d57c8fd629007867e148d68e1927b58416ccedea3dc772e592677
BLAKE2b-256 checksum
How to use checksums
714621cee194c3a525cd7e27d46a2fb31c6387f3c0547341cb00d9344e2a291f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for g3w-admin-authjwt 0.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for g3w_admin_authjwt-0.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files Full provenance

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