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

Method ActiveTokenWithRefresh

internal/config/config.go:377–389  ·  view source on GitHub ↗

ActiveTokenWithRefresh retrieves the active credential for the given hostname and, when it is refreshable and its access token is expiring, renews and persists it, returning the credential to use and the refresh outcome. Non-refreshable credentials are returned unchanged with RefreshStatusInapplicab

(hostname string)

Source from the content-addressed store, hash-verified

375// access token is expiring, renews and persists it, returning the credential to use and the refresh outcome.
376// Non-refreshable credentials are returned unchanged with RefreshStatusInapplicable.
377func (c *AuthConfig) ActiveTokenWithRefresh(hostname string) (gh.Credential, gh.RefreshStatus, error) {
378 credential := c.ActiveToken(hostname)
379 if !credential.IsRefreshable() {
380 return credential, gh.RefreshStatusInapplicable, nil
381 }
382 user, err := c.ActiveUser(hostname)
383 if err != nil {
384 // A refreshable active credential is always keyed by the active user, so this is unreachable in practice.
385 // If we somehow cannot identify the user, we have no key to refresh under, so return the credential as-is.
386 return credential, gh.RefreshStatusInapplicable, err
387 }
388 return c.refreshCredentialForUser(hostname, user, credential)
389}
390
391// HasActiveToken returns true when a token for the hostname is present.
392func (c *AuthConfig) HasActiveToken(hostname string) bool {

Callers

nothing calls this directly

Calls 4

ActiveTokenMethod · 0.95
ActiveUserMethod · 0.95
IsRefreshableMethod · 0.80

Tested by

no test coverage detected