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

Interface AuthConfig

internal/gh/gh.go:138–217  ·  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

136// with knowledge on how to access encrypted storage when necessary.
137// Behavior is scoped to authentication specific tasks.
138type AuthConfig interface {
139 // HasActiveToken returns true when a token for the hostname is present.
140 HasActiveToken(hostname string) bool
141
142 // ActiveToken will retrieve the active auth token for the given hostname, searching environment variables,
143 // general configuration, and finally encrypted storage.
144 ActiveToken(hostname string) (token string, source string)
145
146 // ActiveTokenType reports what kind of credential the active token for the
147 // hostname is, so a caller can decide whether it will do without handling
148 // the token itself.
149 ActiveTokenType(hostname string) TokenType
150
151 // HasEnvToken returns true when a token has been specified in an environment variable, else returns false.
152 HasEnvToken() bool
153
154 // TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage.
155 TokenFromKeyring(hostname string) (token string, err error)
156
157 // TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching
158 // in encrypted storage.
159 //
160 // An empty username will return an error because the potential to return the currently active token under
161 // surprising cases is just too high to risk compared to the utility of having the function being smart.
162 TokenFromKeyringForUser(hostname, username string) (token string, err error)
163
164 // ActiveUser will retrieve the username for the active user at the given hostname.
165 //
166 // This will not be accurate if the oauth token is set from an environment variable.
167 ActiveUser(hostname string) (username string, err error)
168
169 // Hosts retrieves a list of known hosts.
170 Hosts() []string
171
172 // APIHostForHost returns the api_host configured for host, reporting false
173 // when the host has no api_host set. See config.AuthConfig.APIHostForHost.
174 APIHostForHost(host string) (apiHost string, found bool)
175
176 // HostForAPIHost returns the known host whose api_host is the given hostname,
177 // reporting false when no host claims it. See config.AuthConfig.HostForAPIHost.
178 HostForAPIHost(apiHost string) (host string, found bool)
179
180 // DefaultHost retrieves the default host.
181 DefaultHost() (host string, source string)
182
183 // Login will set user, git protocol, and auth token for the given hostname.
184 //
185 // If the encrypt option is specified it will first try to store the auth token
186 // in encrypted storage and will fall back to the general insecure configuration.
187 Login(hostname, username, token, gitProtocol string, secureStorage bool) (insecureStorageUsed bool, err error)
188
189 // SwitchUser switches the active user for a given hostname.
190 SwitchUser(hostname, user string) error
191
192 // Logout will remove user, git protocol, and auth token for the given hostname.
193 // It will remove the auth token from the encrypted storage if it exists there.
194 Logout(hostname, username string) error
195

Implementers 1

AuthConfiginternal/config/config.go

Calls

no outgoing calls

Tested by

no test coverage detected