Skip to content

Commit

Permalink
Merge pull request #107 from JesusIslam/bodyclose
Browse files Browse the repository at this point in the history
Close all request body
  • Loading branch information
smancke committed Dec 26, 2018
2 parents 8e70a3a + 92692f1 commit fe0e370
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
7 changes: 5 additions & 2 deletions oauth2/bitbucket.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down
16 changes: 9 additions & 7 deletions 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"
Expand All @@ -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{
Expand All @@ -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"))
Expand Down
4 changes: 3 additions & 1 deletion oauth2/github.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions oauth2/google.go
Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions oauth2/oauth.go
Expand Up @@ -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)
Expand Down

0 comments on commit fe0e370

Please sign in to comment.