MCPcopy Index your code
hub / github.com/cli/cli / ActiveToken

Method ActiveToken

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

235// searching environment variables, plain text config, and
236// lastly encrypted storage.
237func (c *AuthConfig) ActiveToken(hostname string) (string, string) {
238 if c.tokenOverride != nil {
239 return c.tokenOverride(hostname)
240 }
241 token, source := ghauth.TokenFromEnvOrConfig(hostname)
242 if token == "" {
243 var user string
244 var err error
245 if user, err = c.ActiveUser(hostname); err == nil {
246 token, err = c.TokenFromKeyringForUser(hostname, user)
247 }
248 if err != nil {
249 // We should generally be able to find a token for the active user,
250 // but in some cases such as if the keyring was set up in a very old
251 // version of the CLI, it may only have a unkeyed token, so fallback
252 // to it.
253 token, err = c.TokenFromKeyring(hostname)
254 }
255 if err == nil {
256 source = "keyring"
257 }
258 }
259 return token, source
260}
261
262// HasActiveToken returns true when a token for the hostname is present.
263func (c *AuthConfig) HasActiveToken(hostname string) bool {

Callers 2

HasActiveTokenMethod · 0.95
SwitchUserMethod · 0.95

Calls 3

ActiveUserMethod · 0.95
TokenFromKeyringMethod · 0.95

Tested by

no test coverage detected