Skip to content

Commit

Permalink
Run hatch fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormheg committed Jul 18, 2024
1 parent 0169de8 commit 818b739
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/django_otp_webauthn/backends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any

from django.contrib.auth import get_user_model
from django.contrib.auth.base_user import AbstractBaseUser
from django.http import HttpRequest
Expand All @@ -7,22 +8,25 @@

UserModel = get_user_model()


class WebAuthnBackend:
"""A simple authentication backend used when django_otp_webauthn is used for passwordless authentication."""

def authenticate(self, request: HttpRequest, webauthn_credential: AbstractWebAuthnCredential | None = None, **kwargs: Any) -> AbstractBaseUser | None:
def authenticate(
self, request: HttpRequest, webauthn_credential: AbstractWebAuthnCredential | None = None, **kwargs: Any
) -> AbstractBaseUser | None:
if webauthn_credential:
user = webauthn_credential.user
return user if self.user_can_authenticate(user) else None
return None

def get_user(self, user_id) -> AbstractBaseUser | None:
try:
user = UserModel._default_manager.get(pk=user_id)
except UserModel.DoesNotExist:
return None
return user if self.user_can_authenticate(user) else None

def user_can_authenticate(self, user: AbstractBaseUser | None) -> bool:
"""
Reject users with is_active=False. Custom user models that don't have
Expand Down
4 changes: 2 additions & 2 deletions src/django_otp_webauthn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_exempt_urls() -> list:
]


def get_credential_model() -> "AbstractWebAuthnCredential":
def get_credential_model() -> AbstractWebAuthnCredential:
"""Returns the WebAuthnCredential model that is active in this project."""
# Inspired by Django's django.contrib.auth.get_user_model
try:
Expand All @@ -114,7 +114,7 @@ def get_credential_model() -> "AbstractWebAuthnCredential":
)


def get_attestation_model() -> "AbstractWebAuthnAttestation":
def get_attestation_model() -> AbstractWebAuthnAttestation:
"""Returns the WebAuthnAttestation model that is active in this project."""
# Inspired by Django's django.contrib.auth.get_user_model
try:
Expand Down

0 comments on commit 818b739

Please sign in to comment.