Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 94c6193

Browse files
committed
Merge tag '1.7.0' into pr-1.7.1-grn
2 parents 7f7f1d5 + a6bd0d0 commit 94c6193

28 files changed

+737
-110
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Install Python dependencies
3838
run: |
3939
python -m pip install --upgrade pip
40-
python -m pip install --upgrade tox tox-gh-actions django
40+
python -m pip install --upgrade tox tox-gh-actions
4141
4242
- name: Tox tests
4343
run: |

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
- id: black
66
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.0.1
8+
rev: v4.1.0
99
hooks:
1010
- id: check-ast
1111
- id: trailing-whitespace

.readthedocs.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
# .readthedocs.yml
1+
# .readthedocs.yaml
22
# Read the Docs configuration file
33
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
44

55
# Required
66
version: 2
77

8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-20.04
11+
tools:
12+
python: "3.9"
13+
# You can also specify other tool versions:
14+
# nodejs: "16"
15+
# rust: "1.55"
16+
# golang: "1.17"
17+
818
# Build documentation in the docs/ directory with Sphinx
919
sphinx:
10-
configuration: docs/conf.py
20+
configuration: docs/conf.py
21+
22+
# If using Sphinx, optionally build your docs in additional formats such as PDF
23+
# formats:
24+
# - pdf
1125

26+
# Optionally declare the Python requirements required to build your docs
1227
python:
13-
version: 3.7
14-
install:
15-
- requirements: docs/requirements.txt
28+
install:
29+
- requirements: docs/requirements.txt

AUTHORS

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Authors
2-
=======
2+
-------
33

44
Massimiliano Pippi
55
Federico Frenguelli
66

77
Contributors
8-
============
8+
------------
99

1010
Abhishek Patel
1111
Alan Crosswell
@@ -24,6 +24,7 @@ Bas van Oostveen
2424
Dave Burkholder
2525
David Fischer
2626
David Smith
27+
Dawid Wolski
2728
Diego Garcia
2829
Dulmandakh Sukhbaatar
2930
Dylan Giesler
@@ -46,6 +47,7 @@ Michael Howitz
4647
Paul Dekkers
4748
Paul Oswald
4849
Pavel Tvrdík
50+
Patrick Palacin
4951
Peter Carnesciali
5052
Petr Dlouhý
5153
Rodney Richardson
@@ -62,6 +64,7 @@ Jadiel Teófilo
6264
pySilver
6365
Łukasz Skarżyński
6466
Shaheed Haque
65-
Andrea Greco
6667
Vinay Karanam
67-
68+
Eduardo Oliveira
69+
Andrea Greco
70+
Dominik George

CHANGELOG.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Security
1515
-->
1616

