Django app for Keycloak OAuth2 authentication with DRF.
Project description
django-drf-keycloak-auth
When using Django, DRF, and Keycloak for authentication and permission management, django-drf-keycloak-auth can make your work easier.
Getting Started
pip install django-drf-keycloak-auth
OR
uv add django-drf-keycloak-auth
Usage
-
Add
django-drf-keycloak-authtorequirements.txtdjango-drf-keycloak-auth==0.1.0
You need to create your own
nonceandstateon the client side and then pass thatnonceandstatealong with theredirect_urito the server side.codeandstateare returned after successful authentication. You need to use thecodeto obtain token information. -
Set environment variables
Refer to the
.env.templatein django-drf-keycloak-auth-example-back-end.
Examples
There is a full example in the django-drf-keycloak-auth-example-front-end and django-drf-keycloak-auth-example-back-end that can be run directly.
You can start from the example to learn how to use django-drf-keycloak-auth.
Deploy project(memo for developer)
setuptools version
The latest setuptools(version 80.9.0) produces .whl files with a METADATA version of 2.4. You can check this by running:
unzip -p dist/*.whl '*/METADATA' | sed -n '1,160p'
Note that TestPyPI and TestPyPI only supports METADATA versions 1.0–2.2. Therefore, if you plan to publish your package to TestPyPI or TestPyPI, you should not use the latest setuptools.
Deploy to TestPyPI
Depending on the network environment, you may need to use a proxy.
# https://test.pypi.org/
expect interactive_deploy_test.expect
Install
django-drf-keycloak-authfrom TestPyPI.uv pip uninstall django-drf-keycloak-auth uv pip install --no-cache-dir \ --index-url https://pypi.org/simple \ --extra-index-url https://test.pypi.org/simple \ --index-strategy unsafe-best-match \ django-drf-keycloak-auth==0.0.1OR
uv pip install --index-url https://test.pypi.org/simple django-drf-keycloak-auth==0.0.1
Deploy to PyPI
Depending on the network environment, you may need to use a proxy.
# https://pypi.org/
expect interactive_deploy.expect
How to mark a version as yanked
twine yank <package_name> --version <version> --reason "Reason this release was yanked: Yanked due to <reason>"
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[0.0.1] - 2025-10-15
- First commit(Only for test)
[0.0.2] - 2025-10-17
-
Add drf-spectacular support
-
Update auth api
[0.1.0] - 2025-10-20
- Update client state support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_drf_keycloak_auth-0.1.0.tar.gz.
File metadata
- Download URL: django_drf_keycloak_auth-0.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed5cfa42edfbca7e3a8c7e4952a4dca2581542e21f65d51273e98d904597d37e
|
|
| MD5 |
7b047ca6786f1402c7053facc1bf19b3
|
|
| BLAKE2b-256 |
73e8af85ebf304c4d10e914c2687cb46ed715241cdf873b45ff4e56369da1d33
|
File details
Details for the file django_drf_keycloak_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_drf_keycloak_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4017c179c525d83bc1f28844b921433058cb40ceb065a220cc741a47f2d8174d
|
|
| MD5 |
70027d8e8b400af71d55c4590c4bd678
|
|
| BLAKE2b-256 |
43a099ec50a416c6090143fbc6cd27269fd6d3c6db1212bbe4abb222f6cf87be
|