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

Method ActiveToken

internal/config/config.go:250–273  ·  view source on GitHub ↗

ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, plain text config, and lastly encrypted storage.

(hostname string)

Source from the content-addressed store, hash-verified

248// searching environment variables, plain text config, and
249// lastly encrypted storage.
250func (c *AuthConfig) ActiveToken(hostname string) (string, string) {
251 if c.tokenOverride != nil {
252 return c.tokenOverride(hostname)
253 }
254 token, source := ghauth.TokenFromEnvOrConfig(hostname)
255 if token == "" {
256 var user string
257 var err error
258 if user, err = c.ActiveUser(hostname); err == nil {
259 token, err = c.TokenFromKeyringForUser(hostname, user)
260 }
261 if err != nil {
262 // We should generally be able to find a token for the active user,
263 // but in some cases such as if the keyring was set up in a very old
264 // version of the CLI, it may only have a unkeyed token, so fallback
265 // to it.
266 token, err = c.TokenFromKeyring(hostname)
267 }
268 if err == nil {
269 source = "keyring"
270 }
271 }
272 return token, source
273}
274
275// HasActiveToken returns true when a token for the hostname is present.
276func (c *AuthConfig) HasActiveToken(hostname string) bool {

Callers 3

ActiveTokenTypeMethod · 0.95
HasActiveTokenMethod · 0.95
SwitchUserMethod · 0.95

Calls 3

ActiveUserMethod · 0.95
TokenFromKeyringMethod · 0.95

Tested by

no test coverage detected