Python (FastAPI + Authlib)
Authlib reads the discovery document and handles PKCE and ID token checks.
Register the app first: ask your agent, or create a web app in the dashboard with redirect URI http://localhost:8000/auth/callback.
Environment
SESSION_SECRETsigns the app's own session cookie; generate one withopenssl rand -base64 32..envYOURSELF_ISSUER=https://yourself.mees.sh YOURSELF_CLIENT_ID=app_… YOURSELF_CLIENT_SECRET=ysec_… (shown once when the app was created; rotate it if lost) YOURSELF_REDIRECT_URI=http://localhost:8000/auth/callback SESSION_SECRET=Install
shpip install fastapi uvicorn authlib httpx itsdangerousWire it up
main.pyimport os from fastapi import FastAPI, Request from fastapi.responses import RedirectResponse from starlette.middleware.sessions import SessionMiddleware from authlib.integrations.starlette_client import OAuth app = FastAPI() app.add_middleware(SessionMiddleware, secret_key=os.environ["SESSION_SECRET"], same_site="lax") oauth = OAuth() oauth.register( name="yourself", server_metadata_url=f"{os.environ['YOURSELF_ISSUER']}/.well-known/openid-configuration", client_id=os.environ["YOURSELF_CLIENT_ID"], client_secret=os.environ["YOURSELF_CLIENT_SECRET"], client_kwargs={"scope": "openid profile email", "code_challenge_method": "S256"}, ) @app.get("/auth/login") async def login(request: Request): return await oauth.yourself.authorize_redirect(request, os.environ["YOURSELF_REDIRECT_URI"]) @app.get("/auth/callback") async def callback(request: Request): token = await oauth.yourself.authorize_access_token(request) request.session["user"] = dict(token["userinfo"]) return RedirectResponse("/") @app.post("/auth/logout") async def logout(request: Request): request.session.clear() return RedirectResponse("/", status_code=303) @app.get("/") async def home(request: Request): user = request.session.get("user") if not user: return RedirectResponse("/auth/login") return {"hello": user.get("name")}Check it works
Start the app and open it. You're sent to yourself, sign in with your passkey, and land back in the app signed in. The
list_activityMCP tool (or the dashboard) shows anapp.signed_inevent.