auth.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. =======================
  2. ``django.contrib.auth``
  3. =======================
  4. This document provides API reference material for the components of Django's
  5. authentication system. For more details on the usage of these components or
  6. how to customize authentication and authorization see the :doc:`authentication
  7. topic guide </topics/auth/index>`.
  8. .. currentmodule:: django.contrib.auth
  9. ``User`` model
  10. ==============
  11. Fields
  12. ------
  13. .. class:: models.User
  14. :class:`~django.contrib.auth.models.User` objects have the following
  15. fields:
  16. .. attribute:: username
  17. Required. 150 characters or fewer. Usernames may contain alphanumeric,
  18. ``_``, ``@``, ``+``, ``.`` and ``-`` characters.
  19. The ``max_length`` should be sufficient for many use cases. If you need
  20. a longer length, please use a :ref:`custom user model
  21. <specifying-custom-user-model>`. If you use MySQL with the ``utf8mb4``
  22. encoding (recommended for proper Unicode support), specify at most
  23. ``max_length=191`` because MySQL can only create unique indexes with
  24. 191 characters in that case by default.
  25. .. admonition:: Usernames and Unicode
  26. Django originally accepted only ASCII letters in usernames.
  27. Although it wasn't a deliberate choice, Unicode characters have
  28. always been accepted when using Python 3. Django 1.10 officially
  29. added Unicode support in usernames, keeping the ASCII-only behavior
  30. on Python 2, with the option to customize the behavior using
  31. :attr:`.User.username_validator`.
  32. .. attribute:: first_name
  33. Optional. 30 characters or fewer.
  34. .. attribute:: last_name
  35. Optional. 30 characters or fewer.
  36. .. attribute:: email
  37. Optional. Email address.
  38. .. attribute:: password
  39. Required. A hash of, and metadata about, the password. (Django doesn't
  40. store the raw password.) Raw passwords can be arbitrarily long and can
  41. contain any character. See the :doc:`password documentation
  42. </topics/auth/passwords>`.
  43. .. attribute:: groups
  44. Many-to-many relationship to :class:`~django.contrib.auth.models.Group`
  45. .. attribute:: user_permissions
  46. Many-to-many relationship to :class:`~django.contrib.auth.models.Permission`
  47. .. attribute:: is_staff
  48. Boolean. Designates whether this user can access the admin site.
  49. .. attribute:: is_active
  50. Boolean. Designates whether this user account should be considered
  51. active. We recommend that you set this flag to ``False`` instead of
  52. deleting accounts; that way, if your applications have any foreign keys
  53. to users, the foreign keys won't break.
  54. This doesn't necessarily control whether or not the user can log in.
  55. Authentication backends aren't required to check for the ``is_active``
  56. flag but the default backend
  57. (:class:`~django.contrib.auth.backends.ModelBackend`) and the
  58. :class:`~django.contrib.auth.backends.RemoteUserBackend` do. You can
  59. use :class:`~django.contrib.auth.backends.AllowAllUsersModelBackend`
  60. or :class:`~django.contrib.auth.backends.AllowAllUsersRemoteUserBackend`
  61. if you want to allow inactive users to login. In this case, you'll also
  62. want to customize the
  63. :class:`~django.contrib.auth.forms.AuthenticationForm` used by the
  64. :class:`~django.contrib.auth.views.LoginView` as it rejects inactive
  65. users. Be aware that the permission-checking methods such as
  66. :meth:`~django.contrib.auth.models.User.has_perm` and the
  67. authentication in the Django admin all return ``False`` for inactive
  68. users.
  69. .. attribute:: is_superuser
  70. Boolean. Designates that this user has all permissions without
  71. explicitly assigning them.
  72. .. attribute:: last_login
  73. A datetime of the user's last login.
  74. .. attribute:: date_joined
  75. A datetime designating when the account was created. Is set to the
  76. current date/time by default when the account is created.
  77. Attributes
  78. ----------
  79. .. class:: models.User
  80. .. attribute:: is_authenticated
  81. Read-only attribute which is always ``True`` (as opposed to
  82. ``AnonymousUser.is_authenticated`` which is always ``False``). This is
  83. a way to tell if the user has been authenticated. This does not imply
  84. any permissions and doesn't check if the user is active or has a valid
  85. session. Even though normally you will check this attribute on
  86. ``request.user`` to find out whether it has been populated by the
  87. :class:`~django.contrib.auth.middleware.AuthenticationMiddleware`
  88. (representing the currently logged-in user), you should know this
  89. attribute is ``True`` for any :class:`~models.User` instance.
  90. .. attribute:: is_anonymous
  91. Read-only attribute which is always ``False``. This is a way of
  92. differentiating :class:`~models.User` and :class:`~models.AnonymousUser`
  93. objects. Generally, you should prefer using
  94. :attr:`~django.contrib.auth.models.User.is_authenticated` to this
  95. attribute.
  96. .. attribute:: username_validator
  97. Points to a validator instance used to validate usernames. Defaults to
  98. :class:`validators.UnicodeUsernameValidator` on Python 3 and
  99. :class:`validators.ASCIIUsernameValidator` on Python 2.
  100. To change the default username validator, you can subclass the ``User``
  101. model and set this attribute to a different validator instance. For
  102. example, to use ASCII usernames on Python 3::
  103. from django.contrib.auth.models import User
  104. from django.contrib.auth.validators import ASCIIUsernameValidator
  105. class CustomUser(User):
  106. username_validator = ASCIIUsernameValidator()
  107. class Meta:
  108. proxy = True # If no new field is added.
  109. Methods
  110. -------
  111. .. class:: models.User
  112. .. method:: get_username()
  113. Returns the username for the user. Since the ``User`` model can be
  114. swapped out, you should use this method instead of referencing the
  115. username attribute directly.
  116. .. method:: get_full_name()
  117. Returns the :attr:`~django.contrib.auth.models.User.first_name` plus
  118. the :attr:`~django.contrib.auth.models.User.last_name`, with a space in
  119. between.
  120. .. method:: get_short_name()
  121. Returns the :attr:`~django.contrib.auth.models.User.first_name`.
  122. .. method:: set_password(raw_password)
  123. Sets the user's password to the given raw string, taking care of the
  124. password hashing. Doesn't save the
  125. :class:`~django.contrib.auth.models.User` object.
  126. When the ``raw_password`` is ``None``, the password will be set to an
  127. unusable password, as if
  128. :meth:`~django.contrib.auth.models.User.set_unusable_password()`
  129. were used.
  130. .. method:: check_password(raw_password)
  131. Returns ``True`` if the given raw string is the correct password for
  132. the user. (This takes care of the password hashing in making the
  133. comparison.)
  134. .. method:: set_unusable_password()
  135. Marks the user as having no password set. This isn't the same as
  136. having a blank string for a password.
  137. :meth:`~django.contrib.auth.models.User.check_password()` for this user
  138. will never return ``True``. Doesn't save the
  139. :class:`~django.contrib.auth.models.User` object.
  140. You may need this if authentication for your application takes place
  141. against an existing external source such as an LDAP directory.
  142. .. method:: has_usable_password()
  143. Returns ``False`` if
  144. :meth:`~django.contrib.auth.models.User.set_unusable_password()` has
  145. been called for this user.
  146. .. method:: get_group_permissions(obj=None)
  147. Returns a set of permission strings that the user has, through their
  148. groups.
  149. If ``obj`` is passed in, only returns the group permissions for
  150. this specific object.
  151. .. method:: get_all_permissions(obj=None)
  152. Returns a set of permission strings that the user has, both through
  153. group and user permissions.
  154. If ``obj`` is passed in, only returns the permissions for this
  155. specific object.
  156. .. method:: has_perm(perm, obj=None)
  157. Returns ``True`` if the user has the specified permission, where perm
  158. is in the format ``"<app label>.<permission codename>"``. (see
  159. documentation on :ref:`permissions <topic-authorization>`). If the user is
  160. inactive, this method will always return ``False``.
  161. If ``obj`` is passed in, this method won't check for a permission for
  162. the model, but for this specific object.
  163. .. method:: has_perms(perm_list, obj=None)
  164. Returns ``True`` if the user has each of the specified permissions,
  165. where each perm is in the format
  166. ``"<app label>.<permission codename>"``. If the user is inactive,
  167. this method will always return ``False``.
  168. If ``obj`` is passed in, this method won't check for permissions for
  169. the model, but for the specific object.
  170. .. method:: has_module_perms(package_name)
  171. Returns ``True`` if the user has any permissions in the given package
  172. (the Django app label). If the user is inactive, this method will
  173. always return ``False``.
  174. .. method:: email_user(subject, message, from_email=None, **kwargs)
  175. Sends an email to the user. If ``from_email`` is ``None``, Django uses
  176. the :setting:`DEFAULT_FROM_EMAIL`. Any ``**kwargs`` are passed to the
  177. underlying :meth:`~django.core.mail.send_mail()` call.
  178. Manager methods
  179. ---------------
  180. .. class:: models.UserManager
  181. The :class:`~django.contrib.auth.models.User` model has a custom manager
  182. that has the following helper methods (in addition to the methods provided
  183. by :class:`~django.contrib.auth.models.BaseUserManager`):
  184. .. method:: create_user(username, email=None, password=None, **extra_fields)
  185. Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
  186. The :attr:`~django.contrib.auth.models.User.username` and
  187. :attr:`~django.contrib.auth.models.User.password` are set as given. The
  188. domain portion of :attr:`~django.contrib.auth.models.User.email` is
  189. automatically converted to lowercase, and the returned
  190. :class:`~django.contrib.auth.models.User` object will have
  191. :attr:`~django.contrib.auth.models.User.is_active` set to ``True``.
  192. If no password is provided,
  193. :meth:`~django.contrib.auth.models.User.set_unusable_password()` will
  194. be called.
  195. The ``extra_fields`` keyword arguments are passed through to the
  196. :class:`~django.contrib.auth.models.User`’s ``__init__`` method to
  197. allow setting arbitrary fields on a :ref:`custom user model
  198. <auth-custom-user>`.
  199. See :ref:`Creating users <topics-auth-creating-users>` for example usage.
  200. .. method:: create_superuser(username, email, password, **extra_fields)
  201. Same as :meth:`create_user`, but sets :attr:`~models.User.is_staff` and
  202. :attr:`~models.User.is_superuser` to ``True``.
  203. ``AnonymousUser`` object
  204. ========================
  205. .. class:: models.AnonymousUser
  206. :class:`django.contrib.auth.models.AnonymousUser` is a class that
  207. implements the :class:`django.contrib.auth.models.User` interface, with
  208. these differences:
  209. * :ref:`id <automatic-primary-key-fields>` is always ``None``.
  210. * :attr:`~django.contrib.auth.models.User.username` is always the empty
  211. string.
  212. * :meth:`~django.contrib.auth.models.User.get_username()` always returns
  213. the empty string.
  214. * :attr:`~django.contrib.auth.models.User.is_anonymous` is ``True``
  215. instead of ``False``.
  216. * :attr:`~django.contrib.auth.models.User.is_authenticated` is
  217. ``False`` instead of ``True``.
  218. * :attr:`~django.contrib.auth.models.User.is_staff` and
  219. :attr:`~django.contrib.auth.models.User.is_superuser` are always
  220. ``False``.
  221. * :attr:`~django.contrib.auth.models.User.is_active` is always ``False``.
  222. * :attr:`~django.contrib.auth.models.User.groups` and
  223. :attr:`~django.contrib.auth.models.User.user_permissions` are always
  224. empty.
  225. * :meth:`~django.contrib.auth.models.User.set_password()`,
  226. :meth:`~django.contrib.auth.models.User.check_password()`,
  227. :meth:`~django.db.models.Model.save` and
  228. :meth:`~django.db.models.Model.delete()` raise :exc:`NotImplementedError`.
  229. In practice, you probably won't need to use
  230. :class:`~django.contrib.auth.models.AnonymousUser` objects on your own, but
  231. they're used by Web requests, as explained in the next section.
  232. ``Permission`` model
  233. ====================
  234. .. class:: models.Permission
  235. Fields
  236. ------
  237. :class:`~django.contrib.auth.models.Permission` objects have the following
  238. fields:
  239. .. class:: models.Permission
  240. .. attribute:: name
  241. Required. 255 characters or fewer. Example: ``'Can vote'``.
  242. .. attribute:: content_type
  243. Required. A reference to the ``django_content_type`` database table,
  244. which contains a record for each installed model.
  245. .. attribute:: codename
  246. Required. 100 characters or fewer. Example: ``'can_vote'``.
  247. Methods
  248. -------
  249. :class:`~django.contrib.auth.models.Permission` objects have the standard
  250. data-access methods like any other :doc:`Django model </ref/models/instances>`.
  251. ``Group`` model
  252. ===============
  253. .. class:: models.Group
  254. Fields
  255. ------
  256. :class:`~django.contrib.auth.models.Group` objects have the following fields:
  257. .. class:: models.Group
  258. .. attribute:: name
  259. Required. 80 characters or fewer. Any characters are permitted. Example:
  260. ``'Awesome Users'``.
  261. .. attribute:: permissions
  262. Many-to-many field to :class:`~django.contrib.auth.models.Permission`::
  263. group.permissions.set([permission_list])
  264. group.permissions.add(permission, permission, ...)
  265. group.permissions.remove(permission, permission, ...)
  266. group.permissions.clear()
  267. Validators
  268. ==========
  269. .. class:: validators.ASCIIUsernameValidator
  270. A field validator allowing only ASCII letters, in addition to ``@``, ``.``,
  271. ``+``, ``-``, and ``_``. The default validator for ``User.username`` on
  272. Python 2.
  273. .. class:: validators.UnicodeUsernameValidator
  274. A field validator allowing Unicode letters, in addition to ``@``, ``.``,
  275. ``+``, ``-``, and ``_``. The default validator for ``User.username`` on
  276. Python 3.
  277. .. _topics-auth-signals:
  278. Login and logout signals
  279. ========================
  280. .. module:: django.contrib.auth.signals
  281. The auth framework uses the following :doc:`signals </topics/signals>` that
  282. can be used for notification when a user logs in or out.
  283. .. function:: user_logged_in
  284. Sent when a user logs in successfully.
  285. Arguments sent with this signal:
  286. ``sender``
  287. The class of the user that just logged in.
  288. ``request``
  289. The current :class:`~django.http.HttpRequest` instance.
  290. ``user``
  291. The user instance that just logged in.
  292. .. function:: user_logged_out
  293. Sent when the logout method is called.
  294. ``sender``
  295. As above: the class of the user that just logged out or ``None``
  296. if the user was not authenticated.
  297. ``request``
  298. The current :class:`~django.http.HttpRequest` instance.
  299. ``user``
  300. The user instance that just logged out or ``None`` if the
  301. user was not authenticated.
  302. .. function:: user_login_failed
  303. Sent when the user failed to login successfully
  304. ``sender``
  305. The name of the module used for authentication.
  306. ``credentials``
  307. A dictionary of keyword arguments containing the user credentials that were
  308. passed to :func:`~django.contrib.auth.authenticate()` or your own custom
  309. authentication backend. Credentials matching a set of 'sensitive' patterns,
  310. (including password) will not be sent in the clear as part of the signal.
  311. ``request``
  312. The :class:`~django.http.HttpRequest` object, if one was provided to
  313. :func:`~django.contrib.auth.authenticate`.
  314. .. versionchanged:: 1.11
  315. The ``request`` argument was added.
  316. .. _authentication-backends-reference:
  317. Authentication backends
  318. =======================
  319. .. module:: django.contrib.auth.backends
  320. :synopsis: Django's built-in authentication backend classes.
  321. This section details the authentication backends that come with Django. For
  322. information on how to use them and how to write your own authentication
  323. backends, see the :ref:`Other authentication sources section
  324. <authentication-backends>` of the :doc:`User authentication guide
  325. </topics/auth/index>`.
  326. Available authentication backends
  327. ---------------------------------
  328. The following backends are available in :mod:`django.contrib.auth.backends`:
  329. .. class:: ModelBackend
  330. This is the default authentication backend used by Django. It
  331. authenticates using credentials consisting of a user identifier and
  332. password. For Django's default user model, the user identifier is the
  333. username, for custom user models it is the field specified by
  334. USERNAME_FIELD (see :doc:`Customizing Users and authentication
  335. </topics/auth/customizing>`).
  336. It also handles the default permissions model as defined for
  337. :class:`~django.contrib.auth.models.User` and
  338. :class:`~django.contrib.auth.models.PermissionsMixin`.
  339. :meth:`has_perm`, :meth:`get_all_permissions`, :meth:`get_user_permissions`,
  340. and :meth:`get_group_permissions` allow an object to be passed as a
  341. parameter for object-specific permissions, but this backend does not
  342. implement them other than returning an empty set of permissions if
  343. ``obj is not None``.
  344. .. method:: authenticate(request, username=None, password=None, **kwargs)
  345. Tries to authenticate ``username`` with ``password`` by calling
  346. :meth:`User.check_password
  347. <django.contrib.auth.models.User.check_password>`. If no ``username``
  348. is provided, it tries to fetch a username from ``kwargs`` using the
  349. key :attr:`CustomUser.USERNAME_FIELD
  350. <django.contrib.auth.models.CustomUser.USERNAME_FIELD>`. Returns an
  351. authenticated user or ``None``.
  352. ``request`` is an :class:`~django.http.HttpRequest` and may be ``None``
  353. if it wasn't provided to :func:`~django.contrib.auth.authenticate`
  354. (which passes it on to the backend).
  355. .. versionchanged:: 1.11
  356. The ``request`` argument was added.
  357. .. method:: get_user_permissions(user_obj, obj=None)
  358. Returns the set of permission strings the ``user_obj`` has from their
  359. own user permissions. Returns an empty set if
  360. :attr:`~django.contrib.auth.models.AbstractBaseUser.is_anonymous` or
  361. :attr:`~django.contrib.auth.models.CustomUser.is_active` is ``False``.
  362. .. method:: get_group_permissions(user_obj, obj=None)
  363. Returns the set of permission strings the ``user_obj`` has from the
  364. permissions of the groups they belong. Returns an empty set if
  365. :attr:`~django.contrib.auth.models.AbstractBaseUser.is_anonymous` or
  366. :attr:`~django.contrib.auth.models.CustomUser.is_active` is ``False``.
  367. .. method:: get_all_permissions(user_obj, obj=None)
  368. Returns the set of permission strings the ``user_obj`` has, including both
  369. user permissions and group permissions. Returns an empty set if
  370. :attr:`~django.contrib.auth.models.AbstractBaseUser.is_anonymous` or
  371. :attr:`~django.contrib.auth.models.CustomUser.is_active` is ``False``.
  372. .. method:: has_perm(user_obj, perm, obj=None)
  373. Uses :meth:`get_all_permissions` to check if ``user_obj`` has the
  374. permission string ``perm``. Returns ``False`` if the user is not
  375. :attr:`~django.contrib.auth.models.CustomUser.is_active`.
  376. .. method:: has_module_perms(self, user_obj, app_label)
  377. Returns whether the ``user_obj`` has any permissions on the app
  378. ``app_label``.
  379. .. method:: ModelBackend.user_can_authenticate()
  380. Returns whether the user is allowed to authenticate. To match the
  381. behavior of :class:`~django.contrib.auth.forms.AuthenticationForm`
  382. which :meth:`prohibits inactive users from logging in
  383. <django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed>`,
  384. this method returns ``False`` for users with :attr:`is_active=False
  385. <django.contrib.auth.models.User.is_active>`. Custom user models that
  386. don't have an :attr:`~django.contrib.auth.models.CustomUser.is_active`
  387. field are allowed.
  388. .. class:: AllowAllUsersModelBackend
  389. Same as :class:`ModelBackend` except that it doesn't reject inactive users
  390. because :meth:`~ModelBackend.user_can_authenticate` always returns ``True``.
  391. When using this backend, you'll likely want to customize the
  392. :class:`~django.contrib.auth.forms.AuthenticationForm` used by the
  393. :class:`~django.contrib.auth.views.LoginView` by overriding the
  394. :meth:`~django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed`
  395. method as it rejects inactive users.
  396. .. class:: RemoteUserBackend
  397. Use this backend to take advantage of external-to-Django-handled
  398. authentication. It authenticates using usernames passed in
  399. :attr:`request.META['REMOTE_USER'] <django.http.HttpRequest.META>`. See
  400. the :doc:`Authenticating against REMOTE_USER </howto/auth-remote-user>`
  401. documentation.
  402. If you need more control, you can create your own authentication backend
  403. that inherits from this class and override these attributes or methods:
  404. .. attribute:: RemoteUserBackend.create_unknown_user
  405. ``True`` or ``False``. Determines whether or not a user object is created
  406. if not already in the database Defaults to ``True``.
  407. .. method:: RemoteUserBackend.authenticate(request, remote_user)
  408. The username passed as ``remote_user`` is considered trusted. This method
  409. simply returns the user object with the given username, creating a new
  410. user object if :attr:`~RemoteUserBackend.create_unknown_user` is ``True``.
  411. Returns ``None`` if :attr:`~RemoteUserBackend.create_unknown_user` is
  412. ``False`` and a ``User`` object with the given username is not found in the
  413. database.
  414. ``request`` is an :class:`~django.http.HttpRequest` and may be ``None`` if
  415. it wasn't provided to :func:`~django.contrib.auth.authenticate` (which
  416. passes it on to the backend).
  417. .. method:: RemoteUserBackend.clean_username(username)
  418. Performs any cleaning on the ``username`` (e.g. stripping LDAP DN
  419. information) prior to using it to get or create a user object. Returns the
  420. cleaned username.
  421. .. method:: RemoteUserBackend.configure_user(user)
  422. Configures a newly created user. This method is called immediately after a
  423. new user is created, and can be used to perform custom setup actions, such
  424. as setting the user's groups based on attributes in an LDAP directory.
  425. Returns the user object.
  426. .. method:: RemoteUserBackend.user_can_authenticate()
  427. Returns whether the user is allowed to authenticate. This method returns
  428. ``False`` for users with :attr:`is_active=False
  429. <django.contrib.auth.models.User.is_active>`. Custom user models that don't
  430. have an :attr:`~django.contrib.auth.models.CustomUser.is_active` field are
  431. allowed.
  432. .. class:: AllowAllUsersRemoteUserBackend
  433. Same as :class:`RemoteUserBackend` except that it doesn't reject inactive
  434. users because :attr:`~RemoteUserBackend.user_can_authenticate` always
  435. returns ``True``.
  436. Utility functions
  437. =================
  438. .. currentmodule:: django.contrib.auth
  439. .. function:: get_user(request)
  440. Returns the user model instance associated with the given ``request``’s
  441. session.
  442. It checks if the authentication backend stored in the session is present in
  443. :setting:`AUTHENTICATION_BACKENDS`. If so, it uses the backend's
  444. ``get_user()`` method to retrieve the user model instance and then verifies
  445. the session by calling the user model's
  446. :meth:`~django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash`
  447. method.
  448. Returns an instance of :class:`~django.contrib.auth.models.AnonymousUser`
  449. if the authentication backend stored in the session is no longer in
  450. :setting:`AUTHENTICATION_BACKENDS`, if a user isn't returned by the
  451. backend's ``get_user()`` method, or if the session auth hash doesn't
  452. validate.