diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-03-04 02:09:59 -0500 |
---|---|---|
committer | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-03-04 02:09:59 -0500 |
commit | 75c48fbf0ccbf1e7a01350a7fa6855f86a574d38 (patch) | |
tree | 6c0211e37eb61c431aaa1a5cf486b3ff58ce3469 | |
parent | 63e646e199e5bcfb623572d6c57ff71d87fcd60e (diff) | |
download | Atlas-75c48fbf0ccbf1e7a01350a7fa6855f86a574d38.tar.gz Atlas-75c48fbf0ccbf1e7a01350a7fa6855f86a574d38.zip |
pkg/origin: Fix Origin auth refresh when new login required
-rw-r--r-- | pkg/origin/authmgr.go | 2 | ||||
-rw-r--r-- | pkg/origin/login.go | 21 |
2 files changed, 12 insertions, 11 deletions
diff --git a/pkg/origin/authmgr.go b/pkg/origin/authmgr.go index 7e4c06b..2fb1d55 100644 --- a/pkg/origin/authmgr.go +++ b/pkg/origin/authmgr.go @@ -151,7 +151,7 @@ func (a *AuthMgr) OriginAuth(refresh bool) (NucleusToken, bool, error) { a.auth.NucleusToken = tok a.auth.NucleusTokenExpiry = exp return - } else if !errors.Is(err, ErrAuthRequired) { + } else if !errors.Is(aerr, ErrAuthRequired) { err = fmt.Errorf("refresh nucleus token: %w", aerr) return } diff --git a/pkg/origin/login.go b/pkg/origin/login.go index 0d3f936..f8bb255 100644 --- a/pkg/origin/login.go +++ b/pkg/origin/login.go @@ -52,18 +52,19 @@ func GetNucleusToken(ctx context.Context, t http.RoundTripper, sid juno.SID) (Nu return "", time.Time{}, fmt.Errorf("get nucleus token: %w", err) } - if resp.StatusCode != http.StatusOK { - var obj struct { - ErrorCode string `json:"error_code"` - Error string `json:"error"` - ErrorNumber json.Number `json:"error_number"` - } - if obj.ErrorCode == "login_required" { + var eobj struct { + ErrorCode string `json:"error_code"` + Error string `json:"error"` + ErrorNumber json.Number `json:"error_number"` + } + if err := json.Unmarshal(buf, &eobj); err == nil && eobj.Error != "" { + if eobj.ErrorCode == "login_required" { return "", time.Time{}, fmt.Errorf("get nucleus token: %w: login required", ErrAuthRequired) } - if err := json.Unmarshal(buf, &obj); err == nil && obj.Error != "" { - return "", time.Time{}, fmt.Errorf("get nucleus token: %w: error %s: %s (%q)", ErrOrigin, obj.ErrorNumber, obj.ErrorCode, obj.Error) - } + return "", time.Time{}, fmt.Errorf("get nucleus token: %w: error %s: %s (%q)", ErrOrigin, eobj.ErrorNumber, eobj.ErrorCode, eobj.Error) + } + + if resp.StatusCode != http.StatusOK { return "", time.Time{}, fmt.Errorf("get nucleus token: request %q: response status %d (%s)", resp.Request.URL.String(), resp.StatusCode, resp.Status) } |