taolib.testing.oauth#
taolib.oauth — OAuth2 第三方登录模块。
支持 Google、GitHub 等多种 OAuth2 提供商的第三方登录, 提供完整的授权码流程、账户关联、Token 管理和管理面板。
- 核心组件:
providers: OAuth2 提供商实现(Google、GitHub 等)
services: 业务逻辑层(流程、账户、Token、会话、管理)
models: Pydantic 数据模型
repository: MongoDB 数据访问层
crypto: Token 加密存储
cache: Redis 缓存(State、Session)
integration: config_center 桥接
server: FastAPI Web 服务器
Submodules#
Exceptions#
该提供商已关联到此账户。 |
|
无法解除关联(至少需要一种认证方式)。 |
|
授权码交换失败。 |
|
未找到 OAuth 应用凭证。 |
|
OAuth 基础异常。 |
|
引导流程数据无效。 |
|
OAuth 提供商返回错误。 |
|
OAuth 提供商未注册。 |
|
提供商不支持 Token 刷新。 |
|
会话无效或已过期。 |
|
CSRF State 无效或已过期。 |
|
Token 解密失败。 |
|
Token 操作失败。 |
|
Token 刷新失败。 |
|
获取用户信息失败。 |
Classes#
OAuth 活动操作类型枚举。 |
|
OAuth 活动状态枚举。 |
|
OAuth 连接状态枚举。 |
|
OAuth 提供商枚举。 |
|
标准化的 OAuth 用户信息。 |
|
首次登录引导数据模型。 |
|
OAuth 提供商注册表。 |
Package Contents#
- exception taolib.testing.oauth.OAuthAlreadyLinkedError(message: str = '该提供商已关联到此账户')#
Bases:
OAuthError该提供商已关联到此账户。
- exception taolib.testing.oauth.OAuthCannotUnlinkError(message: str = '无法解除关联,至少需要保留一种认证方式')#
Bases:
OAuthError无法解除关联(至少需要一种认证方式)。
- exception taolib.testing.oauth.OAuthCodeExchangeError(message: str = '授权码交换失败')#
Bases:
OAuthProviderError授权码交换失败。
- exception taolib.testing.oauth.OAuthCredentialNotFoundError(message: str = '未找到 OAuth 应用凭证')#
Bases:
OAuthError未找到 OAuth 应用凭证。
- exception taolib.testing.oauth.OAuthError(message: str = 'OAuth 操作失败')#
Bases:
ExceptionOAuth 基础异常。
- message = 'OAuth 操作失败'#
- exception taolib.testing.oauth.OAuthOnboardingError(message: str = '引导流程数据无效')#
Bases:
OAuthError引导流程数据无效。
- exception taolib.testing.oauth.OAuthProviderError(message: str = 'OAuth 提供商返回错误')#
Bases:
OAuthErrorOAuth 提供商返回错误。
- exception taolib.testing.oauth.OAuthProviderNotRegisteredError(message: str = 'OAuth 提供商未注册')#
Bases:
OAuthErrorOAuth 提供商未注册。
- exception taolib.testing.oauth.OAuthRefreshNotSupported(message: str = '该提供商不支持 Token 刷新')#
Bases:
OAuthTokenError提供商不支持 Token 刷新。
- exception taolib.testing.oauth.OAuthSessionError(message: str = '会话无效或已过期')#
Bases:
OAuthError会话无效或已过期。
- exception taolib.testing.oauth.OAuthStateError(message: str = '无效或已过期的 OAuth State')#
Bases:
OAuthErrorCSRF State 无效或已过期。
- exception taolib.testing.oauth.OAuthTokenDecryptionError(message: str = 'Token 解密失败')#
Bases:
OAuthTokenErrorToken 解密失败。
- exception taolib.testing.oauth.OAuthTokenError(message: str = 'Token 操作失败')#
Bases:
OAuthErrorToken 操作失败。
- exception taolib.testing.oauth.OAuthTokenRefreshError(message: str = 'Token 刷新失败')#
Bases:
OAuthTokenErrorToken 刷新失败。
- exception taolib.testing.oauth.OAuthUserInfoError(message: str = '获取用户信息失败')#
Bases:
OAuthProviderError获取用户信息失败。
- class taolib.testing.oauth.OAuthActivityAction#
Bases:
enum.StrEnumOAuth 活动操作类型枚举。
- LOGIN = 'oauth.login'#
- LINK = 'oauth.link'#
- UNLINK = 'oauth.unlink'#
- TOKEN_REFRESH = 'oauth.token_refresh'#
- ONBOARDING_COMPLETE = 'oauth.onboarding_complete'#
- CREDENTIAL_CREATE = 'oauth.credential.create'#
- CREDENTIAL_UPDATE = 'oauth.credential.update'#
- CREDENTIAL_DELETE = 'oauth.credential.delete'#
- class taolib.testing.oauth.OAuthActivityStatus#
Bases:
enum.StrEnumOAuth 活动状态枚举。
- SUCCESS = 'success'#
- FAILED = 'failed'#
- class taolib.testing.oauth.OAuthConnectionStatus#
Bases:
enum.StrEnumOAuth 连接状态枚举。
- ACTIVE = 'active'#
- REVOKED = 'revoked'#
- EXPIRED = 'expired'#
- PENDING_ONBOARDING = 'pending_onboarding'#
- class taolib.testing.oauth.OAuthProvider#
Bases:
enum.StrEnumOAuth 提供商枚举。
- GOOGLE = 'google'#
- GITHUB = 'github'#
- class taolib.testing.oauth.OAuthUserInfo#
Bases:
pydantic.BaseModel标准化的 OAuth 用户信息。
从不同提供商的响应中提取的统一格式用户信息。
- class taolib.testing.oauth.OnboardingData#
Bases:
pydantic.BaseModel首次登录引导数据模型。
新用户通过 OAuth 首次登录时需要填写的资料。
- class taolib.testing.oauth.ProviderRegistry#
OAuth 提供商注册表。
管理所有已注册的 OAuth 提供商,支持动态注册和查找。
- _providers: dict[str, base.OAuthProviderProtocol]#
- register(provider: base.OAuthProviderProtocol) None#
注册一个 OAuth 提供商。
- 参数:
provider -- 实现 OAuthProviderProtocol 的提供商实例
- get(provider_name: str) base.OAuthProviderProtocol#
获取指定的提供商。
- 参数:
provider_name -- 提供商名称
- 返回:
提供商实例
- 抛出:
KeyError -- 如果提供商未注册