Skip to content

Commit 4c1803c

Browse files
authored
Merge pull request #1591 from ksylvan/0707-anthropic-can-now-use-only-oauth
Improved Anthropic Plugin Configuration Logic
2 parents 4cfe237 + d1c614d commit 4c1803c

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

core/plugin_registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (o *PluginRegistry) SetupVendor(vendorName string) (err error) {
243243
func (o *PluginRegistry) ConfigureVendors() {
244244
o.VendorManager.Clear()
245245
for _, vendor := range o.VendorsAll.Vendors {
246-
if vendorErr := vendor.Configure(); vendorErr == nil {
246+
if vendorErr := vendor.Configure(); vendorErr == nil && vendor.IsConfigured() {
247247
o.VendorManager.AddVendors(vendor)
248248
}
249249
}

plugins/ai/anthropic/anthropic.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const webSearchToolName = "web_search"
1919
const webSearchToolType = "web_search_20250305"
2020
const sourcesHeader = "## Sources"
2121

22+
const vendorTokenIdentifier = "claude"
23+
2224
func NewClient() (ret *Client) {
2325
vendorName := "Anthropic"
2426
ret = &Client{}
@@ -32,11 +34,7 @@ func NewClient() (ret *Client) {
3234
ret.ApiBaseURL = ret.AddSetupQuestion("API Base URL", false)
3335
ret.ApiBaseURL.Value = defaultBaseUrl
3436
ret.UseOAuth = ret.AddSetupQuestionBool("Use OAuth login", false)
35-
if plugins.ParseBoolElseFalse(ret.UseOAuth.Value) {
36-
ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", false)
37-
} else {
38-
ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", true)
39-
}
37+
ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", false)
4038

4139
ret.maxTokens = 4096
4240
ret.defaultRequiredUserMessage = "Hi"
@@ -52,6 +50,38 @@ func NewClient() (ret *Client) {
5250
return
5351
}
5452

53+
// IsConfigured returns true if either the API key or OAuth is configured
54+
func (an *Client) IsConfigured() bool {
55+
// Check if API key is configured
56+
if an.ApiKey.Value != "" {
57+
return true
58+
}
59+
60+
// Check if OAuth is enabled and has a valid token
61+
if plugins.ParseBoolElseFalse(an.UseOAuth.Value) {
62+
storage, err := common.NewOAuthStorage()
63+
if err != nil {
64+
return false
65+
}
66+
67+
// If no valid token exists, automatically run OAuth flow
68+
if !storage.HasValidToken(vendorTokenIdentifier, 5) {
69+
fmt.Println("OAuth enabled but no valid token found. Starting authentication...")
70+
_, err := RunOAuthFlow()
71+
if err != nil {
72+
fmt.Printf("OAuth authentication failed: %v\n", err)
73+
return false
74+
}
75+
// After successful OAuth flow, check again
76+
return storage.HasValidToken("claude", 5)
77+
}
78+
79+
return true
80+
}
81+
82+
return false
83+
}
84+
5585
type Client struct {
5686
*plugins.PluginBase
5787
ApiBaseURL *plugins.SetupQuestion

0 commit comments

Comments
 (0)