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

Interface AuthConfig

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

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

Implementers 1

AuthConfiginternal/config/config.go

Calls

no outgoing calls

Tested by

no test coverage detected