Merge remote-tracking branch 'upstream/release-5.0' into release-5.0-merge-to-master-20180615

Этот коммит содержится в:
cpanato
2018-06-15 17:38:08 +02:00
родитель c8b99b97df 85a75526c7
Коммит e38b18565e
3 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@@ -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
}