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

Method ActiveToken

internal/config/config.go:257–280  ·  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

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