From 4df81c8f2145e6db4961f5c319017589638e7314 Mon Sep 17 00:00:00 2001 From: Leland Ursu Date: Thu, 13 Apr 2023 13:12:19 -0400 Subject: [PATCH] also check that the AccessTokenExpiry has not passed (#181) * also check that the AccessTokenExpiry has not passed * added changelog * fix existing test case with new check --------- Co-authored-by: lursu --- .changelog/181.txt | 3 +++ auth/user.go | 6 +++--- auth/user_test.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changelog/181.txt diff --git a/.changelog/181.txt b/.changelog/181.txt new file mode 100644 index 00000000..8b33c16a --- /dev/null +++ b/.changelog/181.txt @@ -0,0 +1,3 @@ +```release-note:bug +Fixed issue of not regenerating auth token when AccessToken expires +``` diff --git a/auth/user.go b/auth/user.go index 0cfba9ed..f957e896 100644 --- a/auth/user.go +++ b/auth/user.go @@ -29,9 +29,9 @@ func (s *UserSession) GetToken(ctx context.Context, conf *oauth2.Config) (*oauth var tok *oauth2.Token var err error - // Check the session expiry of the retrieved token. - // If session expiry has passed, then reauthenticate with browser login and reassign token. - if readErr != nil || cache.SessionExpiry.Before(time.Now()) { + // Check the expiry of the retrieved token. + // If session expiry or the AccessTokenExpiry has passed, then reauthenticate with browser login and reassign token. + if readErr != nil || cache.SessionExpiry.Before(time.Now()) || cache.AccessTokenExpiry.Before(time.Now()) { // Login with browser. log.Print("No credentials found, proceeding with browser login.") diff --git a/auth/user_test.go b/auth/user_test.go index 56957ce5..97cbf389 100644 --- a/auth/user_test.go +++ b/auth/user_test.go @@ -26,7 +26,7 @@ func TestGetToken_ExistingToken(t *testing.T) { cache := Cache{ AccessToken: "Test.Access.Token", RefreshToken: "TestRefreshToken", - AccessTokenExpiry: now, + AccessTokenExpiry: now.Add(time.Hour * 2), SessionExpiry: time.Now().Add(time.Hour * 24), }