src/server/auth/cmds/cmds.go
func LoginCmd(noMetrics, noPortForwarding *bool) *cobra.Command {
	var useOTP bool
	login := &cobra.Command{
		Short: "Log in to Pachyderm",
		Long: "Login to Pachyderm. Any resources that have been restricted to " +
			"the account you have with your ID provider (e.g. GitHub, Okta) " +
			"account will subsequently be accessible.",
		Run: cmdutil.Run(func([]string) error {
			c, err := client.NewOnUserMachine(!*noMetrics, !*noPortForwarding, "user")
			if err != nil {
				return fmt.Errorf("could not connect: %v", err)
			}
			defer c.Close()

			// Issue authentication request to Pachyderm and get response
			var resp *auth.AuthenticateResponse
			var authErr error
			if useOTP {
				// Exhange short-lived Pachyderm auth code for long-lived Pachyderm token
				fmt.Println("Please enter your Pachyderm One-Time Password:")
				code, err := bufio.NewReader(os.Stdin).ReadString('\n')
				if err != nil {
					return fmt.Errorf("error reading One-Time Password: %v", err)
				}
				code = strings.TrimSpace(code) // drop trailing newline
				resp, authErr = c.Authenticate(
					c.Ctx(),
					&auth.AuthenticateRequest{OneTimePassword: code})
			} else {
				// Exchange GitHub token for Pachyderm token
				token, err := githubLogin()
				if err != nil {
					return err
				}
				fmt.Println("Retrieving Pachyderm token...")
				resp, authErr = c.Authenticate(
					c.Ctx(),
					&auth.AuthenticateRequest{GitHubToken: token})
			}

			// Write new Pachyderm token to config
			if authErr != nil {
				if auth.IsErrPartiallyActivated(authErr) {
					return fmt.Errorf("%v: if pachyderm is stuck in this state, you "+
						"can revert by running 'pachctl auth deactivate' or retry by "+
						"running 'pachctl auth activate' again", authErr)
				}
				return fmt.Errorf("error authenticating with Pachyderm cluster: %v",
					grpcutil.ScrubGRPC(authErr))
			}
			return writePachTokenToCfg(resp.PachToken)
		}),
	}
	login.PersistentFlags().BoolVarP(&useOTP, "one-time-password", "o", false,
		"If set, authenticate with a Dash-provided One-Time Password, rather than "+
			"via GitHub")
	return cmdutil.CreateAlias(login, "auth login")
}
func LoginCmd(noMetrics, noPortForwarding *bool) *cobra.Command {
	var useOTP bool
	login := &cobra.Command{
		Short: "Log in to Pachyderm",
		Long: "Login to Pachyderm. Any resources that have been restricted to " +
			"the account you have with your ID provider (e.g. GitHub, Okta) " +
			"account will subsequently be accessible.",
		Run: cmdutil.Run(func([]string) error {
			c, err := client.NewOnUserMachine(!*noMetrics, !*noPortForwarding, "user")
			if err != nil {
				return fmt.Errorf("could not connect: %v", err)
			}
			defer c.Close()

			// Issue authentication request to Pachyderm and get response
			var resp *auth.AuthenticateResponse
			var authErr error
			if useOTP {
				// Exhange short-lived Pachyderm auth code for long-lived Pachyderm token
				fmt.Println("Please enter your Pachyderm One-Time Password:")
				code, err := bufio.NewReader(os.Stdin).ReadString('\n')
				if err != nil {
					return fmt.Errorf("error reading One-Time Password: %v", err)
				}
				code = strings.TrimSpace(code) // drop trailing newline
				resp, authErr = c.Authenticate(
					c.Ctx(),
					&auth.AuthenticateRequest{OneTimePassword: code})
			} else {
				// Exchange GitHub token for Pachyderm token
				token, err := githubLogin()
				if err != nil {
					return err
				}
				fmt.Println("Retrieving Pachyderm token...")
				resp, authErr = c.Authenticate(
					c.Ctx(),
					&auth.AuthenticateRequest{GitHubToken: token})
			}

			// Write new Pachyderm token to config
			if authErr != nil {
				if auth.IsErrPartiallyActivated(authErr) {
					return fmt.Errorf("%v: if pachyderm is stuck in this state, you "+
						"can revert by running 'pachctl auth deactivate' or retry by "+
						"running 'pachctl auth activate' again", authErr)
				}
				return fmt.Errorf("error authenticating with Pachyderm cluster: %v",
					grpcutil.ScrubGRPC(authErr))
			}
			return writePachTokenToCfg(resp.PachToken)
		}),
	}
	login.PersistentFlags().BoolVarP(&useOTP, "one-time-password", "o", false,
		"If set, authenticate with a Dash-provided One-Time Password, rather than "+
			"via GitHub")
	return cmdutil.CreateAlias(login, "auth login")
}
// LoginCmd returns a cobra.Command to login to a Pachyderm cluster with your
// GitHub account. Any resources that have been restricted to the email address
// registered with your GitHub account will subsequently be accessible.