Skip to content

Commit c7117ea

Browse files
UA-4020 | Pulled in changes from upstream 0.8.3 (#14)
* Update settings.rst * Update LICENSE * Default ordering RSA keys + example app for Django 4.2 * Update docs * Update docs * Work on end_session_endpoint * Work on end_session_endpoint * Work on end_session_endpoint * Work on end_session_endpoint * Work on end_session_endpoint * Work on end_session_endpoint * Work on end_session_endpoint * Fix create_id_token with extra scope claims + add ruff as formatter. * Fix create_id_token with extra scope claims + add ruff as formatter. * Fix create_id_token with extra scope claims + add ruff as formatter. * Bump version 0.8.3 * UA-4020 | reducing the diff between ours/theirs where its reasonable. * UA-4020 | reducing the diff between ours/theirs where its reasonable. * UA-4020 | reducing the diff between ours/theirs where its reasonable. --------- Co-authored-by: Juan Ignacio Fiorentino <[email protected]> Co-authored-by: juanifioren <[email protected]>
1 parent 116256b commit c7117ea

34 files changed

+1075
-637
lines changed

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"[python]": {
3+
"editor.formatOnSave": true,
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll": "explicit",
6+
"source.organizeImports": "explicit"
7+
},
8+
"editor.defaultFormatter": "charliermarsh.ruff"
9+
}
10+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2019 Juan Ignacio Fiorentino
3+
Copyright (c) 2014-2024 Juan Ignacio Fiorentino
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# General information about the project.
4747
project = u'django-oidc-provider'
48-
copyright = u'2023, Juan Ignacio Fiorentino'
48+
copyright = u'2025, Juan Ignacio Fiorentino'
4949
author = u'Juan Ignacio Fiorentino'
5050

5151
# The version info for the project you're documenting, acts as replacement for
@@ -55,7 +55,7 @@
5555
# The short X.Y version.
5656
version = u'0.8'
5757
# The full version, including alpha/beta/rc tags.
58-
release = u'0.8.0'
58+
release = u'0.8'
5959

6060
# The language for content autogenerated by Sphinx. Refer to documentation
6161
# for a list of supported languages.

docs/images/add_rsa_key.png

56.7 KB
Loading

docs/sections/changelog.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ All notable changes to this project will be documented in this file.
88
Unreleased
99
==========
1010

11+
None
12+
13+
0.8.3
14+
=====
15+
16+
*2024-12-06*
17+
18+
* Changed: Improved "OpenID Connect RP-Initiated Logout" implementation.
19+
* Fixed: Fix ID Tokens not including standard claims when using extra scope claims.
20+
* Fixed: RSA server keys random ordering.
21+
* Fixed: Example app working with Django 4.
1122

1223
0.8.2
1324
=====

docs/sections/contribute.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Use `tox <https://pypi.python.org/pypi/tox>`_ for running tests in each of the e
2424
# Run with Python 3.11 and Django 4.2.
2525
$ tox -e py311-django42
2626

27-
# Run single test file on specific environment.
28-
$ tox -e py311-django42 -- tests/cases/test_authorize_endpoint.py
27+
# Run a single test method.
28+
$ tox -e py311-django42 -- tests/cases/test_authorize_endpoint.py::TestClass::test_some_method
2929

3030
We use `Github Actions <https://github.com/juanifioren/django-oidc-provider/actions>`_ to automatically test every commit to the project.
3131

@@ -34,7 +34,7 @@ Improve Documentation
3434

3535
We use `Sphinx <http://www.sphinx-doc.org/>`_ to generate this documentation. If you want to add or modify something just:
3636

37-
* Install Sphinx (``pip install sphinx``) and the auto-build tool (``pip install sphinx-autobuild``).
37+
* Install Sphinx (``pip install sphinx sphinx_rtd_theme``) and the auto-build tool (``pip install sphinx-autobuild``).
3838
* Move inside the docs folder. ``cd docs/``
3939
* Generate and watch docs by running ``sphinx-autobuild . _build/``.
4040
* Open ``http://127.0.0.1:8000`` in a browser.

docs/sections/scopesclaims.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ Inside your oidc_provider_settings.py file add the following class::
111111

