Skip to content

Commit e655507

Browse files
authored
Merge branch 'main' into fix/nulls-distinct-validator-8409
2 parents fa13a1e + f56ec95 commit e655507

87 files changed

Lines changed: 1056 additions & 8320 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/theme/src/drf-logos.fig filter=lfs diff=lfs merge=lfs -text

.github/FUNDING.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github: encode
2-
custom: https://fund.django-rest-framework.org/topics/funding/
1+
github: [browniebroke]
2+
open_collective: django-rest-framework

.github/dependabot.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,37 @@ updates:
1313
interval: weekly
1414
cooldown:
1515
default-days: 7
16+
17+
- package-ecosystem: "pip"
18+
directory: "/"
19+
20+
groups:
21+
test:
22+
patterns:
23+
- "pytest*"
24+
- "attrs"
25+
- "importlib-metadata"
26+
- "pytz"
27+
28+
docs:
29+
patterns:
30+
- "mkdocs"
31+
- "pylinkvalidator"
32+
33+
optional:
34+
patterns:
35+
- "coreapi"
36+
- "coreschema"
37+
- "django-filter"
38+
- "django-guardian"
39+
- "inflection"
40+
- "legacy-cgi"
41+
- "markdown"
42+
- "psycopg*"
43+
- "pygments"
44+
- "pyyaml"
45+
46+
schedule:
47+
interval: weekly
48+
cooldown:
49+
default-days: 7

.github/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- dependencies
5+
- Internal
6+
- CI
7+
- Documentation
8+
authors:
9+
- dependabot[bot]
10+
- pre-commit-ci[bot]
11+
categories:
12+
- title: Breaking changes
13+
labels:
14+
- Breaking
15+
- title: Features
16+
labels:
17+
- Feature
18+
- title: Bug fixes
19+
labels:
20+
- Bug
21+
- title: Translations
22+
labels:
23+
- Translations
24+
- title: Packaging
25+
labels:
26+
- Packaging
27+
- title: Other changes
28+
labels:
29+
- '*'

.github/workflows/main.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
pre-commit:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
20+
21+
- uses: actions/setup-python@v6
22+
with:
23+
python-version: "3.10"
24+
25+
- uses: pre-commit/action@v3.0.1
26+
1427
tests:
1528
name: Python ${{ matrix.python-version }}
1629
runs-on: ubuntu-24.04
@@ -71,7 +84,6 @@ jobs:
7184
- run: if [ $WAIT_TIME == 5 ]; then echo cannot start mkdocs server on http://localhost:8000; exit 1; fi
7285

7386
- name: Check links
74-
continue-on-error: true
7587
run: pylinkvalidate.py -P http://localhost:8000/
7688

7789
- run: echo "Done"

.github/workflows/pre-commit.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.pyc
22
*.db
33
*~
4-
.*
54
*.py.bak
65

76

@@ -14,6 +13,8 @@
1413
/env/
1514
MANIFEST
1615
coverage.*
16+
.coverage
17+
.cache/
1718

1819
!.github
1920
!.gitignore

