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.

  1. Environment

    SESSION_SECRET signs the app's own session cookie; generate one with openssl rand -base64 32.

    .env
    YOURSELF_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=
  2. Install

    sh
    pip install fastapi uvicorn authlib httpx itsdangerous
  3. Wire it up

    main.py
    import 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")}
  4. 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_activity MCP tool (or the dashboard) shows an app.signed_in event.