Shared JWT + Google OAuth auth middleware for pal-e platform services
Find a file
forgejo_admin 20a6dd1b84
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci: remove old .woodpecker.yaml (replaced by .woodpecker.yml)
2026-03-01 17:47:05 +00:00
src/pal_e_auth feat: add Woodpecker CI pipeline and update ruff config (#8) 2026-03-01 17:32:13 +00:00
tests Scaffold pal-e-auth shared library (#1) (#4) 2026-02-23 22:01:46 +00:00
.gitignore Scaffold pal-e-auth shared library (#1) (#4) 2026-02-23 22:01:46 +00:00
.woodpecker.yml ci: add header comment to trigger pipeline 2026-03-01 17:45:25 +00:00
CLAUDE.md Scaffold pal-e-auth shared library (#1) (#4) 2026-02-23 22:01:46 +00:00
poetry.lock Scaffold pal-e-auth shared library (#1) (#4) 2026-02-23 22:01:46 +00:00
pyproject.toml feat: add Woodpecker CI pipeline and update ruff config (#8) 2026-03-01 17:32:13 +00:00
README.md Scaffold pal-e-auth shared library (#1) (#4) 2026-02-23 22:01:46 +00:00

pal-e-auth

Shared JWT + Google OAuth auth middleware for pal-e platform services.

Install

pip install pal-e-auth-ldraney

Quick Start

from fastapi import FastAPI, Depends
from pal_e_auth import AuthConfig, auth_router, get_current_user, require_role, User

app = FastAPI()

config = AuthConfig(
    secret_key="your-jwt-secret",
    google_client_id="your-google-client-id",
    google_client_secret="your-google-client-secret",
)
app.state.auth_config = config
app.include_router(auth_router(config))

@app.get("/protected")
async def protected(user: User = Depends(get_current_user)):
    return {"email": user.email}

@app.get("/admin-only")
async def admin_only(user: User = Depends(require_role("admin"))):
    return {"email": user.email}

Auth Flow

  1. User visits /auth/google → redirected to Google consent screen
  2. Google redirects back to /auth/callback with auth code
  3. Server exchanges code for ID token, extracts user info
  4. JWT created and set as access_token cookie
  5. Subsequent requests authenticated via cookie or Authorization: Bearer header

Dependencies

FastAPI apps provide auth by reading app.state.auth_config:

  • get_current_user — requires valid JWT, returns User
  • optional_user — returns User | None
  • require_role("admin", "coach") — requires valid JWT + matching role

Roles

admin, coach, parent, viewer (default)

Development

poetry install
poetry run pytest
poetry run ruff check .
poetry run ruff format --check .