From a1292fac8182aa3314f3253d4c2868ef91d03016 Mon Sep 17 00:00:00 2001 From: shaw Date: Fri, 23 Jan 2026 16:30:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(oauth):=20=E6=94=AF=E6=8C=81Anthropic?= =?UTF-8?q?=E7=9A=84Team=E8=B4=A6=E5=8F=B7=E4=BD=BF=E7=94=A8sk=E6=8E=88?= =?UTF-8?q?=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/claude_oauth_service.go | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/internal/repository/claude_oauth_service.go b/backend/internal/repository/claude_oauth_service.go index 1f1db553..fc0d2918 100644 --- a/backend/internal/repository/claude_oauth_service.go +++ b/backend/internal/repository/claude_oauth_service.go @@ -35,7 +35,9 @@ func (s *claudeOAuthService) GetOrganizationUUID(ctx context.Context, sessionKey client := s.clientFactory(proxyURL) var orgs []struct { - UUID string `json:"uuid"` + UUID string `json:"uuid"` + Name string `json:"name"` + RavenType *string `json:"raven_type"` // nil for personal, "team" for team organization } targetURL := s.baseURL + "/api/organizations" @@ -65,7 +67,23 @@ func (s *claudeOAuthService) GetOrganizationUUID(ctx context.Context, sessionKey return "", fmt.Errorf("no organizations found") } - log.Printf("[OAuth] Step 1 SUCCESS - Got org UUID: %s", orgs[0].UUID) + // 如果只有一个组织,直接使用 + if len(orgs) == 1 { + log.Printf("[OAuth] Step 1 SUCCESS - Single org found, UUID: %s, Name: %s", orgs[0].UUID, orgs[0].Name) + return orgs[0].UUID, nil + } + + // 如果有多个组织,优先选择 raven_type 为 "team" 的组织 + for _, org := range orgs { + if org.RavenType != nil && *org.RavenType == "team" { + log.Printf("[OAuth] Step 1 SUCCESS - Selected team org, UUID: %s, Name: %s, RavenType: %s", + org.UUID, org.Name, *org.RavenType) + return org.UUID, nil + } + } + + // 如果没有 team 类型的组织,使用第一个 + log.Printf("[OAuth] Step 1 SUCCESS - No team org found, using first org, UUID: %s, Name: %s", orgs[0].UUID, orgs[0].Name) return orgs[0].UUID, nil }