Add more oauth logging and note about GitLab ToS for login (#8949)

This commit is contained in:
Joram Wilander
2018-06-14 19:27:00 +02:00
committed by Carlos Tadeu Panato Junior
parent 8d29f8f58b
commit 85a75526c7
2 changed files with 18 additions and 1 deletions
+14 -1
View File
@@ -8,6 +8,7 @@ import (
b64 "encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@@ -690,10 +691,13 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
if resp, err := a.HTTPClient(true).Do(req); err != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
bodyBytes, _ = ioutil.ReadAll(resp.Body)
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
ar = model.AccessResponseFromJson(resp.Body)
consumeAndClose(resp)
if ar == nil {
if ar == nil || resp.StatusCode != http.StatusOK {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, "response_body="+string(bodyBytes), http.StatusInternalServerError)
}
}
@@ -717,6 +721,15 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
if resp, err := a.HTTPClient(true).Do(req); err != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]interface{}{"Service": service}, err.Error(), http.StatusInternalServerError)
} else {
bodyBytes, _ = ioutil.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
bodyString := string(bodyBytes)
mlog.Error("Error getting OAuth user: " + bodyString)
if service == model.SERVICE_GITLAB && resp.StatusCode == http.StatusForbidden && strings.Contains(bodyString, "Terms of Service") {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "oauth.gitlab.tos.error", nil, "", http.StatusBadRequest)
}
}
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
return resp.Body, teamId, stateProps, nil
}
+4
View File
@@ -2842,6 +2842,10 @@
"id": "api.user.complete_switch_with_oauth.blank_email.app_error",
"translation": "Blank email"
},
{
"id": "oauth.gitlab.tos.error",
"translation": "GitLab's Terms of Service have updated. Please go to gitlab.com to accept them and then try logging into Mattermost again."
},
{
"id": "api.user.complete_switch_with_oauth.parse.app_error",
"translation": "Could not parse auth data out of {{.Service}} user object"