mirror of
https://github.com/cpacker/MemGPT.git
synced 2025-06-03 04:30:22 +00:00

Co-authored-by: Charles Packer <packercharles@gmail.com> Co-authored-by: Shubham Naik <shubham.naik10@gmail.com> Co-authored-by: Shubham Naik <shub@memgpt.ai>
23 lines
774 B
Python
23 lines
774 B
Python
import uuid
|
|
|
|
from fastapi import Depends, HTTPException
|
|
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
|
|
|
from letta.server.server import SyncServer
|
|
|
|
security = HTTPBearer()
|
|
|
|
|
|
def get_current_user(server: SyncServer, password: str, auth: HTTPAuthorizationCredentials = Depends(security)) -> uuid.UUID:
|
|
try:
|
|
api_key_or_password = auth.credentials
|
|
if api_key_or_password == password:
|
|
# user is admin so we just return the default uuid
|
|
return server.authenticate_user()
|
|
user_id = server.api_key_to_user(api_key=api_key_or_password)
|
|
return user_id
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(status_code=403, detail=f"Authentication error: {e}")
|