Authenticate your users using OpenID Connect (OIDC)
Project description
Makina Django OIDC
This library allow Single Sign On (SSO) integration into Django through the Open ID Connect (OIDC) protocol.
It can be used to setup a Single Sign On using an identity provider (Keycloak, etc.) or to login using Google, Twitter, etc.
Warning : this library has not been audited. However, we are based on pyoidc which we believe is a sane OIDC implementation.
Features
- Easy configuration through premade
Provider
classes. - Multiple provider support
- Easy integration with the Django permission system
- Highly customizable design that should suit most needs
- Back-channel Logout
- Sane and secure defaults settings
Roadmap
Bearer
authentication support fordjango-rest-framework
integration- Frontchannel logout
Acknowledgement
This library is built on the work of many others. First all, thanks to all the maintainers of pyoidc as they did all the spec implementation. This library is mostly about glue between Django and pyoidc.
We were also heavily inspired by :
mozilla-django-oidc
for it's login redirection URI managementdjango-auth-oidc
for it's hook system
If you want to understand why we decided to implement our own library, this is documented here.
Documentation
The documentation is graciously hosted at readthedocs.
Installation
First, install the python package :
pip install makina-django-doic
Then add the library app to your django applications, after django.contrib.sessions
and django.contrib.auth
:
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.sessions",
...
"django-pyoidc"
]
Don't forget to add the session middleware ! Add in your settings.py
:
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
]
Now is time to run a migrate operation, as we create a database table (read why here). Run in your project dir :
./manage.py migrate
We also need a cache (read why here), so let's configure a dumb one for development purposes. Add in your settings.py
:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "unique-snowflake",
}
}
Now you can pick an identity provider from the available providers. Providers class are a quick way to generate the library configuration and URLs for a givenv identity provider. You can also use [manual set] if you wish.
Create a file named oidc.py
next to your settings file and initialize your provider there :
from django_pyoidc.providers.keycloak import KeycloakProvider
my_oidc_provider = KeycloakProvider(
op_name="keycloak",
client_secret="s3cret",
client_id="my_client_id",
keycloak_base_uri="http://keycloak.local:8080/auth/", # we use the auth/ path prefix option on Keycloak
keycloak_realm="Demo",
logout_redirect="http://app.local:8082/",
failure_redirect="http://app.local:8082/",
success_redirect="http://app.local:8082/",
redirect_requires_https=False,
)
You can then add to your django configuration the following line :
from .oidc_providers import my_oidc_provider
DJANGO_PYOIDC = {
**my_oidc_provider.get_config(allowed_hosts=["app.local:8082"]),
}
Finally, add OIDC views to your url configuration (urls.py
):
from .oidc_providers import my_oidc_provider
urlpatterns = [
path("auth", include(my_oidc_provider.get_urlpatterns())),
]
And you are ready to go !
If you struggle with those instructions, take a look at the quickstart tutorial.
Usage/Examples
We wrote an extensive collection of 'how-to' guides in the documentation.
Appendix
Commercial support
This project is sponsored by Makina Corpus. If you require assistance on your project(s), please contact us: contact@makina-corpus.com
Report a security vulnerability
License
Authors
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
File details
Details for the file django_pyoidc-0.0.13.tar.gz
.
File metadata
- Download URL: django_pyoidc-0.0.13.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9c342210ace0ff4fdc74d0434c7bf98ae0ff1c53d5cd3e03bbd256e7546706e |
|
MD5 | 2a583b14444f93e0b908bd8963010d2a |
|
BLAKE2b-256 | d8af43cd9d03671909188e8c3d2bfe85af7b2d962009b6168f9bbf332ec85c6c |
File details
Details for the file django_pyoidc-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: django_pyoidc-0.0.13-py3-none-any.whl
- Upload date:
- Size: 35.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69be4561c68597a485b994aaeca1e8384baeac1ce0d7f154cd7f73e5534a244b |
|
MD5 | 5abde99385e3149857440aa466f9fb28 |
|
BLAKE2b-256 | 95cddb5f384cf38a156d36d87b8eda22494479f761cdc91901775d5828d50674 |