mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-12 04:09:48 +08:00
feat(providers): expand OAuth account management
Add Claude Code manual and cookie authorization, including redacted batch tasks. Harden OAuth imports, duplicate replacement, provider dialogs, and related account-management tests.
This commit is contained in:
@@ -3,8 +3,13 @@ use super::super::errors::{
|
||||
};
|
||||
use crate::handlers::admin::request::{AdminAppState, AdminProviderOAuthTemplate};
|
||||
use aether_contracts::ProxySnapshot;
|
||||
use aether_oauth::provider::providers::GenericProviderOAuthAdapter;
|
||||
use aether_oauth::provider::{ProviderOAuthService, ProviderOAuthTransportContext};
|
||||
use aether_oauth::provider::providers::{
|
||||
ClaudeCodeProviderOAuthAdapter, GenericProviderOAuthAdapter, CLAUDE_CODE_PROVIDER_TYPE,
|
||||
CLAUDE_CODE_TOKEN_URL, CLAUDE_CODE_WEB_BASE_URL,
|
||||
};
|
||||
use aether_oauth::provider::{
|
||||
ProviderOAuthCookieAuthorizationInput, ProviderOAuthService, ProviderOAuthTransportContext,
|
||||
};
|
||||
use axum::{body::Body, http, response::Response};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -140,3 +145,40 @@ pub(crate) async fn exchange_admin_provider_oauth_refresh_token(
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn authorize_admin_provider_oauth_with_cookie(
|
||||
state: &AdminAppState<'_>,
|
||||
session_key: String,
|
||||
proxy: Option<ProxySnapshot>,
|
||||
) -> Result<serde_json::Value, Response<Body>> {
|
||||
let web_base_url =
|
||||
state.provider_oauth_token_url("claude_code_cookie_base_url", CLAUDE_CODE_WEB_BASE_URL);
|
||||
let token_url =
|
||||
state.provider_oauth_token_url(CLAUDE_CODE_PROVIDER_TYPE, CLAUDE_CODE_TOKEN_URL);
|
||||
let service = ProviderOAuthService::new().with_adapter(Arc::new(
|
||||
ClaudeCodeProviderOAuthAdapter::default().with_endpoint_overrides(web_base_url, token_url),
|
||||
));
|
||||
let ctx = provider_oauth_exchange_context(CLAUDE_CODE_PROVIDER_TYPE, proxy);
|
||||
let executor = crate::oauth::GatewayOAuthHttpExecutor::new(*state);
|
||||
let result = service
|
||||
.authorize_with_cookie(
|
||||
&executor,
|
||||
&ctx,
|
||||
ProviderOAuthCookieAuthorizationInput { session_key },
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
let detail = if matches!(error, aether_oauth::core::OAuthError::InvalidRequest(_)) {
|
||||
"Claude Cookie 格式无效"
|
||||
} else {
|
||||
"Claude Cookie 授权失败"
|
||||
};
|
||||
build_internal_control_error_response(http::StatusCode::BAD_REQUEST, detail)
|
||||
})?;
|
||||
token_payload_from_provider_oauth_result(result).map_err(|_| {
|
||||
build_internal_control_error_response(
|
||||
http::StatusCode::BAD_REQUEST,
|
||||
"Claude Cookie 授权返回缺少 access_token",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user