Remove FUCKING FALLBACKS
This commit is contained in:
18
esi/sso.go
18
esi/sso.go
@@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -279,12 +280,21 @@ func (s *SSO) processCallback(isGet bool, code, state string, writeResponse func
|
||||
}{code, state, nil}
|
||||
}
|
||||
|
||||
// parseTokenExpiryBufferSeconds parses the token expiry buffer from Go duration format to seconds
|
||||
func parseTokenExpiryBufferSeconds() int {
|
||||
duration, err := time.ParseDuration(options.GlobalOptions.TokenExpiryBuffer)
|
||||
if err != nil {
|
||||
logger.Error("Invalid token expiry buffer duration %s: %v", options.GlobalOptions.TokenExpiryBuffer, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return int(duration.Seconds())
|
||||
}
|
||||
|
||||
func (s *SSO) waitForCallback() (code, state string, err error) {
|
||||
// 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
|
||||
return "", "", fmt.Errorf("invalid SSO callback timeout duration %s: %w", options.GlobalOptions.SSOCallbackTimeout, err)
|
||||
}
|
||||
|
||||
logger.Debug("Waiting for authentication callback (timeout: %v)", callbackTimeout)
|
||||
@@ -343,7 +353,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-options.GlobalOptions.TokenExpiryBuffer) * time.Second),
|
||||
ExpiresAt: time.Now().Add(time.Duration(tr.ExpiresIn-parseTokenExpiryBufferSeconds()) * time.Second),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -384,7 +394,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-options.GlobalOptions.TokenExpiryBuffer) * time.Second)
|
||||
char.ExpiresAt = time.Now().Add(time.Duration(tr.ExpiresIn-parseTokenExpiryBufferSeconds()) * time.Second)
|
||||
}
|
||||
|
||||
logger.Debug("Saving refreshed token to database for character %s", char.CharacterName)
|
||||
|
||||
Reference in New Issue
Block a user