.readthedocs.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version, and other tools you might need
8+
build:
9+
os: ubuntu-24.04
10+
tools:
11+
python: "3.13"
12+
jobs:
13+
install:
14+
- pip install --upgrade pip
15+
- pip install -e . --group docs
16+
17+
# Build documentation with Mkdocs
18+
mkdocs:
19+
configuration: mkdocs.yml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ INSTALLED_APPS = [
5555

5656
Let's take a look at a quick example of using REST framework to build a simple model-backed API for accessing users and groups.
5757

58-
Startup up a new project like so...
58+
Start up a new project like so...
5959

6060
pip install django
6161
pip install djangorestframework

docs/api-guide/authentication.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ source:
33
- authentication.py
44
---
55

6-
# Authentication
7-
86
> Auth needs to be pluggable.
97
>
108
> — Jacob Kaplan-Moss, ["REST worst practices"][cite]
@@ -89,7 +87,7 @@ Note that when a request may successfully authenticate, but still be denied perm
8987

9088
## Django 5.1+ `LoginRequiredMiddleware`
9189

92-
If you're running Django 5.1+ and use the [`LoginRequiredMiddleware`][login-required-middleware], please note that all views from DRF are opted-out of this middleware. This is because the authentication in DRF is based authentication and permissions classes, which may be determined after the middleware has been applied. Additionally, when the request is not authenticated, the middleware redirects the user to the login page, which is not suitable for API requests, where it's preferable to return a 401 status code.
90+
If you're running Django 5.1+ and use the [`LoginRequiredMiddleware`][login-required-middleware], please note that all views from DRF are opted-out of this middleware. This is because the authentication in DRF is based on authentication and permissions classes, which may be determined after the middleware has been applied. Additionally, when the request is not authenticated, the middleware redirects the user to the login page, which is not suitable for API requests, where it's preferable to return a 401 status code.
9391

9492
REST framework offers an equivalent mechanism for DRF views via the global settings, `DEFAULT_AUTHENTICATION_CLASSES` and `DEFAULT_PERMISSION_CLASSES`. They should be changed accordingly if you need to enforce that API requests are logged in.
9593

@@ -104,9 +102,9 @@ If you are deploying to Apache, and using any non-session based authentication,
104102

105103
---
106104

107-
# API Reference
105+
## API Reference
108106

109-
## BasicAuthentication
107+
### BasicAuthentication
110108

111109
This authentication scheme uses [HTTP Basic Authentication][basicauth], signed against a user's username and password. Basic authentication is generally only appropriate for testing.
112110

@@ -122,7 +120,7 @@ Unauthenticated responses that are denied permission will result in an `HTTP 401
122120
!!! note
123121
If you use `BasicAuthentication` in production you must ensure that your API is only available over `https`. You should also ensure that your API clients will always re-request the username and password at login, and will never store those details to persistent storage.
124122

125-
## TokenAuthentication
123+
### TokenAuthentication
126124

127125
!!! note
128126
The token authentication provided by Django REST framework is a fairly simple implementation.
@@ -171,9 +169,9 @@ The `curl` command line tool may be useful for testing token authenticated APIs.
171169
!!! note
172170
If you use `TokenAuthentication` in production you must ensure that your API is only available over `https`.
173171

174-
### Generating Tokens
172+
#### Generating Tokens
175173

176-
#### By using signals
174+
##### By using signals
177175

178176
If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal.
179177

@@ -197,7 +195,7 @@ If you've already created some users, you can generate tokens for all existing u
197195
for user in User.objects.all():
198196
Token.objects.get_or_create(user=user)
199197

200-
#### By exposing an api endpoint
198+
##### By exposing an api endpoint
201199

202200
When using `TokenAuthentication`, you may want to provide a mechanism for clients to obtain a token given the username and password. REST framework provides a built-in view to provide this behavior. To use it, add the `obtain_auth_token` view to your URLconf:
203201

@@ -246,7 +244,7 @@ And in your `urls.py`:
246244
]
247245

248246

249-
#### With Django admin
247+
##### With Django admin
250248

251249
It is also possible to create Tokens manually through the admin interface. In case you are using a large user base, we recommend that you monkey patch the `TokenAdmin` class to customize it to your needs, more specifically by declaring the `user` field as `raw_field`.
252250

@@ -257,7 +255,7 @@ It is also possible to create Tokens manually through the admin interface. In ca
257255
TokenAdmin.raw_id_fields = ['user']
258256

259257

260-
#### Using Django manage.py command
258+
##### Using Django manage.py command
261259

262260
Since version 3.6.4 it's possible to generate a user token using the following command:
263261

@@ -272,7 +270,7 @@ In case you want to regenerate the token (for example if it has been compromised
272270
./manage.py drf_create_token -r <username>
273271

274272

275-
## SessionAuthentication
273+
### SessionAuthentication
276274

277275
This authentication scheme uses Django's default session backend for authentication. Session authentication is appropriate for AJAX clients that are running in the same session context as your website.
278276

@@ -291,7 +289,7 @@ If you're using an AJAX-style API with SessionAuthentication, you'll need to mak
291289
CSRF validation in REST framework works slightly differently from standard Django due to the need to support both session and non-session based authentication to the same views. This means that only authenticated requests require CSRF tokens, and anonymous requests may be sent without CSRF tokens. This behavior is not suitable for login views, which should always have CSRF validation applied.
292290

293291

294-
## RemoteUserAuthentication
292+
### RemoteUserAuthentication
295293

296294
This authentication scheme allows you to delegate authentication to your web server, which sets the `REMOTE_USER`
297295
environment variable.
@@ -312,7 +310,7 @@ Consult your web server's documentation for information about configuring an aut
312310
* [NGINX (Restricting Access)](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/)
313311

314312

315-
# Custom authentication
313+
## Custom authentication
316314

317315
To implement a custom authentication scheme, subclass `BaseAuthentication` and override the `.authenticate(self, request)` method. The method should return a two-tuple of `(user, auth)` if authentication succeeds, or `None` otherwise.
318316

@@ -330,7 +328,7 @@ If the `.authenticate_header()` method is not overridden, the authentication sch
330328
!!! note
331329
When your custom authenticator is invoked by the request object's `.user` or `.auth` properties, you may see an `AttributeError` re-raised as a `WrappedAttributeError`. This is necessary to prevent the original exception from being suppressed by the outer property access. Python will not recognize that the `AttributeError` originates from your custom authenticator and will instead assume that the request object does not have a `.user` or `.auth` property. These errors should be fixed or otherwise handled by your authenticator.
332330

333-
## Example
331+
### Example
334332

335333
The following example will authenticate any incoming request as the user given by the username in a custom request header named 'X-USERNAME'.
336334

@@ -353,19 +351,19 @@ The following example will authenticate any incoming request as the user given b
353351

354352
---
355353

356-
# Third party packages
354+
## Third party packages
357355

358356
The following third-party packages are also available.
359357

360-
## django-rest-knox
358+
### django-rest-knox
361359

362360
[Django-rest-knox][django-rest-knox] library provides models and views to handle token-based authentication in a more secure and extensible way than the built-in TokenAuthentication scheme - with Single Page Applications and Mobile clients in mind. It provides per-client tokens, and views to generate them when provided some other authentication (usually basic authentication), to delete the token (providing a server enforced logout) and to delete all tokens (logs out all clients that a user is logged into).
363361

364-
## Django OAuth Toolkit
362+
### Django OAuth Toolkit
365363

366364
The [Django OAuth Toolkit][django-oauth-toolkit] package provides OAuth 2.0 support and works with Python 3.4+. The package is maintained by [jazzband][jazzband] and uses the excellent [OAuthLib][oauthlib]. The package is well documented, and well supported and is currently our **recommended package for OAuth 2.0 support**.
367365

368-
### Installation & configuration
366+
#### Installation & configuration
369367

370368
Install using `pip`.
371369

@@ -386,42 +384,42 @@ Add the package to your `INSTALLED_APPS` and modify your REST framework settings
386384

387385
For more details see the [Django REST framework - Getting started][django-oauth-toolkit-getting-started] documentation.
388386

389-
## Django REST framework OAuth
387+
### Django REST framework OAuth
390388

391389
The [Django REST framework OAuth][django-rest-framework-oauth] package provides both OAuth1 and OAuth2 support for REST framework.
392390

393391
This package was previously included directly in the REST framework but is now supported and maintained as a third-party package.
394392

395-
### Installation & configuration
393+
#### Installation & configuration
396394

397395
Install the package using `pip`.
398396

399397
pip install djangorestframework-oauth
400398

401399
For details on configuration and usage see the Django REST framework OAuth documentation for [authentication][django-rest-framework-oauth-authentication] and [permissions][django-rest-framework-oauth-permissions].
402400

403-
## JSON Web Token Authentication
401+
### JSON Web Token Authentication
404402

405403
JSON Web Token is a fairly new standard which can be used for token-based authentication. Unlike the built-in TokenAuthentication scheme, JWT Authentication doesn't need to use a database to validate a token. A package for JWT authentication is [djangorestframework-simplejwt][djangorestframework-simplejwt] which provides some features as well as a pluggable token blacklist app.
406404

407-
## Hawk HTTP Authentication
405+
### Hawk HTTP Authentication
408406

409407
The [HawkREST][hawkrest] library builds on the [Mohawk][mohawk] library to let you work with [Hawk][hawk] signed requests and responses in your API. [Hawk][hawk] lets two parties securely communicate with each other using messages signed by a shared key. It is based on [HTTP MAC access authentication][mac] (which was based on parts of [OAuth 1.0][oauth-1.0a]).
410408

411-
## HTTP Signature Authentication
409+
### HTTP Signature Authentication
412410

413411
HTTP Signature (currently a [IETF draft][http-signature-ietf-draft]) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to [Amazon's HTTP Signature scheme][amazon-http-signature], used by many of its services, it permits stateless, per-request authentication. [Elvio Toccalino][etoccalino] maintains the [djangorestframework-httpsignature][djangorestframework-httpsignature] (outdated) package which provides an easy-to-use HTTP Signature Authentication mechanism. You can use the updated fork version of [djangorestframework-httpsignature][djangorestframework-httpsignature], which is [drf-httpsig][drf-httpsig].
414412

415-
## Djoser
413+
### Djoser
416414

417415
[Djoser][djoser] library provides a set of views to handle basic actions such as registration, login, logout, password reset and account activation. The package works with a custom user model and uses token-based authentication. This is a ready to use REST implementation of the Django authentication system.
418416

419-
## DRF Auth Kit
417+
### DRF Auth Kit
420418

421419
[DRF Auth Kit][drf-auth-kit] library provides a modern REST authentication solution with JWT cookies, social login, multi-factor authentication, and comprehensive user management. The package offers full type safety, automatic OpenAPI schema generation with DRF Spectacular. It supports multiple authentication types (JWT, DRF Token, or Custom) and includes built-in internationalization for 50+ languages.
422420

423421

424-
## django-rest-auth / dj-rest-auth
422+
### django-rest-auth / dj-rest-auth
425423

426424
This library provides a set of REST API endpoints for registration, authentication (including social media authentication), password reset, retrieve and update user details, etc. By having these API endpoints, your client apps such as AngularJS, iOS, Android, and others can communicate to your Django backend site independently via REST APIs for user management.
427425

@@ -431,25 +429,25 @@ There are currently two forks of this project.
431429
* [Django-rest-auth][django-rest-auth] is the original project, [but is not currently receiving updates](https://github.com/Tivix/django-rest-auth/issues/568).
432430
* [Dj-rest-auth][dj-rest-auth] is a newer fork of the project.
433431

434-
## drf-social-oauth2
432+
### drf-social-oauth2
435433

436434
[Drf-social-oauth2][drf-social-oauth2] is a framework that helps you authenticate with major social oauth2 vendors, such as Facebook, Google, Twitter, Orcid, etc. It generates tokens in a JWTed way with an easy setup.
437435

438-
## drfpasswordless
436+
### drfpasswordless
439437

440438
[drfpasswordless][drfpasswordless] adds (Medium, Square Cash inspired) passwordless support to Django REST Framework's TokenAuthentication scheme. Users log in and sign up with a token sent to a contact point like an email address or a mobile number.
441439

442-
## django-rest-authemail
440+
### django-rest-authemail
443441

444442
[django-rest-authemail][django-rest-authemail] provides a RESTful API interface for user signup and authentication. Email addresses are used for authentication, rather than usernames. API endpoints are available for signup, signup email verification, login, logout, password reset, password reset verification, email change, email change verification, password change, and user detail. A fully functional example project and detailed instructions are included.
445443

446-
## Django-Rest-Durin
444+
### Django-Rest-Durin
447445

448446
[Django-Rest-Durin][django-rest-durin] is built with the idea to have one library that does token auth for multiple Web/CLI/Mobile API clients via one interface but allows different token configuration for each API Client that consumes the API. It provides support for multiple tokens per user via custom models, views, permissions that work with Django-Rest-Framework. The token expiration time can be different per API client and is customizable via the Django Admin Interface.
449447

450448
More information can be found in the [Documentation](https://django-rest-durin.readthedocs.io/en/latest/index.html).
451449

452-
## django-pyoidc
450+
### django-pyoidc
453451

454452
[django_pyoidc][django-pyoidc] adds support for OpenID Connect (OIDC) authentication. This allows you to delegate user management to an Identity Provider, which can be used to implement Single-Sign-On (SSO). It provides support for most uses-cases, such as customizing how token info are mapped to user models, using OIDC audiences for access control, etc.
455453

0 commit comments

Comments
 (0)