Shared Xinghe OAuth2 authentication SDK for ECC projects
Project description
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.
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.2.0.tar.gz.
File metadata
- Download URL: ecc_auth-0.2.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8a9254a552a15b0e456bca7cdd80c9b878703b17a4504f4e69ab762cc57a22e
|
|
| MD5 |
616682f57b605bfbeb78015445fae2f1
|
|
| BLAKE2b-256 |
d34f852a314f5d2bea33e2067a574c5d927f42e71aefb79dc1d7240fe4b95a13
|
Provenance
The following attestation bundles were made for ecc_auth-0.2.0.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.2.0.tar.gz -
Subject digest:
b8a9254a552a15b0e456bca7cdd80c9b878703b17a4504f4e69ab762cc57a22e - Sigstore transparency entry: 1565697693
- Sigstore integration time:
-
Permalink:
early-chinese-civilization/ecc-auth@fe1043d775bf2080c349db6cfcd9cee86a045962 -
Branch / Tag:
refs/tags/v0.2.0 - 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@fe1043d775bf2080c349db6cfcd9cee86a045962 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ecc_auth-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ecc_auth-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.1 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 |
57a817d55764e5e1b7f84fa4b7fd9fbb1d1480792518a0172e1e4d2b30e6c9ef
|
|
| MD5 |
7c44047022f5b8f42fbc7a8450458762
|
|
| BLAKE2b-256 |
58947319742233ca8a1f870e7ca8f7963d966d80d10ab782871eb7bbcbd8da6e
|
Provenance
The following attestation bundles were made for ecc_auth-0.2.0-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.2.0-py3-none-any.whl -
Subject digest:
57a817d55764e5e1b7f84fa4b7fd9fbb1d1480792518a0172e1e4d2b30e6c9ef - Sigstore transparency entry: 1565697716
- Sigstore integration time:
-
Permalink:
early-chinese-civilization/ecc-auth@fe1043d775bf2080c349db6cfcd9cee86a045962 -
Branch / Tag:
refs/tags/v0.2.0 - 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@fe1043d775bf2080c349db6cfcd9cee86a045962 -
Trigger Event:
release
-
Statement type: