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

Function resolveCredential

pkg/cmd/auth/status/status.go:540–554  ·  view source on GitHub ↗

resolveCredential returns the credential gh should present for the host and optional user (an empty username means the active account), refreshing an expiring token unless noRefresh is set. Refresh is best effort: a failed refresh yields the last stored credential, which the caller still validates v

(authCfg gh.AuthConfig, hostname, username string, noRefresh bool)

Source from the content-addressed store, hash-verified

538// refresh yields the last stored credential, which the caller still validates via the scope check. The returned status
539// reports whether a refresh happened.
540func resolveCredential(authCfg gh.AuthConfig, hostname, username string, noRefresh bool) (gh.Credential, gh.RefreshStatus) {
541 if noRefresh {
542 if username == "" {
543 return authCfg.ActiveToken(hostname), gh.RefreshStatusInapplicable
544 }
545 credential, _ := authCfg.TokenForUser(hostname, username)
546 return credential, gh.RefreshStatusInapplicable
547 }
548 if username == "" {
549 credential, status, _ := authCfg.ActiveTokenWithRefresh(hostname)
550 return credential, status
551 }
552 credential, status, _ := authCfg.TokenForUserWithRefresh(hostname, username)
553 return credential, status
554}

Callers 1

statusRunFunction · 0.85

Calls 4

ActiveTokenMethod · 0.65
TokenForUserMethod · 0.65

Tested by

no test coverage detected