summaryrefslogtreecommitdiffstats
path: root/app/oauth.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-06-14 13:27:00 -0400
committerCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-06-14 19:27:00 +0200
commit85a75526c7c03fca1d14a39cfb3f2638d98d3fe1 (patch)
tree7de21b1914e4e3285905580014e75d6e94803a21 /app/oauth.go
parent8d29f8f58b68b13ecbc5d5766105de34885a2333 (diff)
downloadchat-85a75526c7c03fca1d14a39cfb3f2638d98d3fe1.tar.gz
chat-85a75526c7c03fca1d14a39cfb3f2638d98d3fe1.tar.bz2
chat-85a75526c7c03fca1d14a39cfb3f2638d98d3fe1.zip
Add more oauth logging and note about GitLab ToS for login (#8949)
Diffstat (limited to 'app/oauth.go')
-rw-r--r--app/oauth.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/app/oauth.go b/app/oauth.go
index 13fbd5a73..477c0aeaf 100644
--- a/app/oauth.go
+++ b/app/oauth.go
@@ -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
}