From 2ee6f2780be9337a445f3ccd8487c2ea5874aaf5 Mon Sep 17 00:00:00 2001 From: Chaim Lev Ari Date: Sun, 30 Dec 2018 18:25:30 +0200 Subject: [PATCH] refactor(oauth): add debug logs --- api/http/handler/auth/authenticate.go | 2 ++ api/oauth/oauth.go | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/http/handler/auth/authenticate.go b/api/http/handler/auth/authenticate.go index 163023d0e..a0fbf7c51 100644 --- a/api/http/handler/auth/authenticate.go +++ b/api/http/handler/auth/authenticate.go @@ -111,11 +111,13 @@ func (handler *Handler) authenticateOAuth(w http.ResponseWriter, r *http.Request token, err := handler.OAuthService.GetAccessToken(payload.Code, &settings.OAuthSettings) if err != nil { + log.Printf("[DEBUG] - Failed retrieving access token: %v", err) return &httperror.HandlerError{http.StatusUnprocessableEntity, "Invalid access token", portainer.ErrUnauthorized} } username, err := handler.OAuthService.GetUsername(token, &settings.OAuthSettings) if err != nil { + log.Printf("[DEBUG] - Failed acquiring username: %v", err) return &httperror.HandlerError{http.StatusForbidden, "Unable to acquire username", portainer.ErrUnauthorized} } diff --git a/api/oauth/oauth.go b/api/oauth/oauth.go index bc175d46c..d2ceffa55 100644 --- a/api/oauth/oauth.go +++ b/api/oauth/oauth.go @@ -51,7 +51,6 @@ func (*Service) GetAccessToken(code string, settings *portainer.OAuthSettings) ( } if r.StatusCode != http.StatusOK { - log.Printf("[Error] - request returned with bad status code %v, body is %v", r.StatusCode, string(body)) type ErrorMessage struct { Message string Type string @@ -157,7 +156,7 @@ func (*Service) GetUsername(token string, settings *portainer.OAuthSettings) (st if !ok { username, ok := datamap[settings.UserIdentifier].(float64) - if ok { + if ok && username != 0 { return fmt.Sprint(int(username)), nil } }