112112
.. note::
113113
If a field is empty or ``None`` inside the dictionary you return on the ``scope_scopename`` method, it will be cleaned from the response.
114+
115+
Include claims in the ID Token
116+
==============================
117+
118+
The draft specifies that ID Tokens MAY include additional claims. You can add claims to the ID Token using ``OIDC_IDTOKEN_INCLUDE_CLAIMS``. Note that the claims will be filtered based on the token's scope.
119+
120+
.. note::
121+
Any extra claims defined with ``OIDC_EXTRA_SCOPE_CLAIMS`` will also be included.

docs/sections/serverkeys.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Server RSA keys are used to sign/encrypt ID Tokens. These keys are stored in the
77

88
You can easily create them with the admin:
99

10-
.. image:: http://i64.tinypic.com/vj2ma.png
10+
.. image:: ../images/add_rsa_key.png
1111
:align: center
1212

1313
Or by using ``python manage.py creatersakey`` command.

docs/sections/sessionmanagement.rst

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,47 @@ Somewhere in your Django ``settings.py``::
2222
If you're in a multi-server setup, you might also want to add ``OIDC_UNAUTHENTICATED_SESSION_MANAGEMENT_KEY`` to your settings and set it to some random but fixed string. While authenticated clients have a session that can be used to calculate the browser state, there is no such thing for unauthenticated clients. Hence this value. By default a value is generated randomly on startup, so this will be different on each server. To get a consistent value across all servers you should set this yourself.
2323

2424

25+
RP-Initiated Logout
26+
===================
27+
28+
An RP can notify the OP that the End-User has logged out of the site, and might want to log out of the OP as well. In this case, the RP, after having logged the End-User out of the RP, redirects the End-User's User Agent to the OP's logout endpoint URL.
29+
30+
This URL is normally obtained via the ``end_session_endpoint`` element of the OP's Discovery response.
31+
32+
Parameters that are passed as query parameters in the logout request:
33+
34+
* ``id_token_hint``
35+
RECOMMENDED. Previously issued ID Token passed to the logout endpoint as a hint about the End-User's current authenticated session with the Client.
36+
* ``post_logout_redirect_uri``
37+
OPTIONAL. URL to which the RP is requesting that the End-User's User Agent be redirected after a logout has been performed.
38+
39+
The value must be a valid, encoded URL that has been registered in the list of "Post Logout Redirect URIs" in your Client (RP) page.
40+
* ``state``
41+
OPTIONAL. Opaque value used by the RP to maintain state between the logout request and the callback to the endpoint specified by the ``post_logout_redirect_uri`` query parameter.
42+
43+
Example redirect::
44+
45+
http://localhost:8000/end-session/?id_token_hint=eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwM...&post_logout_redirect_uri=http%3A%2F%2Frp.example.com%2Flogged-out%2F&state=c91c03ea6c46a86
46+
47+
**Logout consent prompt**
48+
49+
The standard defines that the logout flow should be interrupted to prompt the user for consent if the OpenID provider cannot verify that the request was made by the user.
50+
51+
We enforce this behavior by displaying a logout consent prompt if it detects any of the following conditions:
52+
53+
* If ``id_token_hint`` is not present or is invalid (we could not validate the client from it).
54+
* If ``post_logout_redirect_uri`` is not registered in the list of "Post Logout Redirect URIs".
55+
56+
If the user confirms the logout request, we continue the logout flow. To modify the logout consent template create your own ``oidc_provider/end_session_prompt.html``.
57+
58+
**Other scenarios**
59+
60+
In some cases, there may be no valid redirect URI for the user after logging out (e.g., the OP could not find a post-logout URI). If the user ends up being logged out, the system will render the ``oidc_provider/end_session_completed.html`` template.
61+
62+
On the other hand, if the session remains active for any reason, the ``oidc_provider/end_session_failed.html`` template will be used.
63+
64+
Both templates will receive the ``{{ client }}`` variable in their context.
65+
2566
Example RP iframe
2667
=================
2768

@@ -70,22 +111,4 @@ Example RP iframe
70111
</script>
71112
</html>
72113

73-
RP-Initiated Logout
74-
===================
75-
76-
An RP can notify the OP that the End-User has logged out of the site, and might want to log out of the OP as well. In this case, the RP, after having logged the End-User out of the RP, redirects the End-User's User Agent to the OP's logout endpoint URL.
77-
78-
This URL is normally obtained via the ``end_session_endpoint`` element of the OP's Discovery response.
79-
80-
Parameters that are passed as query parameters in the logout request:
81-
82-
* ``id_token_hint``
83-
Previously issued ID Token passed to the logout endpoint as a hint about the End-User's current authenticated session with the Client.
84-
* ``post_logout_redirect_uri``
85-
URL to which the RP is requesting that the End-User's User Agent be redirected after a logout has been performed.
86-
* ``state``
87-
OPTIONAL. Opaque value used by the RP to maintain state between the logout request and the callback to the endpoint specified by the ``post_logout_redirect_uri`` query parameter.
88-
89-
Example redirect::
90114

