This commit is contained in:
j3d1 2026-08-27 02:51:30 +02:00
parent 6ee5ae38b1
commit 9685b4020e
11 changed files with 331 additions and 268 deletions

View file

@ -2,7 +2,7 @@ from nacl.exceptions import BadSignatureError
from nacl.signing import VerifyKey
from rest_framework import authentication
from authentication.models import KnownIdentity, ToolshedUser
from authentication.models import Group, KnownIdentity, ToolshedUser
def split_userhandle_or_throw(userhandle):
@ -22,6 +22,21 @@ def split_grouphandle_or_throw(grouphandle):
return split_userhandle_or_throw(grouphandle[1:])
def resolve_owner_handle(handle):
"""Resolves a "user@domain" or "+name@domain" handle to (owner_user, owner_group), exactly one set. Raises ValueError if the handle doesn't parse at all (no '@'); returns (None, None) if it parses but names nothing that exists."""
is_group = handle.startswith('+')
name, domain = split_userhandle_or_throw(handle[1:] if is_group else handle)
if is_group:
try:
return None, Group.objects.get(name=name, domain=domain)
except Group.DoesNotExist:
return None, None
try:
return ToolshedUser.objects.get(username=name, domain=domain), None
except ToolshedUser.DoesNotExist:
return None, None
def verify_request(request, raw_request_body):
authentication_header = request.META.get('HTTP_AUTHORIZATION')