Skip to main content

Shared Keycloak OIDC authentication SDK for ECC projects

Project description

ecc-auth

ecc-auth is a small shared authentication SDK for ECC Python services that integrate with Keycloak and FastAPI.

It provides:

  • Keycloak configuration via KeycloakConfig
  • Standard FastAPI auth routes via create_auth_router
  • Current-user dependencies via get_current_user and get_current_user_optional
  • JWT verification helpers via verify_access_token

Installation

Once published to PyPI:

pip install ecc-auth

Or with uv:

uv add ecc-auth

Quick Start

from fastapi import FastAPI

from ecc_auth import AuthSessionMiddleware, KeycloakConfig, create_auth_router, init_dependencies

app = FastAPI()
app.add_middleware(AuthSessionMiddleware)

config = KeycloakConfig(
    url="https://keycloak.example.com",
    realm="ecc",
    client_id="example-client",
    client_secret="example-secret",
    tls_insecure=False,
)

init_dependencies(config)
app.include_router(create_auth_router(config), prefix="/api/auth")

For apps served under a public sub-path, pass that path to the router so Keycloak receives the externally reachable callback URL:

app.include_router(
    create_auth_router(config, public_base_path="/deer-flow"),
    prefix="/api/auth",
)

Development

This repository is a single Python package repository. The package root, tests, and release metadata all live at the repository root.

Build the package locally:

uv build

Run tests:

uv run pytest

Callback Error Contract

When /api/auth/callback cannot complete, ecc-auth redirects back to the app origin with a stable ?error=<code> query parameter.

Current callback error codes:

  • missing_state
  • invalid_state
  • missing_code
  • csrf_mismatch
  • missing_pkce
  • token_exchange_failed
  • callback_upstream_failed
  • token_not_yet_valid
  • token_validation_failed
  • token_verification_unavailable
  • user_sync_failed
  • callback_failed

Consumer apps should map these codes to user-facing copy instead of exposing raw exception text.

Publishing

This repository includes a GitHub Actions workflow at .github/workflows/publish-python.yml.

Recommended release flow:

  1. Bump version in pyproject.toml.
  2. Commit and push the change.
  3. Create a GitHub release.
  4. Let the workflow build and publish the package to PyPI.

Before the first release, configure a Trusted Publisher for this repository in PyPI and point it at:

  • Repository owner: early-chinese-civilization
  • Repository name: ecc-auth
  • Workflow file: .github/workflows/publish-python.yml
  • Environment name: pypi

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

ecc_auth-0.1.4.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

ecc_auth-0.1.4-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file ecc_auth-0.1.4.tar.gz.

File metadata

  • Download URL: ecc_auth-0.1.4.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ecc_auth-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0f74f5e3d0c2100d900d3c7c79c86576421f90035fbb6bd474e531b420c38be3
MD5 1b4bcc3f26563574cb2ae745d3683673
BLAKE2b-256 c2b5198dc34b1e14c519f5cc34a354703a9a1f53dbd97eaee1f22c397827adaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for ecc_auth-0.1.4.tar.gz:

Publisher: publish-python.yml on early-chinese-civilization/ecc-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ecc_auth-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ecc_auth-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ecc_auth-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa04bf227d66b6db63e75b68b01e87e1ce900213a0918b6e21de2bf84db21d9
MD5 b0666a9b3b7696f5aceee4653fcd6a3c
BLAKE2b-256 92a8b798bbfaf3b525a223e13aa8dd8a77073ac4fa606d7eaf3cb4f79dadc327

See more details on using hashes here.

Provenance

The following attestation bundles were made for ecc_auth-0.1.4-py3-none-any.whl:

Publisher: publish-python.yml on early-chinese-civilization/ecc-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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