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_userandget_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")
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_stateinvalid_statemissing_codecsrf_mismatchmissing_pkcetoken_exchange_failedcallback_upstream_failedtoken_not_yet_validtoken_validation_failedtoken_verification_unavailableuser_sync_failedcallback_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:
- Bump
versioninpyproject.toml. - Commit and push the change.
- Create a GitHub release.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ecc_auth-0.1.3.tar.gz.
File metadata
- Download URL: ecc_auth-0.1.3.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70a5f6ab06220bab54147389c126683270ee4f61d8ccfa469b467242bc05beb9
|
|
| MD5 |
a5065f0e2c2054008af1829a9aad6cef
|
|
| BLAKE2b-256 |
9d5990b56adc16378f74583ed2bc4b6675b98bc99a438e34a80e4aa49936abd8
|
Provenance
The following attestation bundles were made for ecc_auth-0.1.3.tar.gz:
Publisher:
publish-python.yml on early-chinese-civilization/ecc-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ecc_auth-0.1.3.tar.gz -
Subject digest:
70a5f6ab06220bab54147389c126683270ee4f61d8ccfa469b467242bc05beb9 - Sigstore transparency entry: 1396596585
- Sigstore integration time:
-
Permalink:
early-chinese-civilization/ecc-auth@b70d442040bd62cb97350e3ea3c77682f4108bd7 -
Branch / Tag:
refs/tags/dev-2 - Owner: https://github.com/early-chinese-civilization
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@b70d442040bd62cb97350e3ea3c77682f4108bd7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ecc_auth-0.1.3-py3-none-any.whl.
File metadata
- Download URL: ecc_auth-0.1.3-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fe921bb2cb106b6df80680ce6c46a91298b0a472fdb6ed6a7dd4d675d44fbf2
|
|
| MD5 |
186a6b360d4566a20fdfce1fcfa47c61
|
|
| BLAKE2b-256 |
3993a73f44d7147fdb2dbb852b6c2ee00dcefe9105cee97d22e7dc195ec9b01d
|
Provenance
The following attestation bundles were made for ecc_auth-0.1.3-py3-none-any.whl:
Publisher:
publish-python.yml on early-chinese-civilization/ecc-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ecc_auth-0.1.3-py3-none-any.whl -
Subject digest:
2fe921bb2cb106b6df80680ce6c46a91298b0a472fdb6ed6a7dd4d675d44fbf2 - Sigstore transparency entry: 1396596593
- Sigstore integration time:
-
Permalink:
early-chinese-civilization/ecc-auth@b70d442040bd62cb97350e3ea3c77682f4108bd7 -
Branch / Tag:
refs/tags/dev-2 - Owner: https://github.com/early-chinese-civilization
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@b70d442040bd62cb97350e3ea3c77682f4108bd7 -
Trigger Event:
release
-
Statement type: