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

Method ActiveTokenWithRefresh

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

351// access token is expiring, renews and persists it, returning the credential to use and the refresh outcome.
352// Non-refreshable credentials are returned unchanged with RefreshStatusInapplicable.
353func (c *AuthConfig) ActiveTokenWithRefresh(hostname string) (gh.Credential, gh.RefreshStatus, error) {
354 credential := c.ActiveToken(hostname)
355 if !credential.IsRefreshable() {
356 return credential, gh.RefreshStatusInapplicable, nil
357 }
358 user, err := c.ActiveUser(hostname)
359 if err != nil {
360 // A refreshable active credential is always keyed by the active user, so this is unreachable in practice.
361 // If we somehow cannot identify the user, we have no key to refresh under, so return the credential as-is.
362 return credential, gh.RefreshStatusInapplicable, err
363 }
364 return c.refreshCredentialForUser(hostname, user, credential)
365}
366
367// HasActiveToken returns true when a token for the hostname is present.
368func (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