Skip to content

Commit

Permalink
Add AxesStandaloneBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
jcgiuffrida authored and aleksihakli committed Jul 17, 2022
1 parent ca32979 commit 5c4bca6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions axes/backends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from django.conf import settings
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.backends import BaseBackend, ModelBackend
from django.http import HttpRequest

from axes.exceptions import (
Expand All @@ -11,14 +11,15 @@
from axes.helpers import get_credentials, get_lockout_message, toggleable


class AxesBackend(ModelBackend):
class AxesStandaloneBackend(BaseBackend):
"""
Authentication backend class that forbids login attempts for locked out users.
Use this class as the first item of ``AUTHENTICATION_BACKENDS`` to
prevent locked out users from being logged in by the Django authentication flow.
.. note:: This backend does not log your user in. It monitors login attempts.
It also does not run any permissions checks at all.
Authentication is handled by the following backends that are configured in ``AUTHENTICATION_BACKENDS``.
"""

Expand Down Expand Up @@ -71,3 +72,16 @@ def authenticate(
raise AxesBackendPermissionDenied(
"AxesBackend detected that the given user is locked out"
)


class AxesBackend(AxesStandaloneBackend, ModelBackend):
"""
Axes authentication backend that also inherits from ModelBackend,
and thus also performs other functions of ModelBackend such as permissions checks.
Use this class as the first item of ``AUTHENTICATION_BACKENDS`` to
prevent locked out users from being logged in by the Django authentication flow.
.. note:: This backend does not log your user in. It monitors login attempts.
Authentication is handled by the following backends that are configured in ``AUTHENTICATION_BACKENDS``.
"""

0 comments on commit 5c4bca6

Please sign in to comment.