Skip to main content

Shared Casdoor authentication client for Blade ecosystem services.

Project description

blade-auth-client

blade-auth-client 是 Blade 生态的共享 Casdoor 认证客户端包。它抽离了统一的 token 校验、FastAPI 装配和 Socket.IO 握手接口,供各个服务复用。

安装

pip install blade-auth-client[fastapi,socketio]

Casdoor 配置要求

Casdoor 的 application、scope 和 redirect URI 约束见 docs/casdoor-setup.md

快速上手(0.4.0+)

from fastapi import FastAPI, Depends
from blade_auth_client import AuthConfig, BladeAuth, CasdoorClaims, LazyProvisioner

class MyProvisioner(LazyProvisioner["MyUser"]):
    async def provision_user(self, claims: CasdoorClaims) -> "MyUser":
        # 首次登录:建用户并绑定 claims.sub;非首次:查出来刷字段
        ...

auth = BladeAuth(
    AuthConfig.from_yaml("configs/oauth_config.yaml"),
    provisioner=MyProvisioner(),
)

app = FastAPI()
app.include_router(auth.router, prefix="/api/v1/auth")

@app.get("/me")
def me(user = auth.require()):
    return user

详细流程见 docs/接入指南.md;多 app 共享鉴权 / BladeAuth 设计背景见 docs/设计-API暴露面收敛.md

从 0.3.x 升级

  • 推荐迁到 BladeAuth facade(上面那段)。老零件(OidcClient / TokenVerifier / create_auth_router / make_require_auth_dep / 等)0.4.0 仍可从顶层 import,但会 DeprecationWarning,0.5.0 移除。
  • LazyProvisioner.ensure_userprovision_user。老名字继续可用且 SDK 内部自动回落,调用时 warn 一次。

版本策略

0.0.x 版本仅用于占位发布和联调验证,不承诺可用性。0.2.0 起采用仅校验 iss + 签名 + exp 的简化策略。

发布

仓库已经预留了 GitHub Actions 发布流水线:

  • PR 校验:.github/workflows/python-sdk-ci.yml
  • PyPI 发布:.github/workflows/python-sdk-publish.yml

首次配置 Trusted Publishing 时,在 PyPI 项目的 Publishing 页面添加 GitHub publisher,填写:

  • Owner: blade-hq
  • Repository name: blade-oauth
  • Workflow name: python-sdk-publish.yml

日常发版流程:

# 1. 修改 sdk/python/pyproject.toml 里的 version

# 2. 推送代码到默认分支后,创建并推送同版本 tag
git tag blade-auth-client-vX.Y.Z
git push origin blade-auth-client-vX.Y.Z

发布 workflow 会校验 tag 版本与 pyproject.toml 一致,然后自动构建并发布到 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

blade_auth_client-0.4.1.tar.gz (102.0 kB view details)

Uploaded Source

Built Distribution

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

blade_auth_client-0.4.1-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file blade_auth_client-0.4.1.tar.gz.

File metadata

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

File hashes

Hashes for blade_auth_client-0.4.1.tar.gz
Algorithm Hash digest
SHA256 99ec8a571b306b89bbc06f9d33fdf1484eb818f627c03380f305bdfcaec11dfc
MD5 2de7fe36fa8d2386557e9cbc8a2c4daa
BLAKE2b-256 2157bcc75b92dc894e6a9fdf54485870d3dacdab1596e0b505427890bdb021a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for blade_auth_client-0.4.1.tar.gz:

Publisher: python-sdk-publish.yml on blade-hq/blade-oauth

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

File details

Details for the file blade_auth_client-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for blade_auth_client-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73d987ee7ad4a67e14ed868acdfb1075727c5f83d6f04e435fc3017892322294
MD5 f43b5c4581969fb0f45f7d2b72239180
BLAKE2b-256 7633fad13d381753a4342b16c82194b688b6220f9992fa3a8e1a2b3dfc817437

See more details on using hashes here.

Provenance

The following attestation bundles were made for blade_auth_client-0.4.1-py3-none-any.whl:

Publisher: python-sdk-publish.yml on blade-hq/blade-oauth

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