mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
23abbb67ea
* feat(auth): add Anthropic OAuth setup-token login flow Add support for Anthropic's OAuth-based setup tokens (sk-ant-oat01-*) as an alternative to API keys. This includes: - New `--setup-token` flag on `auth login` command - Interactive login menu for Anthropic (setup token vs API key) - Setup token validation and credential storage with oauth auth method - Usage endpoint integration to show 5h/7d utilization in `auth status` - Streaming support for OAuth tokens (required by Anthropic API) - Model ID normalization (dots to hyphens) for API compatibility - Remove .env.example (secrets should not be templated) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(auth): update related functionality * refactor(auth): organize constants and improve header casing in requests fo CI * fix(auth): fix golint again * fix(auth): handle nil arguments in tool calls for buildParams function --------- Co-authored-by: Baller <sharonms3377@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package auth
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
func LoginPasteToken(provider string, r io.Reader) (*AuthCredential, error) {
|
|
fmt.Printf("Paste your API key or session token from %s:\n", providerDisplayName(provider))
|
|
fmt.Print("> ")
|
|
|
|
scanner := bufio.NewScanner(r)
|
|
if !scanner.Scan() {
|
|
if err := scanner.Err(); err != nil {
|
|
return nil, fmt.Errorf("reading token: %w", err)
|
|
}
|
|
return nil, fmt.Errorf("no input received")
|
|
}
|
|
|
|
token := strings.TrimSpace(scanner.Text())
|
|
if token == "" {
|
|
return nil, fmt.Errorf("token cannot be empty")
|
|
}
|
|
|
|
return &AuthCredential{
|
|
AccessToken: token,
|
|
Provider: provider,
|
|
AuthMethod: "token",
|
|
}, nil
|
|
}
|
|
|
|
func LoginSetupToken(r io.Reader) (*AuthCredential, error) {
|
|
fmt.Println("Paste your setup token from `claude setup-token`:")
|
|
fmt.Print("> ")
|
|
|
|
scanner := bufio.NewScanner(r)
|
|
if !scanner.Scan() {
|
|
if err := scanner.Err(); err != nil {
|
|
return nil, fmt.Errorf("reading token: %w", err)
|
|
}
|
|
return nil, fmt.Errorf("no input received")
|
|
}
|
|
|
|
token := strings.TrimSpace(scanner.Text())
|
|
|
|
if !strings.HasPrefix(token, "sk-ant-oat01-") {
|
|
return nil, fmt.Errorf("invalid setup token: expected prefix sk-ant-oat01-")
|
|
}
|
|
|
|
if len(token) < 80 {
|
|
return nil, fmt.Errorf("invalid setup token: too short (expected at least 80 characters)")
|
|
}
|
|
|
|
return &AuthCredential{
|
|
AccessToken: token,
|
|
Provider: "anthropic",
|
|
AuthMethod: "oauth",
|
|
}, nil
|
|
}
|
|
|
|
func providerDisplayName(provider string) string {
|
|
switch provider {
|
|
case "anthropic":
|
|
return "console.anthropic.com"
|
|
case "openai":
|
|
return "platform.openai.com"
|
|
default:
|
|
return provider
|
|
}
|
|
}
|