Use chargepoint identity for basic auth to be spec compliant

This commit is contained in:
Oliver Traber 2024-04-14 23:23:51 +02:00
parent 38d3064652
commit 6f998a3c58
Signed by: Bluemedia
GPG key ID: C0674B105057136C

View file

@ -1,6 +1,5 @@
import base64 import base64
import binascii import binascii
from uuid import UUID
from starlette.authentication import ( from starlette.authentication import (
AuthCredentials, AuthenticationBackend, AuthenticationError, SimpleUser AuthCredentials, AuthenticationBackend, AuthenticationError, SimpleUser
) )
@ -23,13 +22,9 @@ class BasicAuthBackend(AuthenticationBackend):
raise AuthenticationError('Invalid basic auth credentials') raise AuthenticationError('Invalid basic auth credentials')
username, _, password = decoded.partition(":") username, _, password = decoded.partition(":")
try:
id = UUID(username)
except (ValueError) as exc:
raise AuthenticationError('Invalid basic auth credentials')
with SessionLocal() as db: with SessionLocal() as db:
chargepoint = db.query(ChargePoint).filter(ChargePoint.id == id).first() chargepoint = db.query(ChargePoint).filter(ChargePoint.friendly_name == username).first()
if chargepoint is None: if chargepoint is None:
raise AuthenticationError('Invalid basic auth credentials') raise AuthenticationError('Invalid basic auth credentials')
if chargepoint.password != password: if chargepoint.password != password: