Commit d43ac93d authored by Dimitrios Gogos's avatar Dimitrios Gogos
Browse files

feat: add support for disabling authorization in API endpoints

parent d6a0e9eb
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for ai_agent/README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ MEMORY_KEY_PREFIX=ai_agent:session
| `MEMORY_WINDOW_TURNS` | Number of recent user/assistant turns to retain |
| `MEMORY_TTL_SECONDS` | Session memory TTL in seconds |
| `MEMORY_KEY_PREFIX` | Prefix for Redis session keys |
| `AUTH_ENABLED` | `false` accepts requests without a bearer token, for platforms deployed without login (default `true`) |

---

+2 −2
Changes for ai_agent/routes/groq.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ memory_store = RedisShortTermMemory()

@router.post("/groq-mcp")
async def groq_query(
    authorization: Annotated[str, Depends(get_authorization)],
    authorization: Annotated[str | None, Depends(get_authorization)],
    payload: Annotated[dict | None, Body()] = None,
):
    query = payload.get("query") if payload else None
@@ -44,7 +44,7 @@ async def groq_query(

@router.get("/groq-mcp/stream")
async def groq_stream(
    authorization: Annotated[str, Depends(get_authorization)],
    authorization: Annotated[str | None, Depends(get_authorization)],
    query: str | None = Query(default=None),
    session_id: str | None = Query(default=None),
):
+5 −1
Changes for ai_agent/security.py: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
import os
from typing import Annotated

from fastapi import Header, HTTPException
@@ -5,12 +6,15 @@ from fastapi import Header, HTTPException

def get_authorization(
    authorization: Annotated[str | None, Header()] = None,
) -> str:
) -> str | None:
    if authorization is not None:
        scheme, _, token = authorization.partition(" ")
        if scheme.lower() == "bearer" and token.strip():
            return f"Bearer {token.strip()}"

    if os.getenv("AUTH_ENABLED", "true").strip().lower() == "false":
        return None

    raise HTTPException(
        status_code=401,
        detail="Bearer token required",
+6 −6
Changes for ai_agent/sub_agents/groq_agent.py: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ def require_env(name: str) -> str:
    return value.strip()


async def create_groq_agent(authorization: str):
async def create_groq_agent(authorization: str | None):
    """Create an MCPAgent using Groq backend."""
    try:
        mcp_server_url = require_env("MCP_SERVER_URL")
@@ -40,13 +40,13 @@ async def create_groq_agent(authorization: str):
            "mcpServers": {
                "http": {
                    "url": mcp_server_url,
                    "headers": {
                        "Authorization": authorization,
                    },
                    "headers": (
                        {"Authorization": authorization} if authorization else {}
                    ),
                    # mcp_use's default ({}) runs OAuth discovery on every connect.
                    "auth": None,
                }
            },
            "use-oauth2": False,
            "use-oidc": False,
        }
    )
    await client.create_session("http")
+2 −0
Changes for mcp_module/README.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ Create a `.env` file in the project root (if not already present) and set your A
OEG_SERVICE_URL=http://your-oeg-host
MCP_HOST=127.0.0.1
MCP_PORT=8004
# false calls OEG without a bearer token when the caller sends none (platform without login)
AUTH_ENABLED=true
```


Loading