loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit fe0e370a3f12b935680de4eaea41c492568fa682
parent 8e70a3a3333be1c03f6a83c51fd0d52bb8561f93
Author: Sebastian Mancke <sebastian.mancke@snabble.io>
Date:   Wed, 26 Dec 2018 23:25:11 +0100

Merge pull request #107 from JesusIslam/bodyclose

Close all request body
Diffstat:
Moauth2/bitbucket.go | 7+++++--
Moauth2/facebook.go | 16+++++++++-------
Moauth2/github.go | 4+++-
Moauth2/google.go | 1+
Moauth2/oauth.go | 1+
5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/oauth2/bitbucket.go b/oauth2/bitbucket.go @@ -3,10 +3,11 @@ package oauth2 import ( "encoding/json" "fmt" - "github.com/tarent/loginsrv/model" "io/ioutil" "net/http" "strings" + + "github.com/tarent/loginsrv/model" ) var bitbucketAPI = "https://api.bitbucket.org/2.0" @@ -38,7 +39,7 @@ type email struct { Email string `json:"email,omitempty"` IsConfirmed bool `json:"is_confirmed,omitempty"` IsPrimary bool `json:"is_primary,omitempty"` - Links struct { + Links struct { Self struct { Href string } @@ -65,6 +66,7 @@ func getBitbucketEmails(token TokenInfo) (emails, error) { if err != nil { return emails{}, err } + defer resp.Body.Close() if !strings.Contains(resp.Header.Get("Content-Type"), "application/json") { return emails{}, fmt.Errorf("wrong content-type on bitbucket get user emails: %v", resp.Header.Get("Content-Type")) @@ -99,6 +101,7 @@ var providerBitbucket = Provider{ if err != nil { return model.UserInfo{}, "", err } + defer resp.Body.Close() if !strings.Contains(resp.Header.Get("Content-Type"), "application/json") { return model.UserInfo{}, "", fmt.Errorf("wrong content-type on bitbucket get user info: %v", resp.Header.Get("Content-Type")) diff --git a/oauth2/facebook.go b/oauth2/facebook.go @@ -1,12 +1,13 @@ package oauth2 import ( - "github.com/tarent/loginsrv/model" + "encoding/json" "fmt" - "net/http" "io/ioutil" - "encoding/json" + "net/http" "strings" + + "github.com/tarent/loginsrv/model" ) var facebookAPI = "https://graph.facebook.com/v2.12" @@ -18,13 +19,13 @@ func init() { // facebookUser is used for parsing the facebook response type facebookUser struct { UserID string `json:"id,omitempty"` - Picture struct{ - Data struct{ + Picture struct { + Data struct { URL string `json:"url,omitempty"` } `json:"data,omitempty"` } `json:"picture,omitempty"` - Name string `json:"name,omitempty"` - Email string `json:"email,omitempty"` + Name string `json:"name,omitempty"` + Email string `json:"email,omitempty"` } var providerfacebook = Provider{ @@ -46,6 +47,7 @@ var providerfacebook = Provider{ if err != nil { return model.UserInfo{}, "", err } + defer resp.Body.Close() if !strings.Contains(resp.Header.Get("Content-Type"), contentType) { return model.UserInfo{}, "", fmt.Errorf("wrong content-type on facebook get user info: %v", resp.Header.Get("Content-Type")) diff --git a/oauth2/github.go b/oauth2/github.go @@ -3,10 +3,11 @@ package oauth2 import ( "encoding/json" "fmt" - "github.com/tarent/loginsrv/model" "io/ioutil" "net/http" "strings" + + "github.com/tarent/loginsrv/model" ) var githubAPI = "https://api.github.com" @@ -34,6 +35,7 @@ var providerGithub = Provider{ if err != nil { return model.UserInfo{}, "", err } + defer resp.Body.Close() if !strings.Contains(resp.Header.Get("Content-Type"), "application/json") { return model.UserInfo{}, "", fmt.Errorf("wrong content-type on github get user info: %v", resp.Header.Get("Content-Type")) diff --git a/oauth2/google.go b/oauth2/google.go @@ -40,6 +40,7 @@ var providerGoogle = Provider{ if err != nil { return model.UserInfo{}, "", err } + defer resp.Body.Close() if !strings.Contains(resp.Header.Get("Content-Type"), "application/json") { return model.UserInfo{}, "", fmt.Errorf("wrong content-type on google get user info: %v", resp.Header.Get("Content-Type")) diff --git a/oauth2/oauth.go b/oauth2/oauth.go @@ -126,6 +126,7 @@ func getAccessToken(cfg Config, state, code string) (TokenInfo, error) { if err != nil { return TokenInfo{}, err } + defer resp.Body.Close() if resp.StatusCode != 200 { return TokenInfo{}, fmt.Errorf("error: expected http status 200 on token exchange, but got %v", resp.StatusCode)