Skip to main content

No project description provided

Project description

Garpix Keycloak

Keycloak uth module for Django/DRF projects. Part of GarpixCMS.

Used packages:

Quickstart

Install with pip:

pip install garpix_keycloak

Add the garpix_keycloak to your INSTALLED_APPS:

# settings.py

# ...
INSTALLED_APPS = [
    # ...
    'garpix_keycloak',
]

Add KeycloakUserMixin to your User model:

from django.contrib.auth.models import AbstractUser

from garpix_keycloak.mixins import KeycloakUserMixin


class User(AbstractUser, KeycloakUserMixin):

    class Meta:
        verbose_name = 'Пользователь'
        verbose_name_plural = 'Пользователи'

    def __str__(self):
        return self.username

Add KeycloakAuthMiddleware to MIDDLEWARE settings after django.contrib.auth.middleware.AuthenticationMiddleware:

# settings.py


MIDDLEWARE = [
    # ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'garpix_keycloak.middlewares.KeycloakAuthMiddleware',
]

Now when your request has Bearer token, it would be firstly checked as base django user token, then as keycloak token.

Enjoy!

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

MIT


Developed by Garpix / https://garpix.com

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

garpix_keycloak-1.0.0.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

garpix_keycloak-1.0.0-py3-none-any.whl (11.0 kB view hashes)

Uploaded Python 3

Supported by

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