Add configurable timeouts and cache validity to ESI and SSO components
This commit is contained in:
18
esi/sso.go
18
esi/sso.go
@@ -16,6 +16,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/options"
|
||||
"go-eve-pi/repositories"
|
||||
"go-eve-pi/types"
|
||||
|
||||
@@ -279,7 +280,14 @@ func (s *SSO) processCallback(isGet bool, code, state string, writeResponse func
|
||||
}
|
||||
|
||||
func (s *SSO) waitForCallback() (code, state string, err error) {
|
||||
logger.Debug("Waiting for authentication callback (timeout: 30s)")
|
||||
// Parse SSO callback timeout ONCE at initialization
|
||||
callbackTimeout, err := time.ParseDuration(options.GlobalOptions.SSOCallbackTimeout)
|
||||
if err != nil {
|
||||
logger.Warning("Invalid SSO callback timeout duration %s, using 30s default: %v", options.GlobalOptions.SSOCallbackTimeout, err)
|
||||
callbackTimeout = 30 * time.Second
|
||||
}
|
||||
|
||||
logger.Debug("Waiting for authentication callback (timeout: %v)", callbackTimeout)
|
||||
// Wait for callback through channel
|
||||
select {
|
||||
case result := <-s.callbackChan:
|
||||
@@ -289,8 +297,8 @@ func (s *SSO) waitForCallback() (code, state string, err error) {
|
||||
}
|
||||
logger.Debug("Callback received successfully")
|
||||
return result.code, result.state, result.err
|
||||
case <-time.After(30 * time.Second):
|
||||
logger.Error("Callback timeout after 30 seconds")
|
||||
case <-time.After(callbackTimeout):
|
||||
logger.Error("Callback timeout after %v", callbackTimeout)
|
||||
return "", "", errors.New("callback timeout")
|
||||
}
|
||||
}
|
||||
@@ -335,7 +343,7 @@ func (s *SSO) exchangeCodeForToken(ctx context.Context, code, verifier string) (
|
||||
CharacterName: name,
|
||||
AccessToken: tr.AccessToken,
|
||||
RefreshToken: tr.RefreshToken,
|
||||
ExpiresAt: time.Now().Add(time.Duration(tr.ExpiresIn-30) * time.Second),
|
||||
ExpiresAt: time.Now().Add(time.Duration(tr.ExpiresIn-options.GlobalOptions.TokenExpiryBuffer) * time.Second),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -376,7 +384,7 @@ func (s *SSO) refreshToken(ctx context.Context, char *types.Character) error {
|
||||
char.RefreshToken = tr.RefreshToken
|
||||
}
|
||||
if tr.ExpiresIn > 0 {
|
||||
char.ExpiresAt = time.Now().Add(time.Duration(tr.ExpiresIn-30) * time.Second)
|
||||
char.ExpiresAt = time.Now().Add(time.Duration(tr.ExpiresIn-options.GlobalOptions.TokenExpiryBuffer) * time.Second)
|
||||
}
|
||||
|
||||
logger.Debug("Saving refreshed token to database for character %s", char.CharacterName)
|
||||
|
||||
Reference in New Issue
Block a user