ecc-auth
ecc-auth is a small shared authentication SDK for ECC Python services that use
星河 OAuth2 authorization-code login with FastAPI.
Version 0.2.0 is a breaking Xinghe-only release. It implements only the
current Xinghe browser login and session model.
It provides:
- 星河 OAuth2 configuration via
XingheOAuthConfig - Standard FastAPI auth routes via
create_auth_router - Current-user dependencies via
get_current_userandget_current_user_optional - Server-side session refresh through Xinghe refreshToken
- User identity validation through Xinghe userInfo
- Xinghe identity normalization for
userId,name,tel,email,organization, andavatarUrl
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,
XingheOAuthConfig,
create_auth_router,
init_dependencies,
)
app = FastAPI()
app.add_middleware(AuthSessionMiddleware)
config = XingheOAuthConfig(
base_url="https://staging-aistudio.ai4s.infly.tech/partner/sso/auth-center",
client_id="auth-server-zhwm",
client_secret="inject-from-secret-manager",
redirect_uri="http://localhost:2026/api/auth/callback",
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 the generated callback and post-login URLs match the externally reachable app:
app.include_router(
create_auth_router(config, public_base_path="/deer-flow"),
prefix="/api/auth",
)
Environment
XingheOAuthConfig() reads these environment variables by default:
XINGHE_OAUTH_BASE_URLXINGHE_OAUTH_CLIENT_IDXINGHE_OAUTH_CLIENT_SECRETXINGHE_OAUTH_REDIRECT_URI(optional)XINGHE_OAUTH_AUTHORIZE_PATH(optional)XINGHE_OAUTH_TOKEN_PATH(optional)XINGHE_OAUTH_REFRESH_PATH(optional)XINGHE_OAUTH_USERINFO_PATH(optional)XINGHE_OAUTH_TOKEN_CLIENT_AUTH_METHOD(optional, defaultbasic)XINGHE_OAUTH_REFRESH_CLIENT_AUTH_METHOD(optional, defaultbody)XINGHE_OAUTH_SCOPE(optional)XINGHE_OAUTH_FORCE_LOGIN_PARAMS(optional)XINGHE_OAUTH_TLS_INSECURE(optional, defaultfalse)
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_mismatchauthorization_failedtoken_exchange_failedcallback_upstream_failedtoken_validation_faileduserinfo_unavailableuser_sync_failedcallback_failed
Consumer apps should map these codes to user-facing copy instead of exposing raw exception text.
Development
Build the package locally:
uv build
Run tests:
uv run pytest
Publishing
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.
Metadata
Release files for ecc-auth 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ecc_auth-0.2.0.tar.gz | 18.3 kB | With provenance | Details for ecc_auth-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ecc_auth-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ecc_auth-0.2.0-py3-none-any.whl |
Total release size: 36.4 kB
Release files / ecc_auth-0.2.0.tar.gz
| Download URL | ecc_auth-0.2.0.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8a9254a552a15b0e456bca7cdd80c9b878703b17a4504f4e69ab762cc57a22e
|
|
BLAKE2b-256 checksum How to use checksums |
d34f852a314f5d2bea33e2067a574c5d927f42e71aefb79dc1d7240fe4b95a13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 18, 2026.
Transparency logRelease files / ecc_auth-0.2.0-py3-none-any.whl
| Download URL | ecc_auth-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57a817d55764e5e1b7f84fa4b7fd9fbb1d1480792518a0172e1e4d2b30e6c9ef
|
|
BLAKE2b-256 checksum How to use checksums |
58947319742233ca8a1f870e7ca8f7963d966d80d10ab782871eb7bbcbd8da6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 18, 2026.
Transparency logSecurity for ecc-auth 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ecc_auth-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.