17-
## [Unreleased]
17+
## [1.7.0] 2022-01-23
18+
19+
### Added
20+
* #969 Add batching of expired token deletions in `cleartokens` management command and `models.clear_expired()`
21+
to improve performance for removal of large numers of expired tokens. Configure with
22+
[`CLEAR_EXPIRED_TOKENS_BATCH_SIZE`](https://django-oauth-toolkit.readthedocs.io/en/latest/settings.html#clear-expired-tokens-batch-size) and
23+
[`CLEAR_EXPIRED_TOKENS_BATCH_INTERVAL`](https://django-oauth-toolkit.readthedocs.io/en/latest/settings.html#clear-expired-tokens-batch-interval).
24+
* #1070 Add a Celery task for clearing expired tokens, e.g. to be scheduled as a [periodic task](https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html).
25+
* #1062 Add Brazilian Portuguese (pt-BR) translations.
26+
* #1069 OIDC: Add an alternate form of
27+
[get_additional_claims()](https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#adding-claims-to-the-id-token)
28+
which makes the list of additional `claims_supported` available at the OIDC auto-discovery endpoint (`.well-known/openid-configuration`).
29+
30+
### Fixed
31+
* #1012 Return 200 status code with `{"active": false}` when introspecting a nonexistent token
32+
per [RFC 7662](https://datatracker.ietf.org/doc/html/rfc7662#section-2.2). It had been incorrectly returning 401.
33+
34+
## [1.6.3] 2022-01-11
35+
36+
### Fixed
37+
* #1085 Fix for #1083 admin UI search for idtoken results in `django.core.exceptions.FieldError: Cannot resolve keyword 'token' into field.`
38+
39+
### Added
40+
* #1085 Add admin UI search fields for additional models.
41+
42+
## [1.6.2] 2022-01-06
43+
44+
**NOTE: This release reverts an inadvertently-added breaking change.**
45+
46+
### Fixed
47+
48+
* #1056 Add missing migration triggered by [Django 4.0 changes to the migrations autodetector](https://docs.djangoproject.com/en/4.0/releases/4.0/#migrations-autodetector-changes).
49+
* #1068 Revert #967 which incorrectly changed an API. See #1066.
50+
51+
## [1.6.1] 2021-12-23
52+
53+
### Changed
54+
* Note: Only Django 4.0.1+ is supported due to a regression in Django 4.0.0. [Explanation](https://github.com/jazzband/django-oauth-toolkit/pull/1046#issuecomment-998015272)
55+
56+
### Fixed
57+
* Miscellaneous 1.6.0 packaging issues.
1858

1959
## [1.6.0] 2021-12-19
2060
### Added
@@ -32,7 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3272
* #991 Update documentation of [REFRESH_TOKEN_EXPIRE_SECONDS](https://django-oauth-toolkit.readthedocs.io/en/latest/settings.html#refresh-token-expire-seconds) to indicate it may be `int` or `datetime.timedelta`.
3373
* #977 Update [Tutorial](https://django-oauth-toolkit.readthedocs.io/en/stable/tutorial/tutorial_01.html#) to show required `include`.
3474

35-
## Removed
75+
### Removed
3676
* #968 Remove support for Django 3.0 & 3.1 and Python 3.6
3777
* #1035 Removes default_app_config for Django Deprecation Warning
3878
* #1023 six should be dropped

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ capabilities to your Django projects. Django OAuth Toolkit makes extensive use o
3535
`OAuthLib <https://github.com/idan/oauthlib>`_, so that everything is
3636
`rfc-compliant <http://tools.ietf.org/html/rfc6749>`_.
3737

38+
Note: If you have issues installing Django 4.0.0, it is because we only support
39+
Django 4.0.1+ due to a regression in Django 4.0.0. Besides 4.0.0, Django 2.2+ is supported.
40+
`Explanation <https://github.com/jazzband/django-oauth-toolkit/pull/1046#issuecomment-998015272>`_.
41+
3842
Contributing
3943
------------
4044

docs/contributing.rst

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ When deploying your app, don't forget to compile the messages with::
9696
django-admin compilemessages
9797

9898

99+
Migrations
100+
==========
101+
102+
If you alter any models, a new migration will need to be generated. This step is frequently missed
103+
by new contributors. You can check if a new migration is needed with::
104+
105+
tox -e migrations
106+
107+
And, if a new migration is needed, use::
108+
109+
django-admin makemigrations --settings tests.mig_settings
110+
111+
Auto migrations frequently have ugly names like `0004_auto_20200902_2022`. You can make your migration
112+
name "better" by adding the `-n name` option::
113+
114+
django-admin makemigrations --settings tests.mig_settings -n widget
115+
116+
99117
Pull requests
100118
=============
101119

@@ -154,7 +172,8 @@ When you begin your PR, you'll be asked to provide the following:
154172
If your PR is not yet ready to be merged mark it as a Work-in-Progress
155173
By prepending `WIP:` to the PR title so that it doesn't get inadvertently approved and merged.
156174

157-
The repo managers will be notified of your pull request and it will be reviewed, in the meantime you can continue to add
175+
Make sure to request a review by assigning Reviewer `jazzband/django-oauth-toolkit`.
176+
This will assign the review to the project team and a member will review it. In the meantime you can continue to add
158177
commits to your topic branch (and push them up to GitHub) either if you see something that needs changing, or in
159178
response to a reviewer's comments. If a reviewer asks for changes, you do not need to close the pull and reissue it
160179
after making changes. Just make the changes locally, push them to GitHub, then add a comment to the discussion section
@@ -255,7 +274,7 @@ The following notes are to remind the project maintainers and leads of the steps
255274
review and merge PRs and to publish a new release.
256275

257276
Reviewing and Merging PRs
258-
------------------------
277+
-------------------------
259278

260279
- Make sure the PR description includes the `pull request template
261280
<https://github.com/jazzband/django-oauth-toolkit/blob/master/.github/pull_request_template.md>`_
@@ -271,18 +290,25 @@ PRs that are incorrectly merged may (reluctantly) be reverted by the Project Lea
271290
Publishing a Release
272291
--------------------
273292

274-
Only Project Leads can publish a release to pypi.org and rtfd.io. This checklist is a reminder
275-
of steps.
293+
Only Project Leads can `publish a release <https://jazzband.co/about/releases>`_ to pypi.org
294+
and rtfd.io. This checklist is a reminder of the required steps.
276295

277296
- When planning a new release, create a `milestone
278297
<https://github.com/jazzband/django-oauth-toolkit/milestones>`_
279298
and assign issues, PRs, etc. to that milestone.
280299
- Review all commits since the last release and confirm that they are properly
281-
documented in the CHANGELOG. (Unfortunately, this has not always been the case
282-
so you may be stuck documenting things that should have been documented as part of their PRs.)
300+
documented in the CHANGELOG. Reword entries as appropriate with links to docs
301+
to make them meaningful to users.
283302
- Make a final PR for the release that updates:
284303

285304
- CHANGELOG to show the release date.
286-
- setup.cfg to set `version = ...`
287-
288-
- Once the final PR is committed push the new release to pypi and rtfd.io.
305+
- `oauth2_provider/__init__.py` to set `__version__ = "..."`
306+
307+
- Once the final PR is merged, create and push a tag for the release. You'll shortly
308+
get a notification from Jazzband of the availability of two pypi packages (source tgz
309+
and wheel). Download these locally before releasing them.
310+
- Do a `tox -e build` and extract the downloaded and bullt wheel zip and tgz files into
311+
temp directories and do a `diff -r` to make sure they have the same content.
312+
(Unfortunately the checksums do not match due to timestamps in the metadata
313+
so you need to compare all the files.)
314+
- Once happy that the above comparison checks out, approve the releases to Pypi.org.

docs/management_commands.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ If ``cleartokens`` runs daily the maximum delay before a refresh token is
1616
removed is ``REFRESH_TOKEN_EXPIRE_SECONDS`` + 1 day. This is normally not a
1717
problem since refresh tokens are long lived.
1818

19+
To prevent the CPU and RAM high peaks during deletion process use ``CLEAR_EXPIRED_TOKENS_BATCH_SIZE`` and
20+
``CLEAR_EXPIRED_TOKENS_BATCH_INTERVAL`` settings to adjust the process speed.
21+
1922
Note: Refresh tokens need to expire before AccessTokens can be removed from the
2023
database. Using ``cleartokens`` without ``REFRESH_TOKEN_EXPIRE_SECONDS`` has limited effect.
24+
25+
The ``cleartokens`` action can also be scheduled as a `Celery periodic task`_
26+
by using the ``clear_tokens`` task (automatically registered when using Celery).
27+
28+
.. _Celery periodic task: https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html

docs/oidc.rst

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,45 @@ required claims, eg ``iss``, ``aud``, ``exp``, ``iat``, ``auth_time`` etc),
245245
and the ``sub`` claim will use the primary key of the user as the value.
246246
You'll probably want to customize this and add additional claims or change
247247
what is sent for the ``sub`` claim. To do so, you will need to add a method to
248-
our custom validator.
249-
Standard claim ``sub`` is included by default, for remove it override ``get_claim_list``::
248+
our custom validator. It takes one of two forms:
249+
250+
The first form gets passed a request object, and should return a dictionary
251+
mapping a claim name to claim data::
252+
class CustomOAuth2Validator(OAuth2Validator):
253+
def get_additional_claims(self, request):
254+
claims = {}
255+
claims["email"] = request.user.get_user_email()
256+
claims["username"] = request.user.get_full_name()
257+
258+
return claims
259+
260+
The second form gets no request object, and should return a dictionary
261+
mapping a claim name to a callable, accepting a request and producing
262+
the claim data::
250263
class CustomOAuth2Validator(OAuth2Validator):
251264
def get_additional_claims(self):
252265
def get_user_email(request):
253-
return request.user.get_full_name()
266+
return request.user.get_user_email()
267+
268+
claims = {}
269+
claims["email"] = get_user_email
270+
claims["username"] = lambda r: r.user.get_full_name()
271+
272+
return claims
273+
274+
Standard claim ``sub`` is included by default, to remove it override ``get_claim_dict``.
275+
276+
In some cases, it might be desirable to not list all claims in discovery info. To customize
277+
which claims are advertised, you can override the ``get_discovery_claims`` method to return
278+
a list of claim names to advertise. If your ``get_additional_claims`` uses the first form
279+
and you still want to advertise claims, you can also override ``get_discovery_claims``.
254280

255-
# Element name, callback to obtain data
256-
claims_list = [ ("email", get_sub_cod),
257-
("username", get_user_email) ]
258-
return claims_list
281+
In order to help lcients discover claims early, they can be advertised in the discovery
282+
info, under the ``claims_supported`` key. In order for the discovery info view to automatically
283+
add all claims your validator returns, you need to use the second form (producing callables),
284+
because the discovery info views are requested with an unauthenticated request, so directly
285+
producing claim data would fail. If you use the first form, producing claim data directly,
286+
your claims will not be added to discovery info.
259287

260288
.. note::
261289
This ``request`` object is not a ``django.http.Request`` object, but an

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Django>=3.0,<3.1
1+
Django
22
oauthlib>=3.1.0
33
m2r>=0.2.1
44
mistune<2
5-
.
5+
-e .

0 commit comments

Comments
 (0)