taolib.testing.auth.fastapi.schemes

taolib.testing.auth.fastapi.schemes#

FastAPI 安全方案工厂。

提供 OAuth2 和 API Key 安全方案的工厂函数。

Functions#

create_oauth2_scheme(...)

创建 OAuth2 Password Bearer 安全方案。

create_api_key_header(→ fastapi.security.APIKeyHeader)

创建 API Key Header 安全方案。

Module Contents#

taolib.testing.auth.fastapi.schemes.create_oauth2_scheme(token_url: str = '/api/v1/auth/token', auto_error: bool = False) fastapi.security.OAuth2PasswordBearer#

创建 OAuth2 Password Bearer 安全方案。

参数:
  • token_url -- 令牌获取端点 URL

  • auto_error -- 缺少令牌时是否自动返回 401(设为 False 以支持双通道认证)

返回:

OAuth2PasswordBearer 实例

taolib.testing.auth.fastapi.schemes.create_api_key_header(name: str = 'X-API-Key', auto_error: bool = False) fastapi.security.APIKeyHeader#

创建 API Key Header 安全方案。

参数:
  • name -- HTTP 头部名称

  • auto_error -- 缺少密钥时是否自动返回 401

返回:

APIKeyHeader 实例