From b82ecd11c1a0e33409c8118d2acd0961f0a6cfa7 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 28 Feb 2023 12:04:27 +0100 Subject: API + OAuth: Add some debug logging for tokens --- internal/oauth/token.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'internal/oauth') diff --git a/internal/oauth/token.go b/internal/oauth/token.go index c1d72f8..1594f43 100644 --- a/internal/oauth/token.go +++ b/internal/oauth/token.go @@ -6,6 +6,7 @@ import ( "time" "github.com/go-errors/errors" + "github.com/eduvpn/eduvpn-common/internal/log" ) // TokenResponse defines the OAuth response from the server that includes the tokens. @@ -58,29 +59,34 @@ type tokenLock struct { // It returns the access token as a string, possibly obtained fresh using the refresher // If the token cannot be obtained, an error is returned and the token is an empty string. func (l *tokenLock) Access() (string, error) { + log.Logger.Debugf("Getting access token") l.mu.Lock() defer l.mu.Unlock() // The tokens are not expired yet // So they should be valid, re-login not neede if !l.expired() { + log.Logger.Debugf("Access token is not expired, returning") return l.t.Access, nil } // Check if refresh is even possible by doing a simple check if the refresh token is empty // This is not needed but reduces API calls to the server if l.t.Refresh == "" { + log.Logger.Debugf("Refresh token is empty, returning error") return "", errors.Wrap(&TokensInvalidError{Cause: "no refresh token is present"}, 0) } // Otherwise refresh and then later return the access token if we are successful tr, s, err := l.t.Refresher(l.t.Refresh) if err != nil { + log.Logger.Debugf("Got a refresh token error: %v", err) // We have failed to ensure the tokens due to refresh not working return "", errors.Wrap( &TokensInvalidError{Cause: fmt.Sprintf("tokens failed refresh with error: %v", err)}, 0) } if tr == nil { + log.Logger.Debugf("No token response after refreshing") return "", errors.New("No token response after refreshing") } r := *tr -- cgit v1.2.3