MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / startAuthCmd

Function startAuthCmd

internal/tui/app.go:540–566  ·  view source on GitHub ↗

── Commands (async) ──────────────────────────────────────────────────────────

(client *api.Client)

Source from the content-addressed store, hash-verified

538// ── Commands (async) ──────────────────────────────────────────────────────────
539
540func startAuthCmd(client *api.Client) tea.Cmd {
541 return func() tea.Msg {
542 tokenResp, err := client.GenerateToken()
543 if err != nil {
544 return authResultMsg{err: err}
545 }
546
547 authURL := fmt.Sprintf("%s?token=%s&exchange=%s", api.CLIBaseURL, tokenResp.AccessToken, tokenResp.ExchangeCode)
548 browser.OpenURL(authURL)
549
550 const maxAttempts = 150
551 for i := 0; i < maxAttempts; i++ {
552 time.Sleep(2 * time.Second)
553 resp, err := client.ExchangeToken(tokenResp.ExchangeCode)
554 if err != nil {
555 continue
556 }
557 if resp.CliID != nil && resp.APIKey != nil {
558 return authResultMsg{cliID: *resp.CliID, apiKey: *resp.APIKey}
559 }
560 if resp.Status != nil && *resp.Status == "expired" {
561 return authResultMsg{err: fmt.Errorf("authentication token expired")}
562 }
563 }
564 return authResultMsg{err: fmt.Errorf("authentication timed out")}
565 }
566}
567
568func downloadMetadataCmd(client *api.Client) tea.Cmd {
569 return func() tea.Msg {

Callers 1

handleInitAuthKeyMethod · 0.85

Calls 2

GenerateTokenMethod · 0.80
ExchangeTokenMethod · 0.80

Tested by

no test coverage detected