Skip to content

Commit 658cafc

Browse files
committed
Merge branch 'main' into callback-routes
2 parents d240bf9 + 1fa51a4 commit 658cafc

File tree

8 files changed

+630
-425
lines changed

8 files changed

+630
-425
lines changed

README.md

+38-34
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@ It can be used to setup a Single Sign On using an identity provider (Keycloak, e
1313

1414
**Warning** : this library has not been audited. However, we are based on [pyoidc](https://github.com/CZ-NIC/pyoidc/) which we believe is a sane OIDC implementation.
1515

16+
We tried to make OpenID Connect (OIDC) configuration as easy and secure as possible. However
17+
everything can be customized, and we tried to take into account every use case in the library design.
18+
If you are not satisfied with the default configuration, take a look at the cookbook or the setting reference.
19+
1620
## Features
1721

1822
- Easy configuration through premade [`Provider`](https://django-pyoidc.readthedocs.io/en/latest/user.html#providers) classes.
19-
- Multiple provider support
23+
- Authenticate users from multiple providers
24+
- Bearer authentication support for [django-rest-framework](https://www.django-rest-framework.org/) integration (**single provider**)
2025
- Easy integration with the [Django permission system](https://django-pyoidc.readthedocs.io/en/latest/how-to.html#use-the-django-permission-system-with-oidc)
2126
- Highly customizable design that should suit most needs
22-
- Back-channel Logout
27+
- Support back-channel logout
28+
- Support service accounts (accounts for machine-to-machine uses)
2329
- Sane and secure defaults settings
2430

2531
## Roadmap
2632

27-
- `Bearer` authentication support for `django-rest-framework` integration
2833
- Frontchannel logout
34+
- Switch to django signal system login/logout hooks
35+
- Allow for audience check without customizing `get_user` using a setting
2936

3037
## Acknowledgement
3138

@@ -47,7 +54,7 @@ The documentation is graciously hosted at [readthedocs](https://django-pyoidc.re
4754
First, install the python package :
4855

4956
```bash
50-
pip install makina-django-doic
57+
pip install django_pyoidc
5158
```
5259

5360
Then add the library app to your django applications, after `django.contrib.sessions` and `django.contrib.auth` :
@@ -86,52 +93,49 @@ CACHES = {
8693
}
8794
```
8895

89-
Now you can pick an identity provider from the [available providers](https://django-pyoidc.readthedocs.io/en/latest/user.html#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.
90-
91-
Create a file named `oidc.py` next to your settings file and initialize your provider there :
92-
93-
FIXME: Here config as settings only OR using custom provider
94-
95-
```python
96-
from django_pyoidc.providers.keycloak import KeycloakProvider
97-
98-
my_oidc_provider = KeycloakProvider(
99-
op_name="keycloak",
100-
keycloak_base_uri="http://keycloak.local:8080/auth/", # we use the auth/ path prefix option on Keycloak
101-
keycloak_realm="Demo",
102-
client_secret="s3cret",
103-
client_id="my_client_id",
104-
logout_redirect="http://app.local:8082/",
105-
failure_redirect="http://app.local:8082/",
106-
success_redirect="http://app.local:8082/",
107-
redirect_requires_https=False,
108-
login_uris_redirect_allowed_hosts=["app.local:8082"],
109-
)
110-
```
96+
Now you can pick an identity provider from the [available providers](https://django-pyoidc.readthedocs.io/en/latest/user.html#providers). Providers class are a quick way to generate the library configuration and URLs. You can also configure the settings manually, but this is not recommended if you are not familiar with the OpendID Connect (OIDC) protocol.
11197

112-
You can then add to your django configuration the following line :
98+
Add the following `DJANGO_PYOIDC` to your `settings.py` :
11399

114100
```python
115-
from .oidc_providers import my_oidc_provider
116-
101+
# settings
117102
DJANGO_PYOIDC = {
118-
**my_oidc_provider.get_config(),
119-
}
103+
# This is the name that your identity provider will have within the library
104+
"sso": {
105+
# change the following line to use your provider
106+
"provider_class": "django_pyoidc.providers.keycloak_18.Keycloak18Provider",
107+
108+
# your secret should not be stored in settings.py, load them from an env variable
109+
"client_secret": os.getenv("SSO_CLIENT_SECRET"),
110+
"client_id": os.getenv("SSO_CLIENT_ID"),
111+
112+
"provider_discovery_uri": "https://keycloak.example.com/auth/realms/fixme",
113+
114+
# This setting allow the library to cache the provider configuration auto-detected using
115+
# the `provider_discovery_uri` setting
116+
"oidc_cache_provider_metadata": True,
117+
}
120118
```
121119

122120
Finally, add OIDC views to your url configuration (`urls.py`):
123121

124122
```python
125-
from .oidc_providers import my_oidc_provider
123+
from django_pyoidc.helper import OIDCHelper
124+
125+
# `op_name` must be the name of your identity provider as used in the `DJANGO_PYOIDC` setting
126+
oidc_helper = OIDCHelper(op_name="sso")
126127

127128
urlpatterns = [
128-
path("auth", include(my_oidc_provider.get_urlpatterns())),
129+
path(
130+
"auth/",
131+
include((oidc_helper.get_urlpatterns(), "django_pyoidc"), namespace="auth"),
132+
),
129133
]
130134
```
131135

132136
And you are ready to go !
133137

134-
If you struggle with those instructions, take a look at [the quickstart tutorial](https://django-pyoidc.readthedocs.io/en/latest/tutorial.html#getting-started).
138+
If you struggle with those instructions, take a look at [the quickstart tutorial](https://django-pyoidc.readthedocs.io/en/latest/tutorial.html#requirements).
135139

136140
## Usage/Examples
137141

docs/explanation.rst

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
Makina Django OIDC Explanations
2-
===============================
3-
4-
Other OIDC libraries
5-
--------------------
1+
Why make a new OIDC library ?
2+
=============================
63

74
We decided to role our own OIDC integration with Django, and that is not a small work. As such we first performed an analysis of the existing libraries, evaluating whether or not we should contribute to them or implement our own.
85

@@ -15,6 +12,12 @@ Here are our criteria :
1512
* is it still maintained ?
1613
* does it supports *Bearer* authentication (for ``django-rest-framework``).
1714

15+
16+
`django-allauth <https://github.com/pennersr/django-allauth/>`_
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
19+
**Todo**
20+
1821
`django-auth-oidc <https://gitlab.com/aiakos/django-auth-oidc>`_
1922
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023

@@ -69,7 +72,7 @@ This library is based on ``django-auth-oidc`` and adds some glue to allow more f
6972

7073
- Very old and unmaintained
7174

72-
`Django OAuth Toolkit <https://github.com/jazzband/django-oauth-toolkit>`_
75+
`Django OAuth Toolkit <https://github.com/jazzband/django-oauth-toolkit>`_
7376
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7477

7578

@@ -85,10 +88,11 @@ This library is based on ``django-auth-oidc`` and adds some glue to allow more f
8588
- Documentation (which needs to covers also the *server* part) is not easy to use for an *simple* oidc client integration
8689

8790
This Project Goals
88-
-------------------
91+
==================
8992

90-
This project aim to make OIDC client integration with Django easier while still being robust, exapandable and flexible.
93+
This project aim to make OIDC client integration with Django easier while still being robust, expandable and flexible.
9194
To reach this goal we wanted a project with:
95+
9296
- good documentations, based on use cases and helping users doing the right things in the quite complex OIDC world
9397
- robust security components (handling the cryptography and security aspects of OIDC)
9498
- more real world usage than the too simple 'handle OIDC login' examples (like API modes, logouts, asynchronous logouts, MtoM mode, multi-tenant setup, etc.)
@@ -97,7 +101,7 @@ Handling the 'login' part in OIDC is quite easy, on the client side. And this pa
97101

98102
Direct Logout and Asynchronous logouts are more complex to understand and manage. The next section is a deeper explanation on this subject.
99103

100-
MtoM mode is about Machine-To-Machine communication, like B-to-B, the fact that you application may need to use OIDC not only to handle real
104+
MtoM mode is about Machine-To-Machine communication, like B-to-B, the fact that your application may need to use OIDC not only to handle real
101105
(human) users sessions, but also maybe connections made by some other applications, or you may also need to perform such operation (connecting
102106
a remote web service using OIDC, not using an human account but a service account instead, identifying as an application and not as a human).
103107

@@ -298,8 +302,8 @@ Note: if your Django acts as an OIDC SSO server for other applications, receivin
298302
containing an iframe with front channel logouts links for all the client applications of your Django. In this library we consider the
299303
Django website to be only an OIDC client (not server) and we did not implement this cascading front channel logout specification.
300304

301-
Cache Management
302-
----------------
305+
About caching
306+
=============
303307

304308
This library depends on **Django cache system**. Why do an OIDC client depends on a cache ?
305309

@@ -321,4 +325,4 @@ This data is stored in a database table.
321325
:alt: Illustration of how a user session is killed in a backchannel logout request
322326

323327
.. image:: images/cache/oidc_bl_2.png
324-
:alt: Illustration of how a user session is killed in a backchannel logout request
328+
:alt: Illustration of how a user session is killed in a backchannel logout request

0 commit comments

Comments
 (0)