summaryrefslogtreecommitdiffstats
path: root/app/oauth.go
diff options
context:
space:
mode:
authorTorsten Juergeleit <torsten.juergeleit@gmail.com>2017-05-31 16:34:05 +0200
committerHarrison Healey <harrisonmhealey@gmail.com>2017-05-31 10:34:05 -0400
commitfdf1164aee36d60b34ca82c07fe02b68e972f53a (patch)
treedecf173e9b6fb8d8f3c10463d065ad9234fc3391 /app/oauth.go
parentddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7 (diff)
downloadchat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.gz
chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.bz2
chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.zip
PLT-5705 Created a single source of http.Client creation logic with internet proxy support, reasonable timeouts and optional insecure connections (#6503)
Diffstat (limited to 'app/oauth.go')
-rw-r--r--app/oauth.go14
1 files changed, 3 insertions, 11 deletions
diff --git a/app/oauth.go b/app/oauth.go
index deeb10f17..a2edae8be 100644
--- a/app/oauth.go
+++ b/app/oauth.go
@@ -5,7 +5,6 @@ package app
import (
"bytes"
- "crypto/tls"
b64 "encoding/base64"
"fmt"
"io"
@@ -576,10 +575,6 @@ func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser
p.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
p.Set("redirect_uri", redirectUri)
- tr := &http.Transport{
- TLSClientConfig: &tls.Config{InsecureSkipVerify: *utils.Cfg.ServiceSettings.EnableInsecureOutgoingConnections},
- }
- client := &http.Client{Transport: tr}
req, _ := http.NewRequest("POST", sso.TokenEndpoint, strings.NewReader(p.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -587,14 +582,11 @@ func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser
var ar *model.AccessResponse
var respBody []byte
- if resp, err := client.Do(req); err != nil {
+ if resp, err := utils.HttpClient().Do(req); err != nil {
return nil, "", nil, model.NewLocAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error())
} else {
ar = model.AccessResponseFromJson(resp.Body)
- defer func() {
- ioutil.ReadAll(resp.Body)
- resp.Body.Close()
- }()
+ defer CloseBody(resp)
if ar == nil {
return nil, "", nil, model.NewLocAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, "")
}
@@ -616,7 +608,7 @@ func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", "Bearer "+ar.AccessToken)
- if resp, err := client.Do(req); err != nil {
+ if resp, err := utils.HttpClient().Do(req); err != nil {
return nil, "", nil, model.NewLocAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error",
map[string]interface{}{"Service": service}, err.Error())
} else {