summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJon Janzen <jon@jonjanzen.com>2023-02-10 20:43:26 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-06-27 11:17:17 +0200
commit5e98959d9242c57a55c65847758781f82d386fa4 (patch)
treee137f31489e3bf6893b79b5fe9984b2368e7682c /docs
parent2360ba22742c3ee8729697bfe2d508110465af56 (diff)
Fixed #34391 -- Added async-compatible interface to auth functions and related methods test clients.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/auth.txt7
-rw-r--r--docs/releases/5.0.txt12
-rw-r--r--docs/topics/auth/default.txt28
-rw-r--r--docs/topics/testing/tools.txt28
4 files changed, 74 insertions, 1 deletions
diff --git a/docs/ref/contrib/auth.txt b/docs/ref/contrib/auth.txt
index 61fd74a38f..be4960f1bf 100644
--- a/docs/ref/contrib/auth.txt
+++ b/docs/ref/contrib/auth.txt
@@ -693,6 +693,9 @@ Utility functions
.. currentmodule:: django.contrib.auth
.. function:: get_user(request)
+.. function:: aget_user(request)
+
+ *Asynchronous version*: ``aget_user()``
Returns the user model instance associated with the given ``request``’s
session.
@@ -716,3 +719,7 @@ Utility functions
.. versionchanged:: 4.1.8
Fallback verification with :setting:`SECRET_KEY_FALLBACKS` was added.
+
+ .. versionchanged:: 5.0
+
+ ``aget_user()`` function was added.
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index 0f80dc85bf..a51475f040 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -150,6 +150,12 @@ Minor features
* The default iteration count for the PBKDF2 password hasher is increased from
600,000 to 720,000.
+* The new asynchronous functions are now provided, using an
+ ``a`` prefix: :func:`django.contrib.auth.aauthenticate`,
+ :func:`~.django.contrib.auth.aget_user`,
+ :func:`~.django.contrib.auth.alogin`, :func:`~.django.contrib.auth.alogout`,
+ and :func:`~.django.contrib.auth.aupdate_session_auth_hash`.
+
* ``AuthenticationMiddleware`` now adds an :meth:`.HttpRequest.auser`
asynchronous method that returns the currently logged-in user.
@@ -366,7 +372,11 @@ Templates
Tests
~~~~~
-* ...
+* :class:`~django.test.Client` and :class:`~django.test.AsyncClient` now
+ provide asynchronous methods, using an ``a`` prefix:
+ :meth:`~django.test.Client.asession`, :meth:`~django.test.Client.alogin`,
+ :meth:`~django.test.Client.aforce_login`, and
+ :meth:`~django.test.Client.alogout`.
URLs
~~~~
diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt
index 166173336a..29238299ba 100644
--- a/docs/topics/auth/default.txt
+++ b/docs/topics/auth/default.txt
@@ -120,6 +120,9 @@ Authenticating users
--------------------
.. function:: authenticate(request=None, **credentials)
+.. function:: aauthenticate(request=None, **credentials)
+
+ *Asynchronous version*: ``aauthenticate()``
Use :func:`~django.contrib.auth.authenticate()` to verify a set of
credentials. It takes credentials as keyword arguments, ``username`` and
@@ -152,6 +155,10 @@ Authenticating users
this. Rather if you're looking for a way to login a user, use the
:class:`~django.contrib.auth.views.LoginView`.
+ .. versionchanged:: 5.0
+
+ ``aauthenticate()`` function was added.
+
.. _topic-authorization:
Permissions and Authorization
@@ -407,6 +414,9 @@ If you have an authenticated user you want to attach to the current session
- this is done with a :func:`~django.contrib.auth.login` function.
.. function:: login(request, user, backend=None)
+.. function:: alogin(request, user, backend=None)
+
+ *Asynchronous version*: ``alogin()``
To log a user in, from a view, use :func:`~django.contrib.auth.login()`. It
takes an :class:`~django.http.HttpRequest` object and a
@@ -436,6 +446,10 @@ If you have an authenticated user you want to attach to the current session
# Return an 'invalid login' error message.
...
+ .. versionchanged:: 5.0
+
+ ``alogin()`` function was added.
+
Selecting the authentication backend
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -463,6 +477,9 @@ How to log a user out
---------------------
.. function:: logout(request)
+.. function:: alogout(request)
+
+ *Asynchronous version*: ``alogout()``
To log out a user who has been logged in via
:func:`django.contrib.auth.login()`, use
@@ -488,6 +505,10 @@ How to log a user out
immediately after logging out, do that *after* calling
:func:`django.contrib.auth.logout()`.
+ .. versionchanged:: 5.0
+
+ ``alogout()`` function was added.
+
Limiting access to logged-in users
----------------------------------
@@ -935,6 +956,9 @@ and wish to have similar behavior, use the :func:`update_session_auth_hash`
function.
.. function:: update_session_auth_hash(request, user)
+.. function:: aupdate_session_auth_hash(request, user)
+
+ *Asynchronous version*: ``aupdate_session_auth_hash()``
This function takes the current request and the updated user object from
which the new session hash will be derived and updates the session hash
@@ -955,6 +979,10 @@ function.
else:
...
+ .. versionchanged:: 5.0
+
+ ``aupdate_session_auth_hash()`` function was added.
+
.. note::
Since
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 561b6eed0e..5f08f6a14d 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -440,6 +440,9 @@ Use the ``django.test.Client`` class to make requests.
The ``headers`` parameter was added.
.. method:: Client.login(**credentials)
+ .. method:: Client.alogin(**credentials)
+
+ *Asynchronous version*: ``alogin()``
If your site uses Django's :doc:`authentication system</topics/auth/index>`
and you deal with logging in users, you can use the test client's
@@ -485,7 +488,14 @@ Use the ``django.test.Client`` class to make requests.
:meth:`~django.contrib.auth.models.UserManager.create_user` helper
method to create a new user with a correctly hashed password.
+ .. versionchanged:: 5.0
+
+ ``alogin()`` method was added.
+
.. method:: Client.force_login(user, backend=None)
+ .. method:: Client.aforce_login(user, backend=None)
+
+ *Asynchronous version*: ``aforce_login()``
If your site uses Django's :doc:`authentication
system</topics/auth/index>`, you can use the ``force_login()`` method
@@ -509,7 +519,14 @@ Use the ``django.test.Client`` class to make requests.
``login()`` by :ref:`using a weaker hasher while testing
<speeding-up-tests-auth-hashers>`.
+ .. versionchanged:: 5.0
+
+ ``aforce_login()`` method was added.
+
.. method:: Client.logout()
+ .. method:: Client.alogout()
+
+ *Asynchronous version*: ``alogout()``
If your site uses Django's :doc:`authentication system</topics/auth/index>`,
the ``logout()`` method can be used to simulate the effect of a user
@@ -519,6 +536,10 @@ Use the ``django.test.Client`` class to make requests.
and session data cleared to defaults. Subsequent requests will appear
to come from an :class:`~django.contrib.auth.models.AnonymousUser`.
+ .. versionchanged:: 5.0
+
+ ``alogout()`` method was added.
+
Testing responses
-----------------
@@ -703,6 +724,13 @@ access these properties as part of a test condition.
session["somekey"] = "test"
session.save()
+.. method:: Client.asession()
+
+ .. versionadded:: 5.0
+
+ This is similar to the :attr:`session` attribute but it works in async
+ contexts.
+
Setting the language
--------------------