{"id":27732,"library":"fastapi-clerk-auth","title":"FastAPI Clerk Auth","description":"FastAPI middleware for Clerk authentication. Version 0.0.9 released 2025-01-30. Supports JWT verification, RS256, and request state. Active development, weekly releases.","status":"active","version":"0.0.9","language":"python","source_language":"en","source_url":"https://github.com/OSSMafia/fastapi-clerk-middleware","tags":["fastapi","clerk","authentication","jwt","middleware"],"install":[{"cmd":"pip install fastapi-clerk-auth","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Required as the web framework","package":"fastapi","optional":false},{"reason":"For JWT decoding and verification","package":"PyJWT","optional":false},{"reason":"Required by PyJWT for RS256 algorithm","package":"cryptography","optional":false}],"imports":[{"note":"Module structure requires explicit middleware import","wrong":"from fastapi_clerk_auth import ClerkAuthMiddleware","symbol":"ClerkAuthMiddleware","correct":"from fastapi_clerk_auth.middleware import ClerkAuthMiddleware"},{"note":"Config class resides in config module","wrong":"from fastapi_clerk_auth import ClerkConfig","symbol":"ClerkConfig","correct":"from fastapi_clerk_auth.config import ClerkConfig"},{"note":"","wrong":"","symbol":"ClerkClaims","correct":"from fastapi_clerk_auth.claims import ClerkClaims"}],"quickstart":{"code":"from fastapi import FastAPI, Request\nfrom fastapi_clerk_auth.middleware import ClerkAuthMiddleware\nfrom fastapi_clerk_auth.config import ClerkConfig\n\napp = FastAPI()\n\nclerk_config = ClerkConfig(\n    api_key=\"your_api_key\",  # Or set env CLERK_API_KEY\n    issuer=\"https://your-issuer.clerk.accounts.dev\",\n)\napp.add_middleware(ClerkAuthMiddleware, config=clerk_config)\n\n@app.get(\"/protected\")\nasync def protected(request: Request):\n    return {\"user\": request.state.clerk_auth}\n","lang":"python","description":"Protect a FastAPI route with Clerk JWT authentication. The decoded token is available via request.state.clerk_auth."},"warnings":[{"fix":"Add verify_iat=False to ClerkConfig if needed.","message":"In v0.0.7, the config attribute 'verify_iat' was added; default is True. If you previously relied on skipping iat verification, you must now set verify_iat=False explicitly.","severity":"breaking","affected_versions":">=0.0.9"},{"fix":"Use float values for leeway, e.g., leeway=5.0.","message":"The 'leeway' parameter in ClerkConfig is now of type float (v0.0.8). Passing an integer will not break code but may cause type warnings.","severity":"deprecated","affected_versions":">=0.0.8"},{"fix":"Ensure issuer ends with '.clerk.accounts.dev' (no trailing slash) and use the API key, not a JWT template secret.","message":"The issuer URL must exactly match the one from your Clerk instance, including trailing slash? No, but https is required. Also the API key must be from Clerk's 'API Keys' section, not the secret key from JWT templates.","severity":"gotcha","affected_versions":"all"},{"fix":"Install cryptography: pip install cryptography","message":"If you use RS256 (default), you must have the 'cryptography' library installed. The middleware does not install it as a hard dependency, so missing it will raise an ImportError.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use: from fastapi_clerk_auth.middleware import ClerkAuthMiddleware","cause":"Wrong import path; the middleware is in a submodule.","error":"ImportError: cannot import name 'ClerkAuthMiddleware' from 'fastapi_clerk_auth'"},{"fix":"Copy the exact issuer from your Clerk dashboard (e.g., https://your-app.clerk.accounts.dev) and ensure no trailing slash.","cause":"The issuer URL provided does not match the issuer in the JWT token.","error":"jwt.exceptions.InvalidIssuerError: Invalid issuer"},{"fix":"pip install cryptography","cause":"Missing dependency for RS256 JWT decoding.","error":"ModuleNotFoundError: No module named 'cryptography'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}