feat(auth): 添加微信小程序登录支持
- 新增 wechat_users 表迁移和 SeaORM Entity - 实现微信登录 Service(code→openid→绑定状态查询) - 实现手机号绑定 Service(创建/关联 user + 签发 JWT) - 添加公开路由 POST /auth/wechat/login 和 /auth/wechat/bind-phone - 新增 WechatConfig 到 AppConfig(appid/secret 通过环境变量配置) - 添加 reqwest 依赖用于调用微信 jscode2session API
This commit is contained in:
@@ -9,6 +9,7 @@ pub struct AppConfig {
|
||||
pub auth: AuthConfig,
|
||||
pub log: LogConfig,
|
||||
pub cors: CorsConfig,
|
||||
pub wechat: WechatConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -53,6 +54,12 @@ pub struct CorsConfig {
|
||||
pub allowed_origins: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct WechatConfig {
|
||||
pub appid: String,
|
||||
pub secret: String,
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
let config = config::Config::builder()
|
||||
|
||||
@@ -51,6 +51,8 @@ impl FromRef<AppState> for erp_auth::AuthState {
|
||||
access_ttl_secs: parse_ttl(&state.config.jwt.access_token_ttl),
|
||||
refresh_ttl_secs: parse_ttl(&state.config.jwt.refresh_token_ttl),
|
||||
default_tenant_id: state.default_tenant_id,
|
||||
wechat_appid: state.config.wechat.appid.clone(),
|
||||
wechat_secret: state.config.wechat.secret.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user