| 22 | } |
| 23 | |
| 24 | func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Command { |
| 25 | opts := &LogoutOptions{ |
| 26 | IO: f.IOStreams, |
| 27 | Config: f.Config, |
| 28 | Prompter: f.Prompter, |
| 29 | } |
| 30 | |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "logout", |
| 33 | Args: cobra.ExactArgs(0), |
| 34 | Short: "Log out of a GitHub account", |
| 35 | Long: heredoc.Doc(` |
| 36 | Remove authentication for a GitHub account. |
| 37 | |
| 38 | This command removes the stored authentication configuration |
| 39 | for an account. The authentication configuration is only |
| 40 | removed locally. |
| 41 | |
| 42 | This command does not revoke authentication tokens. |
| 43 | |
| 44 | To revoke all authentication tokens generated by the GitHub CLI: |
| 45 | |
| 46 | 1. Visit <https://github.com/settings/applications> |
| 47 | 2. Select the "GitHub CLI" application |
| 48 | 3. Select "Revoke Access" |
| 49 | 4. Select "I understand, revoke access" |
| 50 | |
| 51 | Note: this procedure will revoke all authentication tokens ever |
| 52 | generated by the GitHub CLI across all your devices. |
| 53 | |
| 54 | For more information about revoking OAuth application tokens, see: |
| 55 | <https://docs.github.com/en/apps/oauth-apps/using-oauth-apps/reviewing-your-authorized-oauth-apps> |
| 56 | `), |
| 57 | Example: heredoc.Doc(` |
| 58 | # Select what host and account to log out of via a prompt |
| 59 | $ gh auth logout |
| 60 | |
| 61 | # Log out of a specific host and specific account |
| 62 | $ gh auth logout --hostname enterprise.internal --user monalisa |
| 63 | `), |
| 64 | RunE: func(cmd *cobra.Command, args []string) error { |
| 65 | if runF != nil { |
| 66 | return runF(opts) |
| 67 | } |
| 68 | |
| 69 | return logoutRun(opts) |
| 70 | }, |
| 71 | } |
| 72 | |
| 73 | cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The hostname of the GitHub instance to log out of") |
| 74 | cmd.Flags().StringVarP(&opts.Username, "user", "u", "", "The account to log out of") |
| 75 | |
| 76 | return cmd |
| 77 | } |
| 78 | |
| 79 | func logoutRun(opts *LogoutOptions) error { |
| 80 | hostname := opts.Hostname |