MCPcopy Create free account
hub / github.com/basecamp/hey-cli / newAuthLoginCommand

Function newAuthLoginCommand

internal/cmd/auth.go:41–101  ·  view source on GitHub ↗

login subcommand

()

Source from the content-addressed store, hash-verified

39// login subcommand
40
41func newAuthLoginCommand() *cobra.Command {
42 var (
43 token string
44 cookie string
45 noBrowser bool
46 )
47
48 cmd := &cobra.Command{
49 Use: "login",
50 Short: "Authenticate with the HEY server",
51 Long: `Authenticate with the HEY server via Launchpad OAuth.
52
53Opens a browser for OAuth authentication. Use --token or --cookie for non-interactive login.`,
54 Example: ` hey auth login
55 hey auth login --token YOUR_BEARER_TOKEN
56 hey auth login --cookie SESSION_COOKIE_VALUE
57 hey auth login --no-browser`,
58 RunE: func(cmd *cobra.Command, args []string) error {
59 if token != "" {
60 if err := authMgr.LoginWithToken(token); err != nil {
61 return output.ErrAuth(fmt.Sprintf("could not save token: %v", err))
62 }
63 if writer.IsStyled() {
64 fmt.Fprintln(cmd.OutOrStdout(), "Logged in with token.")
65 return nil
66 }
67 return writeOK(map[string]string{"method": "token"}, output.WithSummary("Logged in with token"))
68 }
69
70 if cookie != "" {
71 if err := authMgr.LoginWithCookie(cookie); err != nil {
72 return output.ErrAuth(fmt.Sprintf("could not save cookie: %v", err))
73 }
74 if writer.IsStyled() {
75 fmt.Fprintln(cmd.OutOrStdout(), "Logged in with session cookie.")
76 return nil
77 }
78 return writeOK(map[string]string{"method": "cookie"}, output.WithSummary("Logged in with session cookie"))
79 }
80
81 ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute)
82 defer cancel()
83
84 if err := authMgr.Login(ctx, auth.LoginOptions{NoBrowser: noBrowser}); err != nil {
85 return output.ErrAuth(fmt.Sprintf("login failed: %v", err))
86 }
87
88 if writer.IsStyled() {
89 fmt.Fprintln(cmd.OutOrStdout(), "Logged in successfully.")
90 return nil
91 }
92 return writeOK(map[string]string{"method": "oauth"}, output.WithSummary("Logged in successfully"))
93 },
94 }
95
96 cmd.Flags().StringVar(&token, "token", "", "Pre-generated Bearer token")
97 cmd.Flags().StringVar(&cookie, "cookie", "", "Session cookie value from browser (session_token)")
98 cmd.Flags().BoolVar(&noBrowser, "no-browser", false, "Don't open browser, print URL instead")

Callers 1

newAuthCommandFunction · 0.85

Calls 6

WithSummaryFunction · 0.92
writeOKFunction · 0.85
LoginWithTokenMethod · 0.80
IsStyledMethod · 0.80
LoginWithCookieMethod · 0.80
LoginMethod · 0.80

Tested by

no test coverage detected