主题
AuthorizationService 继承自: Authorization
由 login 使用的 OAuth 授权实现。
该服务负责协调授权 URL 生成、令牌交换、令牌刷新,以及(可选的)借助已配置的 OAuthProvider 解析用户/用户组。
参数: provider: 已配置的 OAuthProvider 描述 OAuth 端点、凭据,以及可选的用户/用户组 API。 fetch_user: 是否请求提供方的用户资料信息。 fetch_groups: 是否请求用户组/角色。 scope: 初始 OAuth 作用域。该服务会在此列表的基础上 追加提供方的默认值(provider.scopes),并在启用时 追加提供方的用户/用户组作用域。
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
dehydrate_token | — | — | Restore and validate previously persisted token state. The token is deserialized, refreshed when expired, and optionally used to load user and group metadata. Args: saved_token: JSON-serialized token data produced by to_json. |
get_token | Optional[OAuthToken] | — | Return current token after applying refresh logic when required. Returns: Current OAuthToken, or None if no token is available yet. |
get_authorization_data | tuple[str, str] | — | Generate authorization URL and CSRF state for OAuth redirect flow. Returns: A tuple of (authorization_url, state). |
request_token | — | — | Exchange authorization code for access token and optional profile data. Args: code: Provider-issued authorization code returned to redirect URL. Raises: httpx.HTTPStatusError: If token endpoint returns a non-success status. |