diff --git a/backend/internal/repository/claude_oauth_service.go b/backend/internal/repository/claude_oauth_service.go index 8cc4bce2..262d8e8b 100644 --- a/backend/internal/repository/claude_oauth_service.go +++ b/backend/internal/repository/claude_oauth_service.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "net/url" + "strings" "time" "sub2api/internal/pkg/oauth" @@ -139,20 +140,12 @@ func (s *claudeOAuthService) GetAuthorizationCode(ctx context.Context, sessionKe func (s *claudeOAuthService) ExchangeCodeForToken(ctx context.Context, code, codeVerifier, state, proxyURL string) (*oauth.TokenResponse, error) { client := createReqClient(proxyURL) + // Parse code which may contain state in format "authCode#state" authCode := code codeState := "" - if len(code) > 0 { - parts := make([]string, 0, 2) - for i, part := range []rune(code) { - if part == '#' { - authCode = code[:i] - codeState = code[i+1:] - break - } - } - if len(parts) == 0 { - authCode = code - } + if idx := strings.Index(code, "#"); idx != -1 { + authCode = code[:idx] + codeState = code[idx+1:] } reqBody := map[string]any{