diff --git a/internal/auth/claude/anthropic_auth.go b/internal/auth/claude/anthropic_auth.go index 07bd5b42..54edce3b 100644 --- a/internal/auth/claude/anthropic_auth.go +++ b/internal/auth/claude/anthropic_auth.go @@ -18,11 +18,12 @@ import ( log "github.com/sirupsen/logrus" ) +// OAuth configuration constants for Claude/Anthropic const ( - anthropicAuthURL = "https://claude.ai/oauth/authorize" - anthropicTokenURL = "https://console.anthropic.com/v1/oauth/token" - anthropicClientID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e" - redirectURI = "http://localhost:54545/callback" + AuthURL = "https://claude.ai/oauth/authorize" + TokenURL = "https://console.anthropic.com/v1/oauth/token" + ClientID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e" + RedirectURI = "http://localhost:54545/callback" ) // tokenResponse represents the response structure from Anthropic's OAuth token endpoint. @@ -82,16 +83,16 @@ func (o *ClaudeAuth) GenerateAuthURL(state string, pkceCodes *PKCECodes) (string params := url.Values{ "code": {"true"}, - "client_id": {anthropicClientID}, + "client_id": {ClientID}, "response_type": {"code"}, - "redirect_uri": {redirectURI}, + "redirect_uri": {RedirectURI}, "scope": {"org:create_api_key user:profile user:inference"}, "code_challenge": {pkceCodes.CodeChallenge}, "code_challenge_method": {"S256"}, "state": {state}, } - authURL := fmt.Sprintf("%s?%s", anthropicAuthURL, params.Encode()) + authURL := fmt.Sprintf("%s?%s", AuthURL, params.Encode()) return authURL, state, nil } @@ -137,8 +138,8 @@ func (o *ClaudeAuth) ExchangeCodeForTokens(ctx context.Context, code, state stri "code": newCode, "state": state, "grant_type": "authorization_code", - "client_id": anthropicClientID, - "redirect_uri": redirectURI, + "client_id": ClientID, + "redirect_uri": RedirectURI, "code_verifier": pkceCodes.CodeVerifier, } @@ -154,7 +155,7 @@ func (o *ClaudeAuth) ExchangeCodeForTokens(ctx context.Context, code, state stri // log.Debugf("Token exchange request: %s", string(jsonBody)) - req, err := http.NewRequestWithContext(ctx, "POST", anthropicTokenURL, strings.NewReader(string(jsonBody))) + req, err := http.NewRequestWithContext(ctx, "POST", TokenURL, strings.NewReader(string(jsonBody))) if err != nil { return nil, fmt.Errorf("failed to create token request: %w", err) } @@ -221,7 +222,7 @@ func (o *ClaudeAuth) RefreshTokens(ctx context.Context, refreshToken string) (*C } reqBody := map[string]interface{}{ - "client_id": anthropicClientID, + "client_id": ClientID, "grant_type": "refresh_token", "refresh_token": refreshToken, } @@ -231,7 +232,7 @@ func (o *ClaudeAuth) RefreshTokens(ctx context.Context, refreshToken string) (*C return nil, fmt.Errorf("failed to marshal request body: %w", err) } - req, err := http.NewRequestWithContext(ctx, "POST", anthropicTokenURL, strings.NewReader(string(jsonBody))) + req, err := http.NewRequestWithContext(ctx, "POST", TokenURL, strings.NewReader(string(jsonBody))) if err != nil { return nil, fmt.Errorf("failed to create refresh request: %w", err) }