Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Update django-oauth-toolkit to 3.4.1 (#5818)

Olga Bulat5fac181af999
diff --git a/api/api/migrations/0074_throttledapplication_cimd_expires_at_and_more.py b/api/api/migrations/0074_throttledapplication_cimd_expires_at_and_more.py
new file mode 100644
index 000000000..2d39c9ea1
--- /dev/null
+++ b/api/api/migrations/0074_throttledapplication_cimd_expires_at_and_more.py
@@ -0,0 +1,98 @@
+# Generated by Django 5.2.19 on 2026-11-17 05:36
+
+import django.db.models.deletion
+import oauth2_provider.generators
+import oauth2_provider.models
+from django.conf import settings
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0073_alter_throttledapplication_authorization_grant_type_and_more'),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='throttledapplication',
+ name='cimd_expires_at',
+ field=models.DateTimeField(blank=True, default=None, help_text='When the cached Client ID Metadata Document should be re-fetched', null=True, verbose_name='CIMD expires at'),
+ ),
+ migrations.AddField(
+ model_name='throttledapplication',
+ name='registration_source',
+ field=models.CharField(choices=[('manual', 'Manual'), ('dcr', 'Dynamic Client Registration'), ('cimd', 'Client ID Metadata Document')], default='manual', help_text='How this application was registered (manual, DCR per RFC 7591, or CIMD)', max_length=32, verbose_name='registration source'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='algorithm',
+ field=models.CharField(blank=True, choices=[('', 'No OIDC support'), ('RS256', 'RSA with SHA-2 256'), ('HS256', 'HMAC with SHA-2 256')], default='', max_length=5, verbose_name='algorithm'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='allowed_origins',
+ field=models.TextField(blank=True, default='', help_text='Allowed origins list to enable CORS, space separated', verbose_name='allowed origins'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='authorization_grant_type',
+ field=models.CharField(choices=[('authorization-code', 'Authorization code'), ('urn:ietf:params:oauth:grant-type:device_code', 'Device Code'), ('implicit', 'Implicit'), ('password', 'Resource owner password-based'), ('client-credentials', 'Client credentials'), ('openid-hybrid', 'OpenID connect hybrid')], max_length=44, verbose_name='authorization grant type'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='client_id',
+ field=models.CharField(db_index=True, default=oauth2_provider.generators.generate_client_id, max_length=255, unique=True, verbose_name='client ID'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='client_secret',
+ field=oauth2_provider.models.ClientSecretField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, help_text='Client secret for authentication', max_length=255, verbose_name='client secret'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='client_type',
+ field=models.CharField(choices=[('confidential', 'Confidential'), ('public', 'Public')], max_length=32, verbose_name='client type'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='created',
+ field=models.DateTimeField(auto_now_add=True, verbose_name='created'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='hash_client_secret',
+ field=models.BooleanField(default=True, verbose_name='hash client secret'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='name',
+ field=models.CharField(blank=True, max_length=255, verbose_name='name'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='post_logout_redirect_uris',
+ field=models.TextField(blank=True, default='', help_text='Allowed Post Logout URIs list, space separated', verbose_name='post logout redirect URIs'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='redirect_uris',
+ field=models.TextField(blank=True, help_text='Allowed URIs list, space separated', verbose_name='redirect URIs'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='skip_authorization',
+ field=models.BooleanField(default=False, verbose_name='skip authorization'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='updated',
+ field=models.DateTimeField(auto_now=True, verbose_name='updated'),
+ ),
+ migrations.AlterField(
+ model_name='throttledapplication',
+ name='user',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s', to=settings.AUTH_USER_MODEL, verbose_name='user'),
+ ),
+ ]
diff --git a/api/conf/urls/auth_tokens.py b/api/conf/urls/auth_tokens.py
index 6b528d6b8..9ec1e66e2 100644
--- a/api/conf/urls/auth_tokens.py
+++ b/api/conf/urls/auth_tokens.py
@@ -1,13 +1,30 @@
from django.urls import include, path
+from oauth2_provider import urls as oauth2_urls
+
from api.views.oauth2_views import CheckRates, Register, TokenView, VerifyEmail
+# Mount only the toolkit's base and management routes. Its default
+# ``urlpatterns`` also publish RFC 8414/9728 metadata documents that advertise
+# grant types this API does not support, Dynamic Client Registration routes,
+# and OIDC routes that raise ``ImproperlyConfigured`` because OIDC is not
+# enabled.
+oauth2_provider_urlpatterns = (
+ oauth2_urls.base_urlpatterns + oauth2_urls.management_urlpatterns
+)
+
auth_tokens_urlpatterns = [
path("register/", Register.as_view(), name="register"),
path("verify/<str:code>/", VerifyEmail.as_view(), name="verify-email"),
path("token/", TokenView.as_view(), name="token"),
- path("", include("oauth2_provider.urls", namespace="oauth2_provider")),
+ path(
+ "",
+ include(
+ (oauth2_provider_urlpatterns, oauth2_urls.app_name),
+ namespace="oauth2_provider",
+ ),
+ ),
]
urlpatterns = [
diff --git a/api/latest_migrations/api b/api/latest_migrations/api
index 2f8377bd5..bdee7d2b5 100644
--- a/api/latest_migrations/api
+++ b/api/latest_migrations/api
@@ -2,4 +2,4 @@
# If you have a merge conflict in this file, it means you need to run:
# manage.py makemigrations --merge
# in order to resolve the conflict between migrations.
-0073_alter_throttledapplication_authorization_grant_type_and_more
+0074_throttledapplication_cimd_expires_at_and_more
diff --git a/api/latest_migrations/oauth2_provider b/api/latest_migrations/oauth2_provider
index e4bdd8892..54efcf42a 100644
--- a/api/latest_migrations/oauth2_provider
+++ b/api/latest_migrations/oauth2_provider
@@ -2,4 +2,4 @@
# If you have a merge conflict in this file, it means you need to run:
# manage.py makemigrations --merge
# in order to resolve the conflict between migrations.
-0014_alter_help_text
+0022_refreshtoken_token_family_index
diff --git a/api/pyproject.toml b/api/pyproject.toml
index b7baa7d1d..daf11f091 100644
--- a/api/pyproject.toml
+++ b/api/pyproject.toml
@@ -18,7 +18,7 @@ dependencies = [
"django-asgi-lifespan >=0.4, <0.5",
"django-cors-headers >=4.3.1, <5",
"django-migrations-git-conflicts >=1.0, <2",
- "django-oauth-toolkit >=3.3.0, <3.4",
+ "django-oauth-toolkit >=3.4.1, <4",
"django-redis >=6.0.0, <7",
"django-split-settings >=1.2.0, <2",
"django-structlog >=9, <10",
diff --git a/api/test/unit/views/test_oauth2_urls.py b/api/test/unit/views/test_oauth2_urls.py
new file mode 100644
index 000000000..1b43d1a8d
--- /dev/null
+++ b/api/test/unit/views/test_oauth2_urls.py
@@ -0,0 +1,33 @@
+from django.urls import reverse
+
+import pytest
+
+
+ "path",
+ [
+ "/v1/auth_tokens/.well-known/oauth-authorization-server",
+ "/v1/auth_tokens/.well-known/oauth-protected-resource",
+ "/v1/auth_tokens/register/some-client-id/",
+ "/v1/auth_tokens/.well-known/openid-configuration",
+ "/v1/auth_tokens/.well-known/jwks.json",
+ "/v1/auth_tokens/userinfo/",
+ "/v1/auth_tokens/logout/",
+ ],
+)
+def test_unused_toolkit_routes_are_not_mounted(api_client, path):
+ res = api_client.get(path)
+
+ assert res.status_code == 404
+
+
+ ("name", "expected_path"),
+ [
+ ("oauth2_provider:authorize", "/v1/auth_tokens/authorize/"),
+ ("oauth2_provider:revoke-token", "/v1/auth_tokens/revoke_token/"),
+ ("oauth2_provider:introspect", "/v1/auth_tokens/introspect/"),
+ ],
+)
+def test_toolkit_base_routes_are_still_mounted(name, expected_path):
+ assert reverse(name) == expected_path
diff --git a/api/uv.lock b/api/uv.lock
index 1f8a7e4fb..9b31a8579 100644
--- a/api/uv.lock
+++ b/api/uv.lock
@@ -374,17 +374,18 @@ wheels = [
[[package]]
name = "django-oauth-toolkit"
-version = "3.3.0"
+version = "3.4.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
{ name = "jwcrypto" },
{ name = "oauthlib" },
{ name = "requests" },
+ { name = "urllib3" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/62/2b/011f3e964f474b7814828586de0277ad373197096b28274d0ae8bf45d5f9/django_oauth_toolkit-3.3.0.tar.gz", hash = "sha256:2b375d14b1c0ff86e5df5e5de5d1a6d9868873304f54aca37c50158552d5b922", size = 118319, upload-time = "2026-05-29T18:13:57.065Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/66/42/b3c6a5d7e204011a702cc02ababb756d10538645dfd188ea441e4c65a082/django_oauth_toolkit-3.4.1.tar.gz", hash = "sha256:c4de73c0765eed55a99ea0fa8433b20664dcc1f43930149cff569abed166c5c2", size = 256139, upload-time = "2026-08-21T03:45:36.538Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/26/e4/d05b3d50d0250f2d2f3a5dc9cd21f85e313ee1493ff60b729dccb8e08c46/django_oauth_toolkit-3.3.0-py3-none-any.whl", hash = "sha256:7af1365cd80735211454b0dca810bc9e860c631e61fd17768ad0fa331737954f", size = 88415, upload-time = "2026-05-29T18:13:55.827Z" },
+ { url = "https://files.pythonhosted.org/packages/c4/16/11cf2eacd7ac1c32908288b6d56fadef5676071a4ac0af7e626fd1abd3ef/django_oauth_toolkit-3.4.1-py3-none-any.whl", hash = "sha256:c47f2a70e83bade0a47a5e9b20e86030d8ed9c0a8f10ec4ed30446cad7291f2d", size = 163957, upload-time = "2026-08-21T03:45:34.904Z" },
]
[[package]]
@@ -1024,7 +1025,7 @@ requires-dist = [
{ name = "django-asgi-lifespan", specifier = ">=0.4,<0.5" },
{ name = "django-cors-headers", specifier = ">=4.3.1,<5" },
{ name = "django-migrations-git-conflicts", specifier = ">=1.0,<2" },
- { name = "django-oauth-toolkit", specifier = ">=3.3.0,<3.4" },
+ { name = "django-oauth-toolkit", specifier = ">=3.4.1,<4" },
{ name = "django-redis", specifier = ">=6.0.0,<7" },
{ name = "django-split-settings", specifier = ">=1.2.0,<2" },
{ name = "django-structlog", specifier = ">=9,<10" },