MCPcopy Create free account
hub / github.com/cli/cli / NewCmdRefresh

Function NewCmdRefresh

pkg/cmd/auth/refresh/refresh.go:48–145  ·  view source on GitHub ↗
(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*RefreshOptions) error)

Source from the content-addressed store, hash-verified

46}
47
48func NewCmdRefresh(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*RefreshOptions) error) *cobra.Command {
49 opts := &RefreshOptions{
50 IO: f.IOStreams,
51 Config: f.Config,
52 AuthFlow: func(httpClient *http.Client, io *iostreams.IOStreams, hostname string, scopes []string, interactive, clipboard, requestRefreshToken bool) (*authflow.AuthResult, error) {
53 return authflow.AuthFlow(httpClient, hostname, io, "", scopes, interactive, f.Browser, clipboard, requestRefreshToken)
54 },
55 PlainHttpClient: f.PlainHttpClient,
56 GitClient: f.GitClient,
57 Prompter: f.Prompter,
58 Telemetry: telemetry,
59 }
60
61 cmd := &cobra.Command{
62 Use: "refresh",
63 Args: cobra.ExactArgs(0),
64 Short: "Refresh stored authentication credentials",
65 Long: heredoc.Docf(`
66 Expand or fix the permission scopes for stored credentials for active account.
67
68 The %[1]s--scopes%[1]s flag accepts a comma separated list of scopes you want
69 your gh credentials to have. If no scopes are provided, the command
70 maintains previously added scopes.
71
72 The %[1]s--remove-scopes%[1]s flag accepts a comma separated list of scopes you
73 want to remove from your gh credentials. Scope removal is idempotent.
74 The minimum set of scopes (%[1]srepo%[1]s, %[1]sread:org%[1]s, and %[1]sgist%[1]s) cannot be removed.
75
76 The %[1]s--reset-scopes%[1]s flag resets the scopes for your gh credentials to
77 the default set of scopes for your auth flow.
78
79 If you have multiple accounts in %[1]sgh auth status%[1]s and want to refresh the credentials for an
80 inactive account, you will have to use %[1]sgh auth switch%[1]s to that account first before using
81 this command, and then switch back when you are done.
82
83 Use %[1]s--expiring%[1]s to prefer expiring credentials that gh refreshes automatically, or
84 %[1]s--expiring=false%[1]s to prefer a non-expiring token. This is a preference, not a guarantee:
85 whether expiring tokens are issued depends on the host and the OAuth app configuration. A host
86 without support issues a non-expiring token instead, and a host configured for them may issue
87 expiring tokens even without the flag. Without the flag, refresh keeps the current token's kind,
88 so an expiring token stays expiring and a non-expiring token stays non-expiring.
89 When using expiring credentials for git operations, git 2.46 or newer is recommended so
90 gh can mark the token as non-cacheable; with older git a credential caching helper may store
91 and reuse an expired token.
92
93 For more information on OAuth scopes, see
94 <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps/>.
95 `, "`"),
96 Example: heredoc.Doc(`
97 # Open a browser to add write:org and read:public_key scopes
98 $ gh auth refresh --scopes write:org,read:public_key
99
100 # Open a browser to ensure your authentication credentials have the correct minimum scopes
101 $ gh auth refresh
102
103 # Open a browser to idempotently remove the delete_repo scope
104 $ gh auth refresh --remove-scopes delete_repo
105

Callers 1

Test_NewCmdRefreshFunction · 0.85

Calls 6

AuthFlowFunction · 0.92
FlagErrorfFunction · 0.92
NilBoolFlagFunction · 0.92
refreshRunFunction · 0.85
CanPromptMethod · 0.80
SetSampleRateMethod · 0.65

Tested by 1

Test_NewCmdRefreshFunction · 0.68