Replies: 1 comment 4 replies
-
RESOLUTION: Microsoft Agents SDK (Agents-for-python) + FastAPI + AuthorizationDiscussion: #400 WHAT IS HAPPENINGDiscussion #400 has no official response from Microsoft yet (opened May 19, 2026). The core issue: the JWT authorization middleware pattern differs between aiohttp ROOT CAUSEThe SDK exposes two separate hosting modules: from microsoft_agents.hosting.aiohttp import start_agent_process # mature For aiohttp, authorization is enabled by passing jwt_authorization_middleware from microsoft_agents.hosting.aiohttp import ( There is no equivalent jwt_authorization_middleware exported for FastAPI yet, SOLUTIONSOPTION 1 — Use fastapi-microsoft-identity (recommended for production)pip install fastapi-microsoft-identity from fastapi import FastAPI, Request initialize(tenant_id="YOUR_TENANT_ID", client_id="YOUR_CLIENT_ID") app = FastAPI() @app.post("/api/messages") This library validates JWT tokens against Azure AD and throws HTTP 401/403 OPTION 2 — Manual JWT middleware in FastAPIfrom fastapi import FastAPI, Request, HTTPException class BotAuthMiddleware(BaseHTTPMiddleware): app = FastAPI() @app.post("/api/messages") NOTE: In practice, the CloudAdapter inside the SDK already validates the OPTION 3 — Minimal working FastAPI setup (no extra middleware)from fastapi import FastAPI, Request app = FastAPI() @app.get("/api/messages") @app.post("/api/messages") if name == "main": INSTALL DEPENDENCIES (from source, for latest fixes)pip install -e libraries/microsoft-agents-hosting-fastapi RECOMMENDATIONS
USEFUL LINKS
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It seems like the samples for FastAPI is not working? Does any managed to make the Agents SDK work with FastAPI with Authorization enabled?
Beta Was this translation helpful? Give feedback.
All reactions