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

Interface AuthConfig

internal/gh/gh.go:224–348  ·  view source on GitHub ↗

AuthConfig is used for interacting with some persistent configuration for gh, with knowledge on how to access encrypted storage when necessary. Behavior is scoped to authentication specific tasks.

Source from the content-addressed store, hash-verified

222// with knowledge on how to access encrypted storage when necessary.
223// Behavior is scoped to authentication specific tasks.
224type AuthConfig interface {
225 // HasActiveToken returns true when a token for the hostname is present.
226 HasActiveToken(hostname string) bool
227
228 // ActiveTokenWithRefresh retrieves the active credential for the given hostname and, when it is refreshable and
229 // its access token is expiring, renews and persists it. It may return a non-empty credential with an error, such
230 // as when refreshing fails. The caller decides whether to use the returned credential.
231 ActiveTokenWithRefresh(hostname string) (credential Credential, refreshResult RefreshStatus, err error)
232
233 // Warnings returns the deduplicated warnings recorded so far in this process, such as a skipped token refresh, in
234 // the order they were first recorded. Callers are expected to show them to the user before gh exits.
235 Warnings() []string
236
237 // ActiveToken retrieves the active credential for the given hostname, searching environment variables, general
238 // configuration, and finally encrypted storage. It returns the last stored token as-is, including the current
239 // access token of a refreshable credential, and never contacts the token endpoint to refresh it. A caller that
240 // needs a token valid for API calls should use ActiveTokenWithRefresh instead.
241 ActiveToken(hostname string) Credential
242
243 // ActiveTokenType reports what kind of credential the active token for the
244 // hostname is, so a caller can decide whether it will do without handling
245 // the token itself.
246 ActiveTokenType(hostname string) TokenType
247
248 // HasEnvToken returns true when a token has been specified in an environment variable, else returns false.
249 HasEnvToken() bool
250
251 // TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage.
252 TokenFromKeyring(hostname string) (token string, err error)
253
254 // TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching
255 // in encrypted storage.
256 //
257 // An empty username will return an error because the potential to return the currently active token under
258 // surprising cases is just too high to risk compared to the utility of having the function being smart.
259 TokenFromKeyringForUser(hostname, username string) (token string, err error)
260
261 // ActiveUser will retrieve the username for the active user at the given hostname.
262 //
263 // This will not be accurate if the oauth token is set from an environment variable.
264 ActiveUser(hostname string) (username string, err error)
265
266 // Hosts retrieves a list of known hosts.
267 Hosts() []string
268
269 // APIHostForHost returns the api_host configured for host, reporting false
270 // when the host has no api_host set. See config.AuthConfig.APIHostForHost.
271 APIHostForHost(host string) (apiHost string, found bool)
272
273 // HostForAPIHost returns the known host whose api_host is the given hostname,
274 // reporting false when no host claims it. See config.AuthConfig.HostForAPIHost.
275 HostForAPIHost(apiHost string) (host string, found bool)
276
277 // DefaultHost retrieves the default host.
278 DefaultHost() (host string, source string)
279
280 // Login will set user, git protocol, and auth token for the given hostname.
281 //

Implementers 1

AuthConfiginternal/config/config.go

Calls

no outgoing calls

Tested by

no test coverage detected