91-
http://localhost:8000/end-session/?id_token_hint=eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwM...&post_logout_redirect_uri=http://rp.example.com/logged-out/&state=c91c03ea6c46a86

docs/sections/settings.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ OIDC_CODE_EXPIRE
5353

5454
OPTIONAL. ``int``. Code object expiration after been delivered.
5555

56-
Expressed in seconds. Default is ``60*10``.
56+
Expressed in seconds. Default is ``10 mins``.
5757

5858
OIDC_DISCOVERY_CACHE_ENABLE
5959
===========================
@@ -67,7 +67,7 @@ OIDC_DISCOVERY_CACHE_EXPIRE
6767

6868
OPTIONAL. ``int``. Discovery endpoint cache expiration time expressed in seconds.
6969

70-
Expressed in seconds. Default is ``60*10``.
70+
Expressed in seconds. Default is ``1 day``.
7171

7272
OIDC_EXTRA_SCOPE_CLAIMS
7373
=======================
@@ -81,7 +81,7 @@ Read more about how to implement it in :ref:`scopesclaims` section.
8181
OIDC_IDTOKEN_INCLUDE_CLAIMS
8282
==============================
8383

84-
OPTIONAL. ``bool``. If enabled, id_token will include standard claims of the user (email, first name, etc.).
84+
OPTIONAL. ``bool``. If enabled, id_token will include standard (and extra if defined) claims of the user (email, first name, etc.).
8585

8686
Default is ``False``.
8787

@@ -90,7 +90,7 @@ OIDC_IDTOKEN_EXPIRE
9090

9191
OPTIONAL. ``int``. ID Token expiration after been delivered.
9292

93-
Expressed in seconds. Default is ``60*10``.
93+
Expressed in seconds. Default is ``10 mins``.
9494

9595
OIDC_IDTOKEN_PROCESSING_HOOK
9696
============================
@@ -188,14 +188,14 @@ OIDC_SKIP_CONSENT_EXPIRE
188188

189189
OPTIONAL. ``int``. How soon User Consent expires after being granted.
190190

191-
Expressed in days. Default is ``30*3``.
191+
Expressed in days. Default is ``90 days``.
192192

193193
OIDC_TOKEN_EXPIRE
194194
=================
195195

196196
OPTIONAL. ``int``. Token object (access token) expiration after being created.
197197

198-
Expressed in seconds. Default is ``60*60``.
198+
Expressed in seconds. Default is ``1 hour``.
199199

200200
OIDC_USERINFO
201201
=============
@@ -258,4 +258,4 @@ A flag which toggles whether the scope is returned with successful response on i
258258

259259
Must be ``True`` to include ``scope`` into the successful response
260260

261-
Default is ``False``.
261+
Default is ``False``.

example/app/settings.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
11
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
22
import os
3+
34
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
45

56
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
67

7-
SECRET_KEY = 'c14d549c574e4d8cf162404ef0b04598'
8+
SECRET_KEY = "c14d549c574e4d8cf162404ef0b04598"
89

910
DEBUG = True
1011

1112
TEMPLATE_DEBUG = False
1213

13-
ALLOWED_HOSTS = ['*']
14+
ALLOWED_HOSTS = ["*"]
1415

1516
# Application definition
1617

1718
INSTALLED_APPS = [
18-
'django.contrib.admin',
19-
'django.contrib.auth',
20-
'django.contrib.contenttypes',
21-
'django.contrib.sessions',
22-
'django.contrib.messages',
23-
'django.contrib.staticfiles',
24-
'app',
25-
'oidc_provider',
19+
"django.contrib.admin",
20+
"django.contrib.auth",
21+
"django.contrib.contenttypes",
22+
"django.contrib.sessions",
23+
"django.contrib.messages",
24+
"django.contrib.staticfiles",
25+
"app",
26+
"oidc_provider",
2627
]
2728

