Skip to main content

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

  1. Add django-drf-keycloak-auth to requirements.txt

    django-drf-keycloak-auth==0.1.0
    

    You need to create your own nonce and state on the client side and then pass that nonce and state along with the redirect_uri to the server side. code and state are returned after successful authentication. You need to use the code to obtain token information.

  2. Set environment variables

    Refer to the .env.template in 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-auth from 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.1

OR

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_drf_keycloak_auth-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_drf_keycloak_auth-0.1.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

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

Hashes for django_drf_keycloak_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed5cfa42edfbca7e3a8c7e4952a4dca2581542e21f65d51273e98d904597d37e
MD5 7b047ca6786f1402c7053facc1bf19b3
BLAKE2b-256 73e8af85ebf304c4d10e914c2687cb46ed715241cdf873b45ff4e56369da1d33

See more details on using hashes here.

File details

Details for the file django_drf_keycloak_auth-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_drf_keycloak_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4017c179c525d83bc1f28844b921433058cb40ceb065a220cc741a47f2d8174d
MD5 70027d8e8b400af71d55c4590c4bd678
BLAKE2b-256 43a099ec50a416c6090143fbc6cd27269fd6d3c6db1212bbe4abb222f6cf87be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page