mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-17 20:00:52 +08:00
- OAuth2 device authorization grant flow (RFC 8628) for authentication - Streaming and non-streaming chat completions via OpenAI-compatible API - Models: kimi-k2, kimi-k2-thinking, kimi-k2.5 - CLI `--kimi-login` command for device flow auth - Token management with automatic refresh - Thinking/reasoning effort support for thinking-enabled models Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
|
sdkAuth "github.com/router-for-me/CLIProxyAPI/v6/sdk/auth"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// DoKimiLogin triggers the OAuth device flow for Kimi (Moonshot AI) and saves tokens.
|
|
// It initiates the device flow authentication, displays the verification URL for the user,
|
|
// and waits for authorization before saving the tokens.
|
|
//
|
|
// Parameters:
|
|
// - cfg: The application configuration containing proxy and auth directory settings
|
|
// - options: Login options including browser behavior settings
|
|
func DoKimiLogin(cfg *config.Config, options *LoginOptions) {
|
|
if options == nil {
|
|
options = &LoginOptions{}
|
|
}
|
|
|
|
manager := newAuthManager()
|
|
authOpts := &sdkAuth.LoginOptions{
|
|
NoBrowser: options.NoBrowser,
|
|
Metadata: map[string]string{},
|
|
Prompt: options.Prompt,
|
|
}
|
|
|
|
record, savedPath, err := manager.Login(context.Background(), "kimi", cfg, authOpts)
|
|
if err != nil {
|
|
log.Errorf("Kimi authentication failed: %v", err)
|
|
return
|
|
}
|
|
|
|
if savedPath != "" {
|
|
fmt.Printf("Authentication saved to %s\n", savedPath)
|
|
}
|
|
if record != nil && record.Label != "" {
|
|
fmt.Printf("Authenticated as %s\n", record.Label)
|
|
}
|
|
fmt.Println("Kimi authentication successful!")
|
|
}
|