]> git.giacomolli.uk - onechat/blobdiff - auth.go
Run the tools of an agent and log each call
[onechat] / auth.go
diff --git a/auth.go b/auth.go
index 1908b89507bc62f210a38679713cb825434462d5..736624e37e0850df3f21f116c60862815282f571 100644 (file)
--- a/auth.go
+++ b/auth.go
@@ -63,7 +63,6 @@ type chatgptAuth struct {
        path   string
        issuer string
        http   *http.Client
-       clock  func() time.Time
 }
 
 // tokenFile is the content of the token file.
@@ -115,7 +114,6 @@ func newChatGPTAuth(path, issuer string) *chatgptAuth {
                path:   path,
                issuer: issuer,
                http:   &http.Client{},
-               clock:  time.Now,
        }
 }
 
@@ -308,7 +306,7 @@ func (a *chatgptAuth) Authorize(ctx context.Context, header http.Header) error {
        }
 
        expiry, found := tokenExpiry(tokens.AccessToken)
-       if !found || !a.clock().Before(expiry.Add(-refreshMargin)) {
+       if !found || !time.Now().Before(expiry.Add(-refreshMargin)) {
                tokens, err = a.refresh(ctx, tokens)
                if err != nil {
                        return err