scenario/example_project scenario/local_user_setup scenario/remote_user_setup scenario/initial_setup scenario/migrating scenario/permissions_by_roles scenario/permissions_by_resources_and_scopes scenario/multi_tenancy
Django Keycloak adds Keycloak support to your Django project. It's build on top of Django's authentication system. It works side-by-side with the standard Django authentication implementation and has tools to migrate your current users and permissions to Keycloak.
- Multi tenancy support
- Permissions by roles or by resource/scope
- Choose if you want to create a local User model for every logged in identity or not.
Read example_project
to quickly test this project.
Note
The documentation and the example project are all based on Keycloak version 3.4 since that is the latest version which is commercially supported by Red Hat (SSO).
Install requirement.
$ pip install git+https://github.com/Peter-Slump/django-keycloak.git
Some settings are always required and some other settings are dependant on how you want to integrate Keycloak in your project.
Add django-keycloak to your installed apps, add the authentication back-end, add the middleware, configure the urls and point to the correct login page.
# your-project/settings.py
INSTALLED_APPS = [
....
'django_keycloak.apps.KeycloakAppConfig'
]
MIDDLEWARE = [
...
'django_keycloak.middleware.BaseKeycloakMiddleware',
]
AUTHENTICATION_BACKENDS = [
...
'django_keycloak.auth.backends.KeycloakAuthorizationCodeBackend',
]
LOGIN_URL = 'keycloak_login'
# your-project/urls.py
...
urlpatterns = [
...
url(r'^keycloak/', include('django_keycloak.urls')),
]
Before you actually start using Django Keycloak make an educated choice between local_user_setup
and remote_user_setup
.
Then walk through the initial_setup
to found out how to link your Keycloak instance to your Django project.
If you don't want to take all that effort please read about example_project
For requiring a logged in user you can just use the standard Django functionality. This also counts for enforcing permissions.
This app makes use of the Python Keycloak client