(hostname, username string, credential gh.Credential)
| 339 | } |
| 340 | |
| 341 | func (c *AuthConfig) setRefreshableInConfig(hostname, username string, credential gh.Credential) { |
| 342 | path := refreshablePath(hostname, username) |
| 343 | // Clear the mapping first so an omitted field does not retain a stale value. |
| 344 | _ = c.cfg.Remove(path) |
| 345 | record := normalizeToUTC(recordFromCredential(credential)) |
| 346 | c.cfg.Set(append(path, "access_token"), record.AccessToken) |
| 347 | c.cfg.Set(append(path, "refresh_token"), record.RefreshToken) |
| 348 | if record.ExpiresIn != 0 { |
| 349 | c.cfg.Set(append(path, "expires_in"), strconv.Itoa(record.ExpiresIn)) |
| 350 | } |
| 351 | if record.ExpiresAt != nil { |
| 352 | c.cfg.Set(append(path, "expires_at"), record.ExpiresAt.Format(time.RFC3339Nano)) |
| 353 | } |
| 354 | if record.RefreshTokenExpiresIn != 0 { |
| 355 | c.cfg.Set(append(path, "refresh_token_expires_in"), strconv.Itoa(record.RefreshTokenExpiresIn)) |
| 356 | } |
| 357 | if record.RefreshTokenExpiresAt != nil { |
| 358 | c.cfg.Set(append(path, "refresh_token_expires_at"), record.RefreshTokenExpiresAt.Format(time.RFC3339Nano)) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // refreshExpiryLeeway is how far ahead of an access token's expiry gh proactively refreshes it, so a token |
| 363 | // on the verge of expiring is renewed before it can fail an in-flight request. |
no test coverage detected