2829
MIDDLEWARE_CLASSES = [
29-
'django.contrib.sessions.middleware.SessionMiddleware',
30-
'django.middleware.common.CommonMiddleware',
31-
'django.middleware.csrf.CsrfViewMiddleware',
32-
'django.contrib.auth.middleware.AuthenticationMiddleware',
33-
'django.contrib.messages.middleware.MessageMiddleware',
34-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
35-
'oidc_provider.middleware.SessionManagementMiddleware',
30+
"django.contrib.sessions.middleware.SessionMiddleware",
31+
"django.middleware.common.CommonMiddleware",
32+
"django.middleware.csrf.CsrfViewMiddleware",
33+
"django.contrib.auth.middleware.AuthenticationMiddleware",
34+
"django.contrib.messages.middleware.MessageMiddleware",
35+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
36+
"oidc_provider.middleware.SessionManagementMiddleware",
3637
]
3738
MIDDLEWARE = MIDDLEWARE_CLASSES
3839

3940
TEMPLATES = [
4041
{
41-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
42-
'DIRS': [],
43-
'APP_DIRS': True,
44-
'OPTIONS': {
45-
'context_processors': [
46-
'django.template.context_processors.debug',
47-
'django.template.context_processors.request',
48-
'django.contrib.auth.context_processors.auth',
49-
'django.contrib.messages.context_processors.messages',
42+
"BACKEND": "django.template.backends.django.DjangoTemplates",
43+
"DIRS": [],
44+
"APP_DIRS": True,
45+
"OPTIONS": {
46+
"context_processors": [
47+
"django.template.context_processors.debug",
48+
"django.template.context_processors.request",
49+
"django.contrib.auth.context_processors.auth",
50+
"django.contrib.messages.context_processors.messages",
5051
],
5152
},
5253
},
5354
]
5455

55-
ROOT_URLCONF = 'app.urls'
56+
ROOT_URLCONF = "app.urls"
5657

57-
WSGI_APPLICATION = 'app.wsgi.application'
58+
WSGI_APPLICATION = "app.wsgi.application"
5859

5960
# Database
6061

6162
DATABASES = {
62-
'default': {
63-
'ENGINE': 'django.db.backends.sqlite3',
64-
'NAME': os.path.join(BASE_DIR, 'DATABASE.sqlite3'),
63+
"default": {
64+
"ENGINE": "django.db.backends.sqlite3",
65+
"NAME": os.path.join(BASE_DIR, "DATABASE.sqlite3"),
6566
}
6667
}
6768

6869
# Internationalization
6970

70-
LANGUAGE_CODE = 'en-us'
71+
LANGUAGE_CODE = "en-us"
7172

72-
TIME_ZONE = 'UTC'
73+
TIME_ZONE = "UTC"
7374

7475
USE_I18N = True
7576

@@ -79,14 +80,14 @@
7980

8081
# Static files (CSS, JavaScript, Images)
8182

82-
STATIC_URL = '/static/'
83-
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
83+
STATIC_URL = "/static/"
84+
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
8485

8586
# Custom settings
8687

87-
LOGIN_REDIRECT_URL = '/'
88+
LOGIN_REDIRECT_URL = "/"
8889

8990
# OIDC Provider settings
9091

91-
SITE_URL = 'http://localhost:8000'
92+
SITE_URL = "http://localhost:8000"
9293
OIDC_SESSION_MANAGEMENT_ENABLE = True

example/app/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n staticfiles %}
1+
{% load i18n static %}
22

33
<!DOCTYPE html>
44
<html lang="en">

example/app/templates/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "base.html" %}
2-
{% load i18n staticfiles %}
2+
{% load i18n static %}
33

44
{% block content %}
55

example/app/templates/oidc_provider/authorize.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'base.html' %}
2-
{% load i18n staticfiles %}
2+
{% load i18n static %}
33

44
{% block content %}
55

@@ -16,10 +16,10 @@ <h2>{% trans 'Request for Permission' %}</h2>
1616
{% endfor %}
1717
</ul>
1818
<br>
19-
<input type="submit" class="btn btn-primary btn-block btn-lg" name="allow" value="{% trans 'Accept' %}" />
19+
<input type="submit" class="btn btn-primary btn-block btn-lg" name="allow" value="{% trans 'Accept' %}" />
2020
<input type="submit" class="btn btn-secondary btn-block" value="{% trans 'Decline' %}" />
2121
</form>
2222
</div>
2323
</div>
2424

25-
{% endblock %}
25+
{% endblock %}

0 commit comments

Comments
 (0)