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

Method ActiveToken

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

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