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