| 41 | } |
| 42 | |
| 43 | func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.Command { |
| 44 | opts := &RefreshOptions{ |
| 45 | IO: f.IOStreams, |
| 46 | Config: f.Config, |
| 47 | AuthFlow: func(httpClient *http.Client, io *iostreams.IOStreams, hostname string, scopes []string, interactive bool, clipboard bool) (token, username, error) { |
| 48 | t, u, err := authflow.AuthFlow(httpClient, hostname, io, "", scopes, interactive, f.Browser, clipboard) |
| 49 | return token(t), username(u), err |
| 50 | }, |
| 51 | PlainHttpClient: f.PlainHttpClient, |
| 52 | GitClient: f.GitClient, |
| 53 | Prompter: f.Prompter, |
| 54 | } |
| 55 | |
| 56 | cmd := &cobra.Command{ |
| 57 | Use: "refresh", |
| 58 | Args: cobra.ExactArgs(0), |
| 59 | Short: "Refresh stored authentication credentials", |
| 60 | Long: heredoc.Docf(` |
| 61 | Expand or fix the permission scopes for stored credentials for active account. |
| 62 | |
| 63 | The %[1]s--scopes%[1]s flag accepts a comma separated list of scopes you want |
| 64 | your gh credentials to have. If no scopes are provided, the command |
| 65 | maintains previously added scopes. |
| 66 | |
| 67 | The %[1]s--remove-scopes%[1]s flag accepts a comma separated list of scopes you |
| 68 | want to remove from your gh credentials. Scope removal is idempotent. |
| 69 | The minimum set of scopes (%[1]srepo%[1]s, %[1]sread:org%[1]s, and %[1]sgist%[1]s) cannot be removed. |
| 70 | |
| 71 | The %[1]s--reset-scopes%[1]s flag resets the scopes for your gh credentials to |
| 72 | the default set of scopes for your auth flow. |
| 73 | |
| 74 | If you have multiple accounts in %[1]sgh auth status%[1]s and want to refresh the credentials for an |
| 75 | inactive account, you will have to use %[1]sgh auth switch%[1]s to that account first before using |
| 76 | this command, and then switch back when you are done. |
| 77 | |
| 78 | For more information on OAuth scopes, see |
| 79 | <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps/>. |
| 80 | `, "`"), |
| 81 | Example: heredoc.Doc(` |
| 82 | # Open a browser to add write:org and read:public_key scopes |
| 83 | $ gh auth refresh --scopes write:org,read:public_key |
| 84 | |
| 85 | # Open a browser to ensure your authentication credentials have the correct minimum scopes |
| 86 | $ gh auth refresh |
| 87 | |
| 88 | # Open a browser to idempotently remove the delete_repo scope |
| 89 | $ gh auth refresh --remove-scopes delete_repo |
| 90 | |
| 91 | # Open a browser to re-authenticate with the default minimum scopes |
| 92 | $ gh auth refresh --reset-scopes |
| 93 | |
| 94 | # Open a browser to re-authenticate and copy one-time OAuth code to clipboard |
| 95 | $ gh auth refresh --clipboard |
| 96 | `), |
| 97 | RunE: func(cmd *cobra.Command, args []string) error { |
| 98 | opts.Interactive = opts.IO.CanPrompt() |
| 99 | |
| 100 | if !opts.Interactive && opts.Hostname == "" { |