mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 12:34:22 +08:00
feat: 添加SECTL云服务集成功能
实现SECTL云服务的全面集成,包括: 1. 添加OAuth认证服务,支持PKCE流程 2. 实现云存储管理功能 3. 添加积分数据同步服务 4. 实现通知服务和KV存储服务 5. 添加多语言支持 6. 创建相关React组件和上下文 7. 更新依赖项添加crypto-js 8. 优化HTTP客户端重用
This commit is contained in:
@@ -354,10 +354,12 @@ pub async fn oauth_exchange_code(
|
||||
platform_id: String,
|
||||
platform_secret: String,
|
||||
callback_url: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<OAuthTokenResponse>, String> {
|
||||
println!("[OAuth] 换取令牌 - code: {}, platform_id: {}, callback_url: {}", code, platform_id, callback_url);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
let params = [
|
||||
("grant_type", "authorization_code"),
|
||||
("code", &code),
|
||||
@@ -396,8 +398,11 @@ pub async fn oauth_revoke_token(
|
||||
token_type_hint: Option<String>,
|
||||
platform_id: String,
|
||||
platform_secret: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<()>, String> {
|
||||
let client = reqwest::Client::new();
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
|
||||
let mut payload = serde_json::json!({
|
||||
"token": token,
|
||||
"client_id": platform_id,
|
||||
@@ -431,8 +436,11 @@ pub async fn oauth_introspect_token(
|
||||
token: String,
|
||||
platform_id: String,
|
||||
platform_secret: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<OAuthIntrospectResponse>, String> {
|
||||
let client = reqwest::Client::new();
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
|
||||
let response = client
|
||||
.post("https://sectl.top/api/oauth/introspect")
|
||||
.json(&serde_json::json!({
|
||||
@@ -463,8 +471,11 @@ pub async fn oauth_introspect_token(
|
||||
#[tauri::command]
|
||||
pub async fn oauth_get_user_info(
|
||||
access_token: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<OAuthUserInfo>, String> {
|
||||
let client = reqwest::Client::new();
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
|
||||
let response = client
|
||||
.get("https://sectl.top/api/oauth/userinfo")
|
||||
.header("Authorization", format!("Bearer {}", access_token))
|
||||
@@ -493,8 +504,11 @@ pub async fn oauth_refresh_token(
|
||||
refresh_token: String,
|
||||
platform_id: String,
|
||||
platform_secret: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<OAuthTokenResponse>, String> {
|
||||
let client = reqwest::Client::new();
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
|
||||
let response = client
|
||||
.post("https://sectl.top/api/oauth/token")
|
||||
.json(&serde_json::json!({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use parking_lot::RwLock;
|
||||
use reqwest::Client;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use std::sync::Arc;
|
||||
use tauri::AppHandle;
|
||||
@@ -19,6 +20,7 @@ pub struct AppState {
|
||||
pub auto_score: Arc<RwLock<AutoScoreService>>,
|
||||
pub logger: Arc<RwLock<LoggerService>>,
|
||||
pub data: Arc<RwLock<DataService>>,
|
||||
pub http_client: Client,
|
||||
pub app_handle: AppHandle,
|
||||
}
|
||||
|
||||
@@ -33,6 +35,11 @@ impl AppState {
|
||||
let logger = Arc::new(RwLock::new(LoggerService::new()));
|
||||
let data = Arc::new(RwLock::new(DataService::new()));
|
||||
let db = Arc::new(RwLock::new(None));
|
||||
|
||||
let http_client = Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.expect("Failed to create HTTP client");
|
||||
|
||||
Self {
|
||||
db,
|
||||
@@ -44,6 +51,7 @@ impl AppState {
|
||||
auto_score,
|
||||
logger,
|
||||
data,
|
||||
http_client,
|
||||
app_handle,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user