提供基本前后端骨架
This commit is contained in:
85
app/schemas/oauth2.py
Normal file
85
app/schemas/oauth2.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
OAuth2 相关 Schema
|
||||
|
||||
定义 OAuth2 认证流程的数据结构。
|
||||
"""
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.schemas.base import BaseSchema
|
||||
|
||||
|
||||
class OAuth2AuthorizeResponse(BaseSchema):
|
||||
"""OAuth2 授权 URL 响应"""
|
||||
|
||||
authorize_url: str = Field(description="OAuth2 授权页面 URL")
|
||||
state: str = Field(description="防 CSRF 状态码")
|
||||
|
||||
|
||||
class OAuth2CallbackRequest(BaseSchema):
|
||||
"""OAuth2 回调请求"""
|
||||
|
||||
code: Annotated[
|
||||
str,
|
||||
Field(
|
||||
min_length=1,
|
||||
description="授权码",
|
||||
),
|
||||
]
|
||||
state: Annotated[
|
||||
str,
|
||||
Field(
|
||||
min_length=1,
|
||||
description="状态码(用于验证请求合法性)",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class OAuth2TokenData(BaseSchema):
|
||||
"""OAuth2 令牌数据(从 OAuth 提供商获取)"""
|
||||
|
||||
access_token: str
|
||||
token_type: str = "Bearer"
|
||||
expires_in: int | None = None
|
||||
refresh_token: str | None = None
|
||||
scope: str | None = None
|
||||
|
||||
|
||||
class OAuth2UserInfo(BaseSchema):
|
||||
"""
|
||||
OAuth2 用户信息(从 Linux.do 获取)
|
||||
|
||||
示例响应:
|
||||
{
|
||||
"id": 1,
|
||||
"username": "neo",
|
||||
"name": "Neo",
|
||||
"active": true,
|
||||
"trust_level": 4,
|
||||
"email": "u1@linux.do",
|
||||
"avatar_url": "https://linux.do/xxxx",
|
||||
"silenced": false
|
||||
}
|
||||
"""
|
||||
|
||||
id: int | str = Field(description="用户 ID")
|
||||
username: str = Field(description="用户名")
|
||||
name: str | None = Field(default=None, description="显示名称")
|
||||
email: str | None = Field(default=None, description="邮箱")
|
||||
avatar_url: str | None = Field(default=None, description="头像 URL")
|
||||
active: bool = Field(default=True, description="是否激活")
|
||||
trust_level: int | None = Field(default=None, description="信任等级")
|
||||
silenced: bool = Field(default=False, description="是否被禁言")
|
||||
|
||||
|
||||
class OAuth2LoginResponse(BaseSchema):
|
||||
"""OAuth2 登录响应"""
|
||||
|
||||
access_token: str = Field(description="JWT 访问令牌")
|
||||
refresh_token: str = Field(description="JWT 刷新令牌")
|
||||
token_type: str = Field(default="Bearer", description="令牌类型")
|
||||
expires_in: int = Field(description="访问令牌过期时间(秒)")
|
||||
is_new_user: bool = Field(description="是否为新注册用户")
|
||||
|
||||
Reference in New Issue
Block a user