Integrate GitHat authentication into FastAPI apps. JWT validation, dependency injection auth guards, and async token management for Python APIs.
Add enterprise-grade auth to FastAPI with GitHat's REST API. Use async HTTP calls to validate tokens, check org membership, and enforce role-based access on every request.
Build a reusable auth dependency: extract the Bearer token, validate it with GitHat, and return the user context. Apply it to any endpoint with Depends(get_current_user).
FastAPI is async-first. Use httpx.AsyncClient to validate tokens against GitHat without blocking the event loop. The /auth/me endpoint returns user + org context in one call.
pip install fastapi httpx uvicorn
# main.py
from fastapi import FastAPI, Depends, HTTPException, Header
import httpx
app = FastAPI()
GITHAT_API = 'https://api.githat.io'
async def get_current_user(authorization: str = Header()):
async with httpx.AsyncClient() as client:
resp = await client.get(f'{GITHAT_API}/auth/me',
headers={'Authorization': authorization})
if resp.status_code != 200:
raise HTTPException(status_code=401)
return resp.json()
@app.get('/api/profile')
async def profile(user=Depends(get_current_user)):
return user
Try GitHat free
Ship authenticated apps in minutes, not weeks.