Skip to main content

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

Project description

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 .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pal_e_auth_ldraney-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pal_e_auth_ldraney-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pal_e_auth_ldraney-0.1.0.tar.gz.

File metadata

  • Download URL: pal_e_auth_ldraney-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pal_e_auth_ldraney-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0014365418b0db7010d89dbfc658e3ed2a9369bace04eff4e718992b4e0d1aa
MD5 33c940e9f7cd1212c86c7a9e27a4c313
BLAKE2b-256 d27b18419d9bd69aff587a352e9e21e0fa92ff913346f17b8573a80f44435d71

See more details on using hashes here.

File details

Details for the file pal_e_auth_ldraney-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pal_e_auth_ldraney-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d07afe731aa8703edd839ccd4e1247c8f6d631ac650b2883266592f15767276a
MD5 6a8ae5832b204d9dcae12d9a229373f3
BLAKE2b-256 8154c63eb58ae5e33de274c89ecf56b2c7756bc58a3d9831699097dd6639154b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page