diff --git a/agixt/ApiClient.py b/agixt/ApiClient.py index 7e77ca8be8c7..f9c78f8f2a88 100644 --- a/agixt/ApiClient.py +++ b/agixt/ApiClient.py @@ -26,22 +26,20 @@ def verify_api_key(authorization: str = Header(None)): authorization = str(authorization).replace("Bearer ", "").replace("bearer ", "") if DEFAULT_USER == "" or DEFAULT_USER is None or DEFAULT_USER == "None": DEFAULT_USER = "user" - if getenv("AUTH_PROVIDER") == "magicalauth": - auth_key = AGIXT_API_KEY + str(datetime.now().strftime("%Y%m%d")) - try: - token = jwt.decode( - jwt=authorization, - key=auth_key, - algorithms=["HS256"], - leeway=timedelta(hours=5), - ) - return token["email"] - except Exception as e: - if authorization == auth_key: - return DEFAULT_USER - if authorization != AGIXT_API_KEY: - logging.info(f"Invalid API Key: {authorization}") - raise HTTPException(status_code=401, detail="Invalid API Key") + try: + token = jwt.decode( + jwt=authorization, + key=AGIXT_API_KEY, + algorithms=["HS256"], + leeway=timedelta(hours=5), + ) + return token["email"] + except Exception as e: + if authorization == AGIXT_API_KEY: + return DEFAULT_USER + if authorization != AGIXT_API_KEY: + logging.info(f"Invalid API Key: {authorization}") + raise HTTPException(status_code=401, detail="Invalid API Key") if AGIXT_API_KEY: if authorization is None: logging.info("Authorization header is missing") diff --git a/agixt/Globals.py b/agixt/Globals.py index a194bb39cd35..f9b2daa3927d 100644 --- a/agixt/Globals.py +++ b/agixt/Globals.py @@ -33,7 +33,6 @@ def getenv(var_name: str): "DISABLED_EXTENSIONS": "", "DISABLED_PROVIDERS": "", "REGISTRATION_DISABLED": "false", - "AUTH_PROVIDER": "magicalauth", "CREATE_AGENT_ON_REGISTER": "true", "CREATE_AGIXT_AGENT": "true", } diff --git a/agixt/MagicalAuth.py b/agixt/MagicalAuth.py index ad5ea4472d6e..4ba63ec55035 100644 --- a/agixt/MagicalAuth.py +++ b/agixt/MagicalAuth.py @@ -134,8 +134,6 @@ def urldecode(data: str): def verify_api_key(authorization: str = Header(None)): AGIXT_API_KEY = getenv("AGIXT_API_KEY") - if getenv("AUTH_PROVIDER") == "magicalauth": - AGIXT_API_KEY = f'{AGIXT_API_KEY}{datetime.now().strftime("%Y%m%d")}' authorization = str(authorization).replace("Bearer ", "").replace("bearer ", "") if AGIXT_API_KEY: if authorization is None: @@ -167,7 +165,6 @@ def verify_api_key(authorization: str = Header(None)): def impersonate_user(user_id: str): AGIXT_API_KEY = getenv("AGIXT_API_KEY") - AGIXT_API_KEY = f'{AGIXT_API_KEY}{datetime.now().strftime("%Y%m%d")}' # Get users email session = get_session() user = session.query(User).filter(User.id == user_id).first() @@ -289,9 +286,8 @@ def decrypt(key: str, data: str): class MagicalAuth: def __init__(self, token: str = None): - encryption_key = getenv("AGIXT_API_KEY") + self.encryption_key = getenv("AGIXT_API_KEY") self.link = getenv("MAGIC_LINK_URL") - self.encryption_key = f'{encryption_key}{datetime.now().strftime("%Y%m%d")}' token = ( str(token) .replace("%2B", "+") @@ -341,7 +337,7 @@ def __init__(self, token: str = None): self.email = None self.token = None self.user_id = None - if token == encryption_key: + if token == self.encryption_key: self.email = getenv("DEFAULT_USER") self.user_id = get_user_id(self.email) self.token = token diff --git a/agixt/Memories.py b/agixt/Memories.py index 53c7a8b902ff..18c6ca6132a0 100644 --- a/agixt/Memories.py +++ b/agixt/Memories.py @@ -86,24 +86,28 @@ def query_results_to_records(results: "QueryResult"): results[k] = [v] except IndexError: return [] - memory_records = [ - { - "external_source_name": metadata.get("external_source_name", "user input"), - "id": metadata["id"], - "description": metadata["description"], - "text": document, - "embedding": embedding, - "additional_metadata": metadata["additional_metadata"], - "key": id, - "timestamp": metadata["timestamp"], - } - for id, document, embedding, metadata in zip( - results["ids"][0], - results["documents"][0], - results["embeddings"][0], - results["metadatas"][0], - ) - ] + memory_records = [] + for id, document, embedding, metadata in zip( + results["ids"][0], + results["documents"][0], + results["embeddings"][0], + results["metadatas"][0], + ): + if metadata: + memory_records.append( + { + "external_source_name": metadata.get( + "external_source_name", "user input" + ), + "id": metadata["id"], + "description": metadata["description"], + "text": document, + "embedding": embedding, + "additional_metadata": metadata["additional_metadata"], + "key": id, + "timestamp": metadata["timestamp"], + } + ) return memory_records diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index fc4429e78848..e51d88999c21 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -8,7 +8,6 @@ services: UVICORN_WORKERS: ${UVICORN_WORKERS:-10} AGIXT_API_KEY: ${AGIXT_API_KEY:-None} AGIXT_URI: ${AGIXT_URI:-http://agixt:7437} - AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth} MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user} DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS} DISABLED_PROVIDERS: ${DISABLED_PROVIDERS} diff --git a/docker-compose-nostreamlit-dev.yml b/docker-compose-nostreamlit-dev.yml index 173b01967f71..541beac3f66b 100644 --- a/docker-compose-nostreamlit-dev.yml +++ b/docker-compose-nostreamlit-dev.yml @@ -8,7 +8,6 @@ services: UVICORN_WORKERS: ${UVICORN_WORKERS:-10} AGIXT_API_KEY: ${AGIXT_API_KEY:-None} AGIXT_URI: ${AGIXT_URI:-http://agixt:7437} - AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth} MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user} DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS} DISABLED_PROVIDERS: ${DISABLED_PROVIDERS} diff --git a/docker-compose-nostreamlit.yml b/docker-compose-nostreamlit.yml index 9822ec7f344d..7846672b9a9e 100644 --- a/docker-compose-nostreamlit.yml +++ b/docker-compose-nostreamlit.yml @@ -8,7 +8,6 @@ services: UVICORN_WORKERS: ${UVICORN_WORKERS:-10} AGIXT_API_KEY: ${AGIXT_API_KEY:-None} AGIXT_URI: ${AGIXT_URI:-http://agixt:7437} - AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth} MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user} DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS} DISABLED_PROVIDERS: ${DISABLED_PROVIDERS} diff --git a/docker-compose.yml b/docker-compose.yml index 7edf4722da05..a4c3a6d34c07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,6 @@ services: UVICORN_WORKERS: ${UVICORN_WORKERS:-10} AGIXT_API_KEY: ${AGIXT_API_KEY:-None} AGIXT_URI: ${AGIXT_URI:-http://agixt:7437} - AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth} MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user} DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS} DISABLED_PROVIDERS: ${DISABLED_PROVIDERS} diff --git a/start.py b/start.py index 90e866c54edc..3e79f6445951 100644 --- a/start.py +++ b/start.py @@ -194,7 +194,6 @@ def get_default_env_vars(): "APP_URI": "http://localhost:3437", "STREAMLIT_APP_URI": "http://localhost:8501", "AUTH_WEB": "http://localhost:3437/user", - "AUTH_PROVIDER": "magicalauth", "CREATE_AGENT_ON_REGISTER": "true", "CREATE_AGIXT_AGENT": "true", "DISABLED_PROVIDERS": "",