From 45616fa60eecffca3727786e799a777e007969e2 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 27 Jul 2020 22:41:15 +0200 Subject: [PATCH] Flip verifyAuthCode if --- cmd/eksterd/auth.go | 1 - cmd/eksterd/http.go | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/eksterd/auth.go b/cmd/eksterd/auth.go index 339084d..571722e 100644 --- a/cmd/eksterd/auth.go +++ b/cmd/eksterd/auth.go @@ -51,7 +51,6 @@ func cachedCheckAuthToken(conn redis.Conn, header string, tokenEndpoint string, } func checkAuthToken(header string, tokenEndpoint string, token *auth.TokenResponse) (bool, error) { - req, err := buildValidateAuthTokenRequest(tokenEndpoint, header) if err != nil { return false, err diff --git a/cmd/eksterd/http.go b/cmd/eksterd/http.go index f0afa84..b2d5241 100644 --- a/cmd/eksterd/http.go +++ b/cmd/eksterd/http.go @@ -177,19 +177,19 @@ func verifyAuthCode(code, redirectURI, authEndpoint, clientID string) (bool, *au defer resp.Body.Close() - if resp.StatusCode == 200 { - input := io.TeeReader(resp.Body, os.Stderr) - dec := json.NewDecoder(input) - var authResponse authResponse - err = dec.Decode(&authResponse) - if err != nil { - return false, nil, fmt.Errorf("while verifying authentication response from %s: %s", authEndpoint, err) - } - - return true, &authResponse, nil + if resp.StatusCode != 200 { + return false, nil, fmt.Errorf("HTTP response code from authorization_endpoint (%s) %d", authEndpoint, resp.StatusCode) } - return false, nil, fmt.Errorf("HTTP response code from authorization_endpoint (%s) %d", authEndpoint, resp.StatusCode) + input := io.TeeReader(resp.Body, os.Stderr) + dec := json.NewDecoder(input) + var authResponse authResponse + err = dec.Decode(&authResponse) + if err != nil { + return false, nil, fmt.Errorf("while verifying authentication response from %s: %s", authEndpoint, err) + } + + return true, &authResponse, nil } func isLoggedIn(backend *memoryBackend, sess *